2023-10-10 09:55:44 +04:00
|
|
|
use zbus::blocking::Connection;
|
|
|
|
|
use zbus::Interface;
|
|
|
|
|
|
|
|
|
|
use crate::niri::State;
|
|
|
|
|
|
2024-02-11 10:59:57 +04:00
|
|
|
pub mod freedesktop_screensaver;
|
2023-09-20 09:28:23 +04:00
|
|
|
pub mod gnome_shell_screenshot;
|
2023-09-08 17:54:02 +04:00
|
|
|
pub mod mutter_display_config;
|
2023-10-10 09:55:44 +04:00
|
|
|
pub mod mutter_service_channel;
|
|
|
|
|
|
2023-09-30 09:58:34 +04:00
|
|
|
#[cfg(feature = "xdp-gnome-screencast")]
|
2023-09-08 17:54:02 +04:00
|
|
|
pub mod mutter_screen_cast;
|
2023-10-10 09:55:44 +04:00
|
|
|
#[cfg(feature = "xdp-gnome-screencast")]
|
|
|
|
|
use mutter_screen_cast::ScreenCast;
|
|
|
|
|
|
2024-02-11 10:59:57 +04:00
|
|
|
use self::freedesktop_screensaver::ScreenSaver;
|
2023-10-10 09:55:44 +04:00
|
|
|
use self::mutter_display_config::DisplayConfig;
|
|
|
|
|
use self::mutter_service_channel::ServiceChannel;
|
|
|
|
|
|
|
|
|
|
trait Start: Interface {
|
|
|
|
|
fn start(self) -> anyhow::Result<zbus::blocking::Connection>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
pub struct DBusServers {
|
|
|
|
|
pub conn_service_channel: Option<Connection>,
|
|
|
|
|
pub conn_display_config: Option<Connection>,
|
2024-02-11 10:59:57 +04:00
|
|
|
pub conn_screen_saver: Option<Connection>,
|
2023-10-10 09:55:44 +04:00
|
|
|
pub conn_screen_shot: Option<Connection>,
|
|
|
|
|
#[cfg(feature = "xdp-gnome-screencast")]
|
|
|
|
|
pub conn_screen_cast: Option<Connection>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl DBusServers {
|
|
|
|
|
pub fn start(state: &mut State, is_session_instance: bool) {
|
|
|
|
|
let _span = tracy_client::span!("DBusServers::start");
|
|
|
|
|
|
|
|
|
|
let backend = &state.backend;
|
|
|
|
|
let niri = &mut state.niri;
|
|
|
|
|
let config = niri.config.borrow();
|
|
|
|
|
|
|
|
|
|
let mut dbus = Self::default();
|
|
|
|
|
|
|
|
|
|
if is_session_instance {
|
|
|
|
|
let service_channel = ServiceChannel::new(niri.display_handle.clone());
|
|
|
|
|
dbus.conn_service_channel = try_start(service_channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if is_session_instance || config.debug.dbus_interfaces_in_non_session_instances {
|
2024-01-17 10:25:23 +04:00
|
|
|
let display_config = DisplayConfig::new(backend.enabled_outputs());
|
2023-10-10 09:55:44 +04:00
|
|
|
dbus.conn_display_config = try_start(display_config);
|
|
|
|
|
|
2024-02-11 10:59:57 +04:00
|
|
|
let screen_saver = ScreenSaver::new(niri.is_fdo_idle_inhibited.clone());
|
|
|
|
|
dbus.conn_screen_saver = try_start(screen_saver);
|
|
|
|
|
|
2023-10-10 09:55:44 +04:00
|
|
|
let (to_niri, from_screenshot) = calloop::channel::channel();
|
|
|
|
|
let (to_screenshot, from_niri) = async_channel::unbounded();
|
|
|
|
|
niri.event_loop
|
|
|
|
|
.insert_source(from_screenshot, move |event, _, state| match event {
|
|
|
|
|
calloop::channel::Event::Msg(msg) => {
|
|
|
|
|
state.on_screen_shot_msg(&to_screenshot, msg)
|
|
|
|
|
}
|
|
|
|
|
calloop::channel::Event::Closed => (),
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
let screenshot = gnome_shell_screenshot::Screenshot::new(to_niri, from_niri);
|
|
|
|
|
dbus.conn_screen_shot = try_start(screenshot);
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "xdp-gnome-screencast")]
|
|
|
|
|
{
|
|
|
|
|
let (to_niri, from_screen_cast) = calloop::channel::channel();
|
|
|
|
|
niri.event_loop
|
|
|
|
|
.insert_source(from_screen_cast, {
|
|
|
|
|
let to_niri = to_niri.clone();
|
|
|
|
|
move |event, _, state| match event {
|
|
|
|
|
calloop::channel::Event::Msg(msg) => {
|
|
|
|
|
state.on_screen_cast_msg(&to_niri, msg)
|
|
|
|
|
}
|
|
|
|
|
calloop::channel::Event::Closed => (),
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
2024-01-17 10:25:23 +04:00
|
|
|
let screen_cast = ScreenCast::new(backend.enabled_outputs(), to_niri);
|
2023-10-10 09:55:44 +04:00
|
|
|
dbus.conn_screen_cast = try_start(screen_cast);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
niri.dbus = Some(dbus);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn try_start<I: Start>(iface: I) -> Option<Connection> {
|
|
|
|
|
match iface.start() {
|
|
|
|
|
Ok(conn) => Some(conn),
|
|
|
|
|
Err(err) => {
|
|
|
|
|
warn!("error starting {}: {err:?}", I::name());
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|