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,
|
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 crate::logging;
|
||||||
|
use std::borrow::BorrowMut;
|
||||||
use super::Destination;
|
use super::Destination;
|
||||||
|
|
||||||
pub mod c {
|
pub mod c {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::util::c::Wrapped;
|
use crate::util::c::ArcWrapped;
|
||||||
/// The mutable instance of state
|
/// The mutable instance of state.
|
||||||
pub type Actor = Wrapped<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.
|
/// It's the same because the state is a simple mutex-protected type.
|
||||||
/// There are no channels involved.
|
/// There are no channels involved.
|
||||||
pub type Destination = Wrapped<State>;
|
pub type Destination = ArcWrapped<State>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
@ -32,8 +37,18 @@ impl Destination for c::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.clone_ref();
|
||||||
let mut actor = actor.borrow_mut();
|
let actor = actor.lock();
|
||||||
*actor = actor.clone().handle_event(event);
|
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::outputs::Outputs;
|
||||||
use crate::state;
|
use crate::state;
|
||||||
use crate::submission::Submission;
|
use crate::submission::Submission;
|
||||||
use crate::util::c::Wrapped;
|
use crate::util::c::{ArcWrapped, Wrapped};
|
||||||
use crate::vkeyboard::c::ZwpVirtualKeyboardV1;
|
use crate::vkeyboard::c::ZwpVirtualKeyboardV1;
|
||||||
|
|
||||||
/// DbusHandler*
|
/// DbusHandler*
|
||||||
@ -132,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(true)),
|
popover: ArcWrapped::new(actors::popover::State::new(true)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user