aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-08-27 10:29:06 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-08-27 10:29:06 +0400
commite09a6d6392e73d8410b177ed9307c15f97d14858 (patch)
treef07d122a8d982ca585ce273995e2faea25c90d32 /src
parenta54e048f419221be9f26310363267d63a8758abb (diff)
downloadniri-e09a6d6392e73d8410b177ed9307c15f97d14858.tar.gz
niri-e09a6d6392e73d8410b177ed9307c15f97d14858.tar.bz2
niri-e09a6d6392e73d8410b177ed9307c15f97d14858.zip
Add trivial Mutter ServiceChannel impl
Makes xdp-gnome work.
Diffstat (limited to 'src')
-rw-r--r--src/dbus/mod.rs1
-rw-r--r--src/dbus/mutter_service_channel.rs38
-rw-r--r--src/main.rs1
-rw-r--r--src/niri.rs20
4 files changed, 60 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 }
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 2b5715fd..3d5079cc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@ mod handlers;
mod animation;
mod backend;
+mod dbus;
mod frame_clock;
mod input;
mod layout;
diff --git a/src/niri.rs b/src/niri.rs
index b428345a..9a8dcac3 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -44,6 +44,7 @@ use smithay::wayland::socket::ListeningSocketSource;
use smithay::wayland::tablet_manager::TabletManagerState;
use crate::backend::Backend;
+use crate::dbus::mutter_service_channel::ServiceChannel;
use crate::frame_clock::FrameClock;
use crate::layout::{MonitorRenderElement, MonitorSet};
use crate::utils::{center, get_monotonic_time, load_default_cursor};
@@ -85,6 +86,8 @@ pub struct Niri {
pub pointer_buffer: Option<(TextureBuffer<GlesTexture>, Point<i32, Physical>)>,
pub cursor_image: CursorImageStatus,
pub dnd_icon: Option<WlSurface>,
+
+ pub zbus_conn: Option<zbus::blocking::Connection>,
}
pub struct OutputState {
@@ -151,6 +154,7 @@ impl Niri {
socket_name.to_string_lossy()
);
+ let mut zbus_conn = None;
if std::env::var_os("NOTIFY_SOCKET").is_some() {
// We're starting as a systemd service. Export our variables and tell systemd we're
// ready.
@@ -166,6 +170,20 @@ impl Niri {
warn!("error spawning shell to import environment into systemd: {err:?}");
}
+ // Set up zbus, make sure it happens before anything might want it.
+ let conn = zbus::blocking::ConnectionBuilder::session()
+ .unwrap()
+ .name("org.gnome.Mutter.ServiceChannel")
+ .unwrap()
+ .serve_at(
+ "/org/gnome/Mutter/ServiceChannel",
+ ServiceChannel::new(display_handle.clone()),
+ )
+ .unwrap()
+ .build()
+ .unwrap();
+ zbus_conn = Some(conn);
+
// Notify systemd we're ready.
if let Err(err) = sd_notify::notify(false, &[NotifyState::Ready]) {
warn!("error notifying systemd: {err:?}");
@@ -210,6 +228,8 @@ impl Niri {
pointer_buffer: None,
cursor_image: CursorImageStatus::Default,
dnd_icon: None,
+
+ zbus_conn,
}
}