popover: Able to receive screensaver events
This commit is contained in:
@ -22,3 +22,12 @@ and by receiving updates from it.
|
|||||||
|
|
||||||
pub mod external;
|
pub mod external;
|
||||||
pub mod popover;
|
pub mod popover;
|
||||||
|
|
||||||
|
/// The implementing actor is able to receive and handle messages.
|
||||||
|
/// Typically, it's the sending end of the channel,
|
||||||
|
/// whose other end is inside an event loop.
|
||||||
|
// TODO: implement for remaning actors and make the event loop refer to this.
|
||||||
|
pub trait Destination {
|
||||||
|
type Event;
|
||||||
|
fn send(&self, event: Self::Event);
|
||||||
|
}
|
||||||
|
|||||||
@ -11,30 +11,52 @@ but it cannot get the user-selected overlay, because it's stored in state.
|
|||||||
To solve this, overlay will be cached in the popover actor,
|
To solve this, overlay will be cached in the popover actor,
|
||||||
and updated by main state every time it changes.
|
and updated by main state every time it changes.
|
||||||
*/
|
*/
|
||||||
|
use super::Destination;
|
||||||
|
|
||||||
pub mod c {
|
pub mod c {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::util::c::Wrapped;
|
use crate::util::c::Wrapped;
|
||||||
/// The mutable instance of state
|
/// The mutable instance of state
|
||||||
pub type Actor = Wrapped<State>;
|
pub type Actor = Wrapped<State>;
|
||||||
|
/// It's the same because the state is a simple mutex-protected type.
|
||||||
|
/// There are no channels involved.
|
||||||
|
pub type Destination = Wrapped<State>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Event {
|
||||||
|
Overlay(Option<String>),
|
||||||
|
ScreensaverActive(bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Destination for c::Destination {
|
||||||
|
type Event = Event;
|
||||||
|
fn send(&self, event: Self::Event) {
|
||||||
|
let actor = self.clone_ref();
|
||||||
|
let mut actor = actor.borrow_mut();
|
||||||
|
*actor = actor.clone().handle_event(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
pub overlay: Option<String>,
|
pub overlay: Option<String>,
|
||||||
|
/// Settings button active
|
||||||
|
pub settings_active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
pub fn new() -> Self {
|
pub fn new(settings_active: bool) -> Self {
|
||||||
Self { overlay: None }
|
Self {
|
||||||
|
overlay: None,
|
||||||
|
settings_active,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_overlay(
|
fn handle_event(mut self, event: Event) -> Self {
|
||||||
actor: &c::Actor,
|
match event {
|
||||||
overlay: Option<String>,
|
Event::Overlay(overlay) => { self.overlay = overlay; },
|
||||||
) {
|
Event::ScreensaverActive(lock_active) => { self.settings_active = !lock_active; },
|
||||||
let actor = actor.clone_ref();
|
};
|
||||||
let mut actor = actor.borrow_mut();
|
self
|
||||||
actor.overlay = overlay;
|
}
|
||||||
}
|
}
|
||||||
@ -21,6 +21,8 @@ mod c {
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use crate::actors::Destination;
|
||||||
|
use crate::actors::popover;
|
||||||
use crate::event_loop::driver;
|
use crate::event_loop::driver;
|
||||||
use crate::imservice::IMService;
|
use crate::imservice::IMService;
|
||||||
use crate::imservice::c::InputMethod;
|
use crate::imservice::c::InputMethod;
|
||||||
@ -130,7 +132,7 @@ mod c {
|
|||||||
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: Wrapped::new(actors::popover::State::new()),
|
popover: Wrapped::new(actors::popover::State::new(true)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +176,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::Actor,
|
popover: &actors::popover::c::Destination,
|
||||||
hint_manager: HintManager,
|
hint_manager: HintManager,
|
||||||
dbus_handler: *const DBusHandler,
|
dbus_handler: *const DBusHandler,
|
||||||
) {
|
) {
|
||||||
@ -195,7 +197,7 @@ mod c {
|
|||||||
overlay_name,
|
overlay_name,
|
||||||
purpose,
|
purpose,
|
||||||
} = description;
|
} = description;
|
||||||
actors::popover::set_overlay(popover, overlay_name.clone());
|
popover.send(popover::Event::Overlay(overlay_name.clone()));
|
||||||
let layout = loading::load_layout(&name, kind, purpose, &overlay_name);
|
let layout = loading::load_layout(&name, kind, purpose, &overlay_name);
|
||||||
let layout = Box::into_raw(Box::new(layout));
|
let layout = Box::into_raw(Box::new(layout));
|
||||||
// CSS can't express "+" in the class
|
// CSS can't express "+" in the class
|
||||||
|
|||||||
Reference in New Issue
Block a user