screensaver: Catch activeness changes
This commit is contained in:
@ -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
|
# For the newer-than-Byzantium config
|
||||||
|
|
||||||
bitflags = "1.3.*"
|
bitflags = "1.3.*"
|
||||||
clap = { version = "3.2.*", features=["std"], default-features = false }
|
clap = { version = "3.2.*", features=["std"], default-features = false }
|
||||||
zbus = "1.9.*"
|
zbus = "1.9.*"
|
||||||
|
|||||||
@ -22,6 +22,7 @@ path = "@path@/examples/find_orphan_layouts.rs"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
glib_v0_14 = []
|
glib_v0_14 = []
|
||||||
|
zbus_v1_5 = []
|
||||||
|
|
||||||
# Dependencies which don't change based on build flags
|
# Dependencies which don't change based on build flags
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -99,7 +99,7 @@ cargo_toml_base = configure_file(
|
|||||||
cargo_patch = []
|
cargo_patch = []
|
||||||
|
|
||||||
if get_option('newer') == true
|
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_deps = files('Cargo.deps.newer')
|
||||||
cargo_lock = files('Cargo.lock.newer')
|
cargo_lock = files('Cargo.lock.newer')
|
||||||
else
|
else
|
||||||
|
|||||||
4
src/actors/external/mod.rs
vendored
4
src/actors/external/mod.rs
vendored
@ -6,4 +6,6 @@
|
|||||||
|
|
||||||
/*! Contains actors with custom event loops, not based off of the event_loop module. */
|
/*! Contains actors with custom event loops, not based off of the event_loop module. */
|
||||||
|
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
|
#[cfg(feature = "zbus_v1_5")]
|
||||||
|
pub mod screensaver;
|
||||||
67
src/actors/external/screensaver.rs
vendored
Normal file
67
src/actors/external/screensaver.rs
vendored
Normal 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,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,7 +23,7 @@ mod assert_matches;
|
|||||||
mod logging;
|
mod logging;
|
||||||
|
|
||||||
mod action;
|
mod action;
|
||||||
mod actors;
|
pub mod actors;
|
||||||
mod animation;
|
mod animation;
|
||||||
pub mod data;
|
pub mod data;
|
||||||
mod drawing;
|
mod drawing;
|
||||||
|
|||||||
@ -121,6 +121,10 @@ mod c {
|
|||||||
};
|
};
|
||||||
let submission = Submission::new(vk, imservice);
|
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 {
|
RsObjects {
|
||||||
submission: Wrapped::new(submission),
|
submission: Wrapped::new(submission),
|
||||||
state_manager: Wrapped::new(state_manager),
|
state_manager: Wrapped::new(state_manager),
|
||||||
|
|||||||
Reference in New Issue
Block a user