forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

mutter_service_channel.rs61 lines, 1.9 KiBHistoryRawDownload
1use std::os::unix::net::UnixStream;
2
3use zbus::{fdo, interface, zvariant};
4
5use super::Start;
6use crate::niri::NewClient;
7
8pub struct ServiceChannel {
9 to_niri: calloop::channel::Sender<NewClient>,
10}
11
12#[interface(name = "org.gnome.Mutter.ServiceChannel")]
13impl ServiceChannel {
14 async fn open_wayland_service_connection(
15 &mut self,
16 service_client_type: u32,
17 ) -> fdo::Result<zvariant::OwnedFd> {
18 // ServiceClientTypes:
19 // PORTAL_BACKEND: 1
20 // FILECHOOSER_PORTAL_BACKEND: 2
21 // GLOBAL_SHORTCUTS_PORTAL_BACKEND: 3
22 //
23 // In mutter, 1 and 2 get access to mutter_x11_interop.
24 // Ours is a stub, so we don't do this filtering.
25 if !matches!(service_client_type, 1..=3) {
26 return Err(fdo::Error::InvalidArgs(
27 "Invalid service client type".to_owned(),
28 ));
29 }
30
31 let (sock1, sock2) = UnixStream::pair().unwrap();
32 let client = NewClient {
33 client: sock2,
34 restricted: false,
35 // FIXME: maybe you can get the PID from D-Bus somehow?
36 credentials_unknown: true,
37 };
38 if let Err(err) = self.to_niri.send(client) {
39 warn!("error sending message to niri: {err:?}");
40 return Err(fdo::Error::Failed("internal error".to_owned()));
41 }
42
43 Ok(zvariant::OwnedFd::from(std::os::fd::OwnedFd::from(sock1)))
44 }
45}
46
47impl ServiceChannel {
48 pub fn new(to_niri: calloop::channel::Sender<NewClient>) -> Self {
49 Self { to_niri }
50 }
51}
52
53impl Start for ServiceChannel {
54 fn start(self, _monitor: bool) -> anyhow::Result<zbus::blocking::Connection> {
55 let conn = zbus::blocking::connection::Builder::session()?
56 .name("org.gnome.Mutter.ServiceChannel")?
57 .serve_at("/org/gnome/Mutter/ServiceChannel", self)?
58 .build()?;
59 Ok(conn)
60 }
61}