popover: Connect to screensaver event
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/actors/external/screensaver.rs
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										21
									
								
								src/actors/external/screensaver.rs
									
									
									
									
										vendored
									
									
								
							@ -3,6 +3,8 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * SPDX-License-Identifier: GPL-3.0-or-later
 | 
					 * SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					use crate::actors::Destination;
 | 
				
			||||||
 | 
					use crate::actors::popover;
 | 
				
			||||||
use crate::logging;
 | 
					use crate::logging;
 | 
				
			||||||
use std::thread;
 | 
					use std::thread;
 | 
				
			||||||
use zbus::{Connection, dbus_proxy};
 | 
					use zbus::{Connection, dbus_proxy};
 | 
				
			||||||
@ -10,11 +12,6 @@ use zbus::{Connection, dbus_proxy};
 | 
				
			|||||||
use super::Void;
 | 
					use super::Void;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug)]
 | 
					 | 
				
			||||||
enum Event {
 | 
					 | 
				
			||||||
    ScreensaverActive(bool),
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[dbus_proxy(
 | 
					#[dbus_proxy(
 | 
				
			||||||
    interface = "org.freedesktop.ScreenSaver",
 | 
					    interface = "org.freedesktop.ScreenSaver",
 | 
				
			||||||
    default_service = "org.freedesktop.ScreenSaver",
 | 
					    default_service = "org.freedesktop.ScreenSaver",
 | 
				
			||||||
@ -25,16 +22,8 @@ pub trait Manager {
 | 
				
			|||||||
    fn active_changed(&self, active: bool) -> fdo::Result<()>;
 | 
					    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
 | 
					/// Listens to screensaver (screen lock) changes
 | 
				
			||||||
pub fn init(destination: Destination) {
 | 
					pub fn init(destination: popover::Destination) {
 | 
				
			||||||
    thread::spawn(move || {
 | 
					    thread::spawn(move || {
 | 
				
			||||||
        if let Err(e) = start(destination) {
 | 
					        if let Err(e) = start(destination) {
 | 
				
			||||||
            log_print!(
 | 
					            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 conn = Connection::new_session()?;
 | 
				
			||||||
    let manager = ManagerProxy::new(&conn)?;
 | 
					    let manager = ManagerProxy::new(&conn)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    manager.connect_active_changed(move |m| {
 | 
					    manager.connect_active_changed(move |m| {
 | 
				
			||||||
        destination.send(Event::ScreensaverActive(m));
 | 
					        destination.send(popover::Event::ScreensaverActive(m));
 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    })?;
 | 
					    })?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ and updated by main state every time it changes.
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
use crate::logging;
 | 
					use crate::logging;
 | 
				
			||||||
use std::borrow::BorrowMut;
 | 
					use std::borrow::BorrowMut;
 | 
				
			||||||
use super::Destination;
 | 
					use std::sync::{Arc, Mutex};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod c {
 | 
					pub mod c {
 | 
				
			||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
@ -23,21 +23,19 @@ pub mod c {
 | 
				
			|||||||
    /// and therefore can't have a channel to receive messages,
 | 
					    /// and therefore can't have a channel to receive messages,
 | 
				
			||||||
    /// so instead messages will be passed directly to the mutexed actor.
 | 
					    /// so instead messages will be passed directly to the mutexed actor.
 | 
				
			||||||
    pub type Actor = ArcWrapped<State>;
 | 
					    pub type Actor = ArcWrapped<State>;
 | 
				
			||||||
    /// It's the same because the state is a simple mutex-protected type.
 | 
					 | 
				
			||||||
    /// There are no channels involved.
 | 
					 | 
				
			||||||
    pub type Destination = ArcWrapped<State>;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub type Destination = Arc<Mutex<State>>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub enum Event {
 | 
					pub enum Event {
 | 
				
			||||||
    Overlay(Option<String>),
 | 
					    Overlay(Option<String>),
 | 
				
			||||||
    ScreensaverActive(bool),
 | 
					    ScreensaverActive(bool),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Destination for c::Destination {
 | 
					impl super::Destination for Destination {
 | 
				
			||||||
    type Event = Event;
 | 
					    type Event = Event;
 | 
				
			||||||
    fn send(&self, event: Self::Event) {
 | 
					    fn send(&self, event: Self::Event) {
 | 
				
			||||||
        let actor = self.clone_ref();
 | 
					        let actor = self.lock();
 | 
				
			||||||
        let actor = actor.lock();
 | 
					 | 
				
			||||||
        match actor {
 | 
					        match actor {
 | 
				
			||||||
            Ok(mut actor) => {
 | 
					            Ok(mut actor) => {
 | 
				
			||||||
                let actor = actor.borrow_mut();
 | 
					                let actor = actor.borrow_mut();
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										11
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.rs
									
									
									
									
									
								
							@ -123,16 +123,17 @@ mod c {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
        let submission = Submission::new(vk, imservice);
 | 
					        let submission = Submission::new(vk, imservice);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        // dummy for now
 | 
					        let popover = ArcWrapped::new(actors::popover::State::new(true));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #[cfg(feature = "zbus_v1_5")]
 | 
					        #[cfg(feature = "zbus_v1_5")]
 | 
				
			||||||
        crate::actors::external::screensaver::init(crate::actors::external::screensaver::Destination);
 | 
					        crate::actors::external::screensaver::init(popover.clone_ref());
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        RsObjects {
 | 
					        RsObjects {
 | 
				
			||||||
            submission: Wrapped::new(submission),
 | 
					            submission: Wrapped::new(submission),
 | 
				
			||||||
            state_manager: Wrapped::new(state_manager),
 | 
					            state_manager: Wrapped::new(state_manager),
 | 
				
			||||||
            receiver: Wrapped::new(receiver),
 | 
					            receiver: Wrapped::new(receiver),
 | 
				
			||||||
            wayland: Box::into_raw(wayland),
 | 
					            wayland: Box::into_raw(wayland),
 | 
				
			||||||
            popover: ArcWrapped::new(actors::popover::State::new(true)),
 | 
					             popover,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -158,7 +159,7 @@ mod c {
 | 
				
			|||||||
                main_loop_handle_message(
 | 
					                main_loop_handle_message(
 | 
				
			||||||
                    msg,
 | 
					                    msg,
 | 
				
			||||||
                    panel_manager.clone(),
 | 
					                    panel_manager.clone(),
 | 
				
			||||||
                    &popover,
 | 
					                    &popover.clone_ref(),
 | 
				
			||||||
                    hint_manager,
 | 
					                    hint_manager,
 | 
				
			||||||
                    dbus_handler,
 | 
					                    dbus_handler,
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
@ -176,7 +177,7 @@ mod c {
 | 
				
			|||||||
    fn main_loop_handle_message(
 | 
					    fn main_loop_handle_message(
 | 
				
			||||||
        msg: Commands,
 | 
					        msg: Commands,
 | 
				
			||||||
        panel_manager: Wrapped<panel::Manager>,
 | 
					        panel_manager: Wrapped<panel::Manager>,
 | 
				
			||||||
        popover: &actors::popover::c::Destination,
 | 
					        popover: &actors::popover::Destination,
 | 
				
			||||||
        hint_manager: HintManager,
 | 
					        hint_manager: HintManager,
 | 
				
			||||||
        dbus_handler: *const DBusHandler,
 | 
					        dbus_handler: *const DBusHandler,
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user