aboutsummaryrefslogtreecommitdiff
path: root/src/dbus/mutter_service_channel.rs
blob: 29af652910ded7cc8e245d022b9a5cf06c08f09f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 }
    }
}