niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·64a9351·Ivan Molodetskikh·2 years ago·1319 commits
| 1 | use zbus::blocking::Connection; |
| 2 | use zbus::Interface; |
| 3 | |
| 4 | use crate::niri::State; |
| 5 | |
| 6 | pub mod freedesktop_screensaver; |
| 7 | pub mod gnome_shell_introspect; |
| 8 | pub mod gnome_shell_screenshot; |
| 9 | pub mod mutter_display_config; |
| 10 | pub mod mutter_service_channel; |
| 11 | |
| 12 | #[cfg(feature = "xdp-gnome-screencast")] |
| 13 | pub mod mutter_screen_cast; |
| 14 | #[cfg(feature = "xdp-gnome-screencast")] |
| 15 | use mutter_screen_cast::ScreenCast; |
| 16 | |
| 17 | use self::freedesktop_screensaver::ScreenSaver; |
| 18 | use self::gnome_shell_introspect::Introspect; |
| 19 | use self::mutter_display_config::DisplayConfig; |
| 20 | use self::mutter_service_channel::ServiceChannel; |
| 21 | |
| 22 | trait Start: Interface { |
| 23 | fn start(self) -> anyhow::Result<zbus::blocking::Connection>; |
| 24 | } |
| 25 | |
| 26 | #[derive(Default)] |
| 27 | pub struct DBusServers { |
| 28 | pub conn_service_channel: Option<Connection>, |
| 29 | pub conn_display_config: Option<Connection>, |
| 30 | pub conn_screen_saver: Option<Connection>, |
| 31 | pub conn_screen_shot: Option<Connection>, |
| 32 | pub conn_introspect: Option<Connection>, |
| 33 | #[cfg(feature = "xdp-gnome-screencast")] |
| 34 | pub conn_screen_cast: Option<Connection>, |
| 35 | } |
| 36 | |
| 37 | impl DBusServers { |
| 38 | pub fn start(state: &mut State, is_session_instance: bool) { |
| 39 | let _span = tracy_client::span!("DBusServers::start"); |
| 40 | |
| 41 | let backend = &state.backend; |
| 42 | let niri = &mut state.niri; |
| 43 | let config = niri.config.borrow(); |
| 44 | |
| 45 | let mut dbus = Self::default(); |
| 46 | |
| 47 | if is_session_instance { |
| 48 | let service_channel = ServiceChannel::new(niri.display_handle.clone()); |
| 49 | dbus.conn_service_channel = try_start(service_channel); |
| 50 | } |
| 51 | |
| 52 | if is_session_instance || config.debug.dbus_interfaces_in_non_session_instances { |
| 53 | let display_config = DisplayConfig::new(backend.ipc_outputs()); |
| 54 | dbus.conn_display_config = try_start(display_config); |
| 55 | |
| 56 | let screen_saver = ScreenSaver::new(niri.is_fdo_idle_inhibited.clone()); |
| 57 | dbus.conn_screen_saver = try_start(screen_saver); |
| 58 | |
| 59 | let (to_niri, from_screenshot) = calloop::channel::channel(); |
| 60 | let (to_screenshot, from_niri) = async_channel::unbounded(); |
| 61 | niri.event_loop |
| 62 | .insert_source(from_screenshot, move |event, _, state| match event { |
| 63 | calloop::channel::Event::Msg(msg) => { |
| 64 | state.on_screen_shot_msg(&to_screenshot, msg) |
| 65 | } |
| 66 | calloop::channel::Event::Closed => (), |
| 67 | }) |
| 68 | .unwrap(); |
| 69 | let screenshot = gnome_shell_screenshot::Screenshot::new(to_niri, from_niri); |
| 70 | dbus.conn_screen_shot = try_start(screenshot); |
| 71 | |
| 72 | let (to_niri, from_introspect) = calloop::channel::channel(); |
| 73 | let (to_introspect, from_niri) = async_channel::unbounded(); |
| 74 | niri.event_loop |
| 75 | .insert_source(from_introspect, move |event, _, state| match event { |
| 76 | calloop::channel::Event::Msg(msg) => { |
| 77 | state.on_introspect_msg(&to_introspect, msg) |
| 78 | } |
| 79 | calloop::channel::Event::Closed => (), |
| 80 | }) |
| 81 | .unwrap(); |
| 82 | let introspect = Introspect::new(to_niri, from_niri); |
| 83 | dbus.conn_introspect = try_start(introspect); |
| 84 | |
| 85 | #[cfg(feature = "xdp-gnome-screencast")] |
| 86 | if niri.pipewire.is_some() { |
| 87 | let (to_niri, from_screen_cast) = calloop::channel::channel(); |
| 88 | niri.event_loop |
| 89 | .insert_source(from_screen_cast, { |
| 90 | move |event, _, state| match event { |
| 91 | calloop::channel::Event::Msg(msg) => state.on_screen_cast_msg(msg), |
| 92 | calloop::channel::Event::Closed => (), |
| 93 | } |
| 94 | }) |
| 95 | .unwrap(); |
| 96 | let screen_cast = ScreenCast::new(backend.ipc_outputs(), to_niri); |
| 97 | dbus.conn_screen_cast = try_start(screen_cast); |
| 98 | } else { |
| 99 | warn!("disabling screencast support because we couldn't start PipeWire"); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | niri.dbus = Some(dbus); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | fn try_start<I: Start>(iface: I) -> Option<Connection> { |
| 108 | match iface.start() { |
| 109 | Ok(conn) => Some(conn), |
| 110 | Err(err) => { |
| 111 | warn!("error starting {}: {err:?}", I::name()); |
| 112 | None |
| 113 | } |
| 114 | } |
| 115 | } |