From c590064ce304d0687a8c173e9128e3b9b8a288e0 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Wed, 7 Dec 2022 15:13:16 +0000 Subject: [PATCH] popover: Connect to screensaver event --- src/actors/external/screensaver.rs | 21 +++++---------------- src/actors/popover.rs | 12 +++++------- src/main.rs | 11 ++++++----- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/actors/external/screensaver.rs b/src/actors/external/screensaver.rs index e0a5b338..7f5afe24 100644 --- a/src/actors/external/screensaver.rs +++ b/src/actors/external/screensaver.rs @@ -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 { +fn start(destination: popover::Destination) -> Result { 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(()) })?; diff --git a/src/actors/popover.rs b/src/actors/popover.rs index 7e8616ab..fc28709f 100644 --- a/src/actors/popover.rs +++ b/src/actors/popover.rs @@ -13,7 +13,7 @@ and updated by main state every time it changes. */ use crate::logging; use std::borrow::BorrowMut; -use super::Destination; +use std::sync::{Arc, Mutex}; pub mod c { use super::*; @@ -23,21 +23,19 @@ pub mod c { /// and therefore can't have a channel to receive messages, /// so instead messages will be passed directly to the mutexed actor. pub type Actor = ArcWrapped; - /// It's the same because the state is a simple mutex-protected type. - /// There are no channels involved. - pub type Destination = ArcWrapped; } +pub type Destination = Arc>; + pub enum Event { Overlay(Option), ScreensaverActive(bool), } -impl Destination for c::Destination { +impl super::Destination for Destination { type Event = Event; fn send(&self, event: Self::Event) { - let actor = self.clone_ref(); - let actor = actor.lock(); + let actor = self.lock(); match actor { Ok(mut actor) => { let actor = actor.borrow_mut(); diff --git a/src/main.rs b/src/main.rs index b51a6114..68e7b7ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,16 +123,17 @@ mod c { }; let submission = Submission::new(vk, imservice); - // dummy for now + let popover = ArcWrapped::new(actors::popover::State::new(true)); + #[cfg(feature = "zbus_v1_5")] - crate::actors::external::screensaver::init(crate::actors::external::screensaver::Destination); + crate::actors::external::screensaver::init(popover.clone_ref()); RsObjects { submission: Wrapped::new(submission), state_manager: Wrapped::new(state_manager), receiver: Wrapped::new(receiver), wayland: Box::into_raw(wayland), - popover: ArcWrapped::new(actors::popover::State::new(true)), + popover, } } @@ -158,7 +159,7 @@ mod c { main_loop_handle_message( msg, panel_manager.clone(), - &popover, + &popover.clone_ref(), hint_manager, dbus_handler, ); @@ -176,7 +177,7 @@ mod c { fn main_loop_handle_message( msg: Commands, panel_manager: Wrapped, - popover: &actors::popover::c::Destination, + popover: &actors::popover::Destination, hint_manager: HintManager, dbus_handler: *const DBusHandler, ) {