From ea5e36e9fd8386cddeb590dbe663ce2edbd9b97d Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Tue, 6 Dec 2022 11:59:34 +0000 Subject: [PATCH] screensaver: Catch activeness changes --- Cargo.deps.newer | 3 +- Cargo.toml.in | 1 + meson.build | 2 +- src/actors/external/mod.rs | 4 +- src/actors/external/screensaver.rs | 67 ++++++++++++++++++++++++++++++ src/lib.rs | 2 +- src/main.rs | 4 ++ 7 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/actors/external/screensaver.rs diff --git a/Cargo.deps.newer b/Cargo.deps.newer index 914cc6aa..8dfae554 100644 --- a/Cargo.deps.newer +++ b/Cargo.deps.newer @@ -1,5 +1,6 @@ -# Dependencies which change based on build flags +# Dependencies and tools which change based on build flags # For the newer-than-Byzantium config + bitflags = "1.3.*" clap = { version = "3.2.*", features=["std"], default-features = false } zbus = "1.9.*" diff --git a/Cargo.toml.in b/Cargo.toml.in index b69e0df9..18f2cdf9 100644 --- a/Cargo.toml.in +++ b/Cargo.toml.in @@ -22,6 +22,7 @@ path = "@path@/examples/find_orphan_layouts.rs" [features] glib_v0_14 = [] +zbus_v1_5 = [] # Dependencies which don't change based on build flags [dependencies] diff --git a/meson.build b/meson.build index a80afa29..a3eeb947 100644 --- a/meson.build +++ b/meson.build @@ -99,7 +99,7 @@ cargo_toml_base = configure_file( cargo_patch = [] if get_option('newer') == true - cargo_build_flags += ['--features', 'glib_v0_14'] + cargo_build_flags += ['--features', 'glib_v0_14,zbus_v1_5'] cargo_deps = files('Cargo.deps.newer') cargo_lock = files('Cargo.lock.newer') else diff --git a/src/actors/external/mod.rs b/src/actors/external/mod.rs index 33344af4..624d89da 100644 --- a/src/actors/external/mod.rs +++ b/src/actors/external/mod.rs @@ -6,4 +6,6 @@ /*! Contains actors with custom event loops, not based off of the event_loop module. */ -pub mod debug; \ No newline at end of file +pub mod debug; +#[cfg(feature = "zbus_v1_5")] +pub mod screensaver; \ No newline at end of file diff --git a/src/actors/external/screensaver.rs b/src/actors/external/screensaver.rs new file mode 100644 index 00000000..bc496f2a --- /dev/null +++ b/src/actors/external/screensaver.rs @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 Purism SPC + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +use std::thread; +use zbus::{Connection, dbus_proxy}; + +use crate::logging; + + +#[derive(Debug)] +enum Event { + ScreensaverActive(bool), +} + +#[dbus_proxy( + interface = "org.freedesktop.ScreenSaver", + default_service = "org.freedesktop.ScreenSaver", + default_path = "/org/freedesktop/ScreenSaver" +)] +pub trait Manager { + #[dbus_proxy(signal)] + fn active_changed(&self, active: bool) -> fdo::Result<()>; +} + +pub struct Destination; + +impl Destination { + fn send(&self, event: Event) { + dbg!(event); + } +} + +/// Listens to screensaver (screen lock) changes +pub fn init(destination: Destination) { + thread::spawn(move || { + if let Err(e) = start(destination) { + log_print!( + logging::Level::Surprise, + "Could not track screensaver status, giving up: {:?}", + e, + ); + } + }); +} + +fn start(destination: Destination) -> Result<(), zbus::Error> { + let conn = Connection::new_session()?; + let manager = ManagerProxy::new(&conn)?; + + manager.connect_active_changed(move |m| { + destination.send(Event::ScreensaverActive(m)); + Ok(()) + })?; + + loop { + match manager.next_signal() { + Ok(None) => {} + other => log_print!( + logging::Level::Bug, + "Encountered unhandled event: {:?}", + other, + ), + } + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 84feb8e3..16885743 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ mod assert_matches; mod logging; mod action; -mod actors; +pub mod actors; mod animation; pub mod data; mod drawing; diff --git a/src/main.rs b/src/main.rs index f9ea1b4b..92a3e3cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,6 +121,10 @@ mod c { }; let submission = Submission::new(vk, imservice); + // dummy for now + #[cfg(feature = "zbus_v1_5")] + crate::actors::external::screensaver::init(crate::actors::external::screensaver::Destination); + RsObjects { submission: Wrapped::new(submission), state_manager: Wrapped::new(state_manager),