diff options
Diffstat (limited to 'src/dbus')
| -rw-r--r-- | src/dbus/mod.rs | 1 | ||||
| -rw-r--r-- | src/dbus/mutter_service_channel.rs | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/dbus/mod.rs b/src/dbus/mod.rs new file mode 100644 index 00000000..01b4c391 --- /dev/null +++ b/src/dbus/mod.rs @@ -0,0 +1 @@ +pub mod mutter_service_channel; diff --git a/src/dbus/mutter_service_channel.rs b/src/dbus/mutter_service_channel.rs new file mode 100644 index 00000000..29af6529 --- /dev/null +++ b/src/dbus/mutter_service_channel.rs @@ -0,0 +1,38 @@ +use std::os::fd::{FromRawFd, IntoRawFd}; +use std::os::unix::net::UnixStream; +use std::sync::Arc; + +use smithay::reexports::wayland_server::DisplayHandle; +use zbus::dbus_interface; + +use crate::niri::ClientState; + +pub struct ServiceChannel { + display: DisplayHandle, +} + +#[dbus_interface(name = "org.gnome.Mutter.ServiceChannel")] +impl ServiceChannel { + async fn open_wayland_service_connection( + &mut self, + service_client_type: u32, + ) -> zbus::fdo::Result<zbus::zvariant::OwnedFd> { + if service_client_type != 1 { + return Err(zbus::fdo::Error::InvalidArgs( + "Invalid service client type".to_owned(), + )); + } + + let (sock1, sock2) = UnixStream::pair().unwrap(); + self.display + .insert_client(sock2, Arc::new(ClientState::default())) + .unwrap(); + Ok(unsafe { zbus::zvariant::OwnedFd::from_raw_fd(sock1.into_raw_fd()) }) + } +} + +impl ServiceChannel { + pub fn new(display: DisplayHandle) -> Self { + Self { display } + } +} |
