screensaver: Catch activeness changes

This commit is contained in:
Dorota Czaplejewicz
2022-12-06 11:59:34 +00:00
parent 783ca9ae11
commit ea5e36e9fd
7 changed files with 79 additions and 4 deletions

View File

@ -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.*"

View File

@ -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]

View File

@ -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

View File

@ -7,3 +7,5 @@
/*! Contains actors with custom event loops, not based off of the event_loop module. */
pub mod debug;
#[cfg(feature = "zbus_v1_5")]
pub mod screensaver;

67
src/actors/external/screensaver.rs vendored Normal file
View File

@ -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,
),
}
}
}

View File

@ -23,7 +23,7 @@ mod assert_matches;
mod logging;
mod action;
mod actors;
pub mod actors;
mod animation;
pub mod data;
mod drawing;

View File

@ -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),