forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

gnome_shell_introspect.rs77 lines, 2.4 KiBHistoryRawDownload
1use std::collections::HashMap;
2
3use zbus::object_server::SignalEmitter;
4use zbus::zvariant::{SerializeDict, Type, Value};
5use zbus::{fdo, interface};
6
7use super::{request_name, Start};
8
9pub struct Introspect {
10 to_niri: calloop::channel::Sender<IntrospectToNiri>,
11 from_niri: async_channel::Receiver<NiriToIntrospect>,
12}
13
14pub enum IntrospectToNiri {
15 GetWindows,
16}
17
18pub enum NiriToIntrospect {
19 Windows(HashMap<u64, WindowProperties>),
20}
21
22#[derive(Debug, SerializeDict, Type, Value)]
23#[zvariant(signature = "dict")]
24pub struct WindowProperties {
25 /// Window title.
26 pub title: String,
27 /// Window app ID.
28 ///
29 /// This is actually the name of the .desktop file, and Shell does internal tracking to match
30 /// Wayland app IDs to desktop files. We don't do that yet, which is the reason why
31 /// xdg-desktop-portal-gnome's window list is missing icons.
32 #[zvariant(rename = "app-id")]
33 pub app_id: String,
34}
35
36#[interface(name = "org.gnome.Shell.Introspect")]
37impl Introspect {
38 async fn get_windows(&self) -> fdo::Result<HashMap<u64, WindowProperties>> {
39 if let Err(err) = self.to_niri.send(IntrospectToNiri::GetWindows) {
40 warn!("error sending message to niri: {err:?}");
41 return Err(fdo::Error::Failed("internal error".to_owned()));
42 }
43
44 match self.from_niri.recv().await {
45 Ok(NiriToIntrospect::Windows(windows)) => Ok(windows),
46 Err(err) => {
47 warn!("error receiving message from niri: {err:?}");
48 Err(fdo::Error::Failed("internal error".to_owned()))
49 }
50 }
51 }
52
53 // FIXME: call this upon window changes, once more of the infrastructure is there (will be
54 // needed for the event stream IPC anyway).
55 #[zbus(signal)]
56 pub async fn windows_changed(ctxt: &SignalEmitter<'_>) -> zbus::Result<()>;
57}
58
59impl Introspect {
60 pub fn new(
61 to_niri: calloop::channel::Sender<IntrospectToNiri>,
62 from_niri: async_channel::Receiver<NiriToIntrospect>,
63 ) -> Self {
64 Self { to_niri, from_niri }
65 }
66}
67
68impl Start for Introspect {
69 fn start(self, monitor: bool) -> anyhow::Result<zbus::blocking::Connection> {
70 let conn = zbus::blocking::Connection::session()?;
71 conn.object_server()
72 .at("/org/gnome/Shell/Introspect", self)?;
73 request_name(&conn, "org.gnome.Shell.Introspect", monitor)?;
74
75 Ok(conn)
76 }
77}