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
|
||||
*/
|
||||
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(())
|
||||
})?;
|
||||
|
||||
|
||||
@ -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<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 {
|
||||
Overlay(Option<String>),
|
||||
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();
|
||||
|
||||
11
src/main.rs
11
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<panel::Manager>,
|
||||
popover: &actors::popover::c::Destination,
|
||||
popover: &actors::popover::Destination,
|
||||
hint_manager: HintManager,
|
||||
dbus_handler: *const DBusHandler,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user