locking: Lock keys statelessly

Locking is not determined by button state any more, but rather based on the view active at the moment. If pressing/locking a key results in the current view being active, the key is active. If locking a key results in the current view, the unlock view is activated.
This commit is contained in:
Dorota Czaplejewicz
2020-02-02 15:41:47 +00:00
parent 97d8dfe4cb
commit 500c23beec
5 changed files with 40 additions and 41 deletions

View File

@ -23,7 +23,6 @@ pub type KeyCode = u32;
#[derive(Debug, Clone)]
pub struct KeyState {
pub pressed: PressType,
pub locked: bool,
/// A cache of raw keycodes derived from Action::Sumbit given a keymap
pub keycodes: Vec<KeyCode>,
/// Static description of what the key does when pressed or released
@ -31,17 +30,6 @@ pub struct KeyState {
}
impl KeyState {
#[must_use]
pub fn into_activated(self) -> KeyState {
match self.action {
Action::LockView { lock: _, unlock: _ } => KeyState {
locked: self.locked ^ true,
..self
},
_ => self,
}
}
#[must_use]
pub fn into_released(self) -> KeyState {
KeyState {
@ -195,7 +183,6 @@ mod tests {
keys: vec!(KeySym("a".into()), KeySym("c".into())),
},
keycodes: vec!(9, 10),
locked: false,
pressed: PressType::Released,
},
}).unwrap();