popover: Use thread-safe reference
This reference will be modified from the screensaver thread.
This commit is contained in:
@ -11,16 +11,21 @@ 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,
|
||||
and updated by main state every time it changes.
|
||||
*/
|
||||
use crate::logging;
|
||||
use std::borrow::BorrowMut;
|
||||
use super::Destination;
|
||||
|
||||
pub mod c {
|
||||
use super::*;
|
||||
use crate::util::c::Wrapped;
|
||||
/// The mutable instance of state
|
||||
pub type Actor = Wrapped<State>;
|
||||
use crate::util::c::ArcWrapped;
|
||||
/// The mutable instance of state.
|
||||
/// Thread-safe because this actor does not get its own event loop,
|
||||
/// 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 = Wrapped<State>;
|
||||
pub type Destination = ArcWrapped<State>;
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
@ -32,8 +37,18 @@ 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);
|
||||
let actor = actor.lock();
|
||||
match actor {
|
||||
Ok(mut actor) => {
|
||||
let actor = actor.borrow_mut();
|
||||
**actor = actor.clone().handle_event(event);
|
||||
},
|
||||
Err(e) => log_print!(
|
||||
logging::Level::Bug,
|
||||
"Cannot lock popover state: {:?}",
|
||||
e,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ mod c {
|
||||
use crate::outputs::Outputs;
|
||||
use crate::state;
|
||||
use crate::submission::Submission;
|
||||
use crate::util::c::Wrapped;
|
||||
use crate::util::c::{ArcWrapped, Wrapped};
|
||||
use crate::vkeyboard::c::ZwpVirtualKeyboardV1;
|
||||
|
||||
/// DbusHandler*
|
||||
@ -132,7 +132,7 @@ mod c {
|
||||
state_manager: Wrapped::new(state_manager),
|
||||
receiver: Wrapped::new(receiver),
|
||||
wayland: Box::into_raw(wayland),
|
||||
popover: Wrapped::new(actors::popover::State::new(true)),
|
||||
popover: ArcWrapped::new(actors::popover::State::new(true)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user