popover: Connect to screensaver event

This commit is contained in:
Dorota Czaplejewicz
2022-12-07 15:13:16 +00:00
parent 3366090454
commit c590064ce3
3 changed files with 16 additions and 28 deletions

View File

@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
use crate::actors::Destination;
use crate::actors::popover;
use crate::logging;
use std::thread;
use zbus::{Connection, dbus_proxy};
@ -10,11 +12,6 @@ use zbus::{Connection, dbus_proxy};
use super::Void;
#[derive(Debug)]
enum Event {
ScreensaverActive(bool),
}
#[dbus_proxy(
interface = "org.freedesktop.ScreenSaver",
default_service = "org.freedesktop.ScreenSaver",
@ -25,16 +22,8 @@ pub trait Manager {
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) {
pub fn init(destination: popover::Destination) {
thread::spawn(move || {
if let Err(e) = start(destination) {
log_print!(
@ -46,12 +35,12 @@ pub fn init(destination: Destination) {
});
}
fn start(destination: Destination) -> Result<Void, zbus::Error> {
fn start(destination: popover::Destination) -> Result<Void, zbus::Error> {
let conn = Connection::new_session()?;
let manager = ManagerProxy::new(&conn)?;
manager.connect_active_changed(move |m| {
destination.send(Event::ScreensaverActive(m));
destination.send(popover::Event::ScreensaverActive(m));
Ok(())
})?;