mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Add trivial Mutter ServiceChannel impl
Makes xdp-gnome work.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
pub mod mutter_service_channel;
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ mod handlers;
|
||||
|
||||
mod animation;
|
||||
mod backend;
|
||||
mod dbus;
|
||||
mod frame_clock;
|
||||
mod input;
|
||||
mod layout;
|
||||
|
||||
+20
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user