layout: Latch keys when clicked twice
Third click unlatches. No actual UI indication.
This commit is contained in:
@ -672,6 +672,12 @@ pub struct Layout {
|
|||||||
pub margins: Margins,
|
pub margins: Margins,
|
||||||
pub kind: ArrangementKind,
|
pub kind: ArrangementKind,
|
||||||
pub current_view: String,
|
pub current_view: String,
|
||||||
|
|
||||||
|
// If current view is latched,
|
||||||
|
// clicking any button that emits an action (erase, submit, set modifier)
|
||||||
|
// will cause lock buttons to unlatch.
|
||||||
|
view_latched: bool,
|
||||||
|
|
||||||
// Views own the actual buttons which have state
|
// Views own the actual buttons which have state
|
||||||
// Maybe they should own UI only,
|
// Maybe they should own UI only,
|
||||||
// and keys should be owned by a dedicated non-UI-State?
|
// and keys should be owned by a dedicated non-UI-State?
|
||||||
@ -718,6 +724,7 @@ impl Layout {
|
|||||||
Layout {
|
Layout {
|
||||||
kind,
|
kind,
|
||||||
current_view: "base".to_owned(),
|
current_view: "base".to_owned(),
|
||||||
|
view_latched: false,
|
||||||
views: data.views,
|
views: data.views,
|
||||||
keymaps: data.keymaps,
|
keymaps: data.keymaps,
|
||||||
pressed_keys: HashSet::new(),
|
pressed_keys: HashSet::new(),
|
||||||
@ -818,6 +825,8 @@ impl Layout {
|
|||||||
}
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod procedures {
|
mod procedures {
|
||||||
@ -1026,24 +1035,35 @@ mod seat {
|
|||||||
Action::Submit { text: _, keys: _ }
|
Action::Submit { text: _, keys: _ }
|
||||||
| Action::Erase
|
| Action::Erase
|
||||||
=> {
|
=> {
|
||||||
unstick_locks(layout).apply();
|
if layout.view_latched {
|
||||||
|
unstick_locks(layout).apply();
|
||||||
|
}
|
||||||
submission.handle_release(KeyState::get_id(rckey), time);
|
submission.handle_release(KeyState::get_id(rckey), time);
|
||||||
},
|
},
|
||||||
Action::SetView(view) => {
|
Action::SetView(view) => {
|
||||||
|
layout.view_latched = false;
|
||||||
try_set_view(layout, view)
|
try_set_view(layout, view)
|
||||||
},
|
},
|
||||||
Action::LockView { lock, unlock } => {
|
Action::LockView { lock, unlock } => {
|
||||||
let gets_locked = !key.action.is_locked(&layout.current_view);
|
let locked = key.action.is_locked(&layout.current_view);
|
||||||
unstick_locks(layout)
|
let (gets_latched, new_view) = match (layout.view_latched, locked) {
|
||||||
// It doesn't matter what the resulting view should be,
|
// Was unlocked, now make locked but latched. (false)
|
||||||
// it's getting changed anyway.
|
// OR (true)
|
||||||
.choose_view(
|
// Layout is latched for reason other than this button.
|
||||||
match gets_locked {
|
(_, false) => (true, Some(lock.clone())),
|
||||||
true => lock.clone(),
|
// Was latched, now only locked.
|
||||||
false => unlock.clone(),
|
(true, true) => (false, None),
|
||||||
}
|
// Was locked, now make unlocked.
|
||||||
)
|
(false, true) => (false, Some(unlock.clone())),
|
||||||
.apply()
|
};
|
||||||
|
layout.view_latched = gets_latched;
|
||||||
|
if let Some(view) = new_view {
|
||||||
|
unstick_locks(layout)
|
||||||
|
// It doesn't matter what the resulting view should be,
|
||||||
|
// it's getting changed anyway.
|
||||||
|
.choose_view(view)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Action::ApplyModifier(modifier) => {
|
Action::ApplyModifier(modifier) => {
|
||||||
// FIXME: key id is unneeded with stateless locks
|
// FIXME: key id is unneeded with stateless locks
|
||||||
@ -1193,6 +1213,7 @@ mod test {
|
|||||||
]);
|
]);
|
||||||
let layout = Layout {
|
let layout = Layout {
|
||||||
current_view: String::new(),
|
current_view: String::new(),
|
||||||
|
view_latched: false,
|
||||||
keymaps: Vec::new(),
|
keymaps: Vec::new(),
|
||||||
kind: ArrangementKind::Base,
|
kind: ArrangementKind::Base,
|
||||||
pressed_keys: HashSet::new(),
|
pressed_keys: HashSet::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user