refactor: connect to privileged socket if possible
This commit is contained in:
parent
21fc43e578
commit
2141230229
2 changed files with 41 additions and 14 deletions
|
|
@ -1,4 +1,9 @@
|
|||
use crate::wayland_subscription::{ToplevelRequest, ToplevelUpdate, WaylandRequest, WaylandUpdate};
|
||||
use std::os::{
|
||||
fd::{FromRawFd, RawFd},
|
||||
unix::net::UnixStream,
|
||||
};
|
||||
|
||||
use cctk::{
|
||||
sctk::{
|
||||
self,
|
||||
|
|
@ -171,7 +176,19 @@ pub(crate) fn wayland_handler(
|
|||
tx: UnboundedSender<WaylandUpdate>,
|
||||
rx: calloop::channel::Channel<WaylandRequest>,
|
||||
) {
|
||||
let conn = Connection::connect_to_env().unwrap();
|
||||
let socket = std::env::var("X_PRIVILEGED_WAYLAND_SOCKET")
|
||||
.ok()
|
||||
.and_then(|fd| {
|
||||
fd.parse::<RawFd>()
|
||||
.ok()
|
||||
.map(|fd| unsafe { UnixStream::from_raw_fd(fd) })
|
||||
});
|
||||
|
||||
let conn = if let Some(socket) = socket {
|
||||
Connection::from_socket(socket).unwrap()
|
||||
} else {
|
||||
Connection::connect_to_env().unwrap()
|
||||
};
|
||||
let (globals, event_queue) = registry_queue_init(&conn).unwrap();
|
||||
|
||||
let mut event_loop = calloop::EventLoop::<AppData>::try_new().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue