niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·9ff2f83·Ivan Molodetskikh·1 year ago·2099 commits
| 1 | use zbus::blocking::Connection; |
| 2 | use zbus::object_server::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 (to_niri, from_service_channel) = calloop::channel::channel(); |
| 49 | let service_channel = ServiceChannel::new(to_niri); |
| 50 | niri.event_loop |
| 51 | .insert_source(from_service_channel, move |event, _, state| match event { |
| 52 | calloop::channel::Event::Msg(new_client) => { |
| 53 | state.niri.insert_client(new_client); |
| 54 | } |
| 55 | calloop::channel::Event::Closed => (), |
| 56 | }) |
| 57 | .unwrap(); |
| 58 | dbus.conn_service_channel = try_start(service_channel); |
| 59 | } |
| 60 | |
| 61 | if is_session_instance || config.debug.dbus_interfaces_in_non_session_instances { |
| 62 | let (to_niri, from_display_config) = calloop::channel::channel(); |
| 63 | let display_config = DisplayConfig::new(to_niri, backend.ipc_outputs()); |
| 64 | niri.event_loop |
| 65 | .insert_source(from_display_config, move |event, _, state| match event { |
| 66 | calloop::channel::Event::Msg(new_conf) => { |
| 67 | for (name, conf) in new_conf { |
| 68 | state.modify_output_config(&name, move |output| { |
| 69 | if let Some(new_output) = conf { |
| 70 | *output = new_output; |
| 71 | } else { |
| 72 | output.off = true; |
| 73 | } |
| 74 | }); |
| 75 | } |
| 76 | state.reload_output_config(); |
| 77 | } |
| 78 | calloop::channel::Event::Closed => (), |
| 79 | }) |
| 80 | .unwrap(); |
| 81 | dbus.conn_display_config = try_start(display_config); |
| 82 | |
| 83 | let screen_saver = ScreenSaver::new(niri.is_fdo_idle_inhibited.clone()); |
| 84 | dbus.conn_screen_saver = try_start(screen_saver); |
| 85 | |
| 86 | let (to_niri, from_screenshot) = calloop::channel::channel(); |
| 87 | let (to_screenshot, from_niri) = async_channel::unbounded(); |
| 88 | niri.event_loop |
| 89 | .insert_source(from_screenshot, move |event, _, state| match event { |
| 90 | calloop::channel::Event::Msg(msg) => { |
| 91 | state.on_screen_shot_msg(&to_screenshot, msg) |
| 92 | } |
| 93 | calloop::channel::Event::Closed => (), |
| 94 | }) |
| 95 | .unwrap(); |
| 96 | let screenshot = gnome_shell_screenshot::Screenshot::new(to_niri, from_niri); |
| 97 | dbus.conn_screen_shot = try_start(screenshot); |
| 98 | |
| 99 | let (to_niri, from_introspect) = calloop::channel::channel(); |
| 100 | let (to_introspect, from_niri) = async_channel::unbounded(); |
| 101 | niri.event_loop |
| 102 | .insert_source(from_introspect, move |event, _, state| match event { |
| 103 | calloop::channel::Event::Msg(msg) => { |
| 104 | state.on_introspect_msg(&to_introspect, msg) |
| 105 | } |
| 106 | calloop::channel::Event::Closed => (), |
| 107 | }) |
| 108 | .unwrap(); |
| 109 | let introspect = Introspect::new(to_niri, from_niri); |
| 110 | dbus.conn_introspect = try_start(introspect); |
| 111 | |
| 112 | #[cfg(feature = "xdp-gnome-screencast")] |
| 113 | { |
| 114 | let (to_niri, from_screen_cast) = calloop::channel::channel(); |
| 115 | niri.event_loop |
| 116 | .insert_source(from_screen_cast, { |
| 117 | move |event, _, state| match event { |
| 118 | calloop::channel::Event::Msg(msg) => state.on_screen_cast_msg(msg), |
| 119 | calloop::channel::Event::Closed => (), |
| 120 | } |
| 121 | }) |
| 122 | .unwrap(); |
| 123 | let screen_cast = ScreenCast::new(backend.ipc_outputs(), to_niri); |
| 124 | dbus.conn_screen_cast = try_start(screen_cast); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | niri.dbus = Some(dbus); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | fn try_start<I: Start>(iface: I) -> Option<Connection> { |
| 133 | match iface.start() { |
| 134 | Ok(conn) => Some(conn), |
| 135 | Err(err) => { |
| 136 | warn!("error starting {}: {err:?}", I::name()); |
| 137 | None |
| 138 | } |
| 139 | } |
| 140 | } |