state: Become the source of layout choice
A redesign of popover was needed: it can no longer query the application state directly due to current state being its own actor, so instead the popover gets a dedicated copy of the relevant state. I'm not entirely happy with the extra complexity of having an extra actor just for 1 string, but at least the duplication between C and Rust and mutual calls have been reduced.
This commit is contained in:
23
src/actors/mod.rs
Normal file
23
src/actors/mod.rs
Normal file
@ -0,0 +1,23 @@
|
||||
/* Copyright (C) 2022 Purism SPC
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*/
|
||||
|
||||
/*! Actors are parts of Squeekboard containing state independent from the main application state.
|
||||
|
||||
Because main application state is meant to be immutable,
|
||||
it cannot be referenced directly by pieces of logic
|
||||
interacting with the environment.
|
||||
|
||||
Such impure logic is split away (actor's logic)
|
||||
and combined with relevant pieces of state (actor state),
|
||||
thus preserving the purity (and sometimes simplicity) of the main state.
|
||||
|
||||
Actors can communicate with the main state by sending it messages,
|
||||
and by receiving updates from it.
|
||||
*/
|
||||
|
||||
// TODO: move crate::panel into crate::actors::panel.
|
||||
// Panel contains state and logic to protect the main state from getting flooded
|
||||
// with low-level wayland and gtk sizing events.
|
||||
|
||||
pub mod popover;
|
||||
40
src/actors/popover.rs
Normal file
40
src/actors/popover.rs
Normal file
@ -0,0 +1,40 @@
|
||||
/* Copyright (C) 2022 Purism SPC
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
*/
|
||||
|
||||
/*! The popover is opened directly by the GTK surface,
|
||||
without bouncing click events off the main state.
|
||||
Then it must accurately show which layout has been selected.
|
||||
It can get the system layout directly from gsettings on open,
|
||||
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.
|
||||
*/
|
||||
|
||||
pub mod c {
|
||||
use super::*;
|
||||
use crate::util::c::Wrapped;
|
||||
/// The mutable instance of state
|
||||
pub type Actor = Wrapped<State>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct State {
|
||||
pub overlay: Option<String>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> Self {
|
||||
Self { overlay: None }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_overlay(
|
||||
actor: &c::Actor,
|
||||
overlay: Option<String>,
|
||||
) {
|
||||
let actor = actor.clone_ref();
|
||||
let mut actor = actor.borrow_mut();
|
||||
actor.overlay = overlay;
|
||||
}
|
||||
Reference in New Issue
Block a user