track suppressed keys and...

...forward non suppressed keys on release
fixes #242
This commit is contained in:
Christian Meissl 2021-06-19 19:32:22 +02:00 committed by Victor Berger
parent 69543c0cfa
commit 4cb03a1d0d
2 changed files with 29 additions and 8 deletions

View File

@ -30,6 +30,7 @@ impl<Backend> AnvilState<Backend> {
let log = &self.log;
let time = Event::time(&evt);
let mut action = KeyAction::None;
let suppressed_keys = &mut self.suppressed_keys;
self.keyboard
.input(keycode, state, serial, time, |modifiers, keysym| {
debug!(log, "keysym";
@ -37,15 +38,33 @@ impl<Backend> AnvilState<Backend> {
"mods" => format!("{:?}", modifiers),
"keysym" => ::xkbcommon::xkb::keysym_get_name(keysym)
);
// If the key is pressed and triggered a action
// we will not forward the key to the client.
// Additionally add the key to the suppressed keys
// so that we can decide on a release if the key
// should be forwarded to the client or not.
if let KeyState::Pressed = state {
action = process_keyboard_shortcut(*modifiers, keysym);
// forward to client only if action == KeyAction::Forward
// both for pressed and released, to avoid inconsistencies
matches!(action, KeyAction::Forward)
});
if let KeyState::Released = state {
// only process special actions on key press, not release
return KeyAction::None;
let forward = matches!(action, KeyAction::Forward);
if !forward {
suppressed_keys.push(keysym);
}
forward
} else {
let suppressed = suppressed_keys.contains(&keysym);
if suppressed {
suppressed_keys.retain(|k| *k != keysym);
}
!suppressed
}
});
action
}

View File

@ -40,6 +40,7 @@ pub struct AnvilState<BackendData> {
// input-related fields
pub pointer: PointerHandle,
pub keyboard: KeyboardHandle,
pub suppressed_keys: Vec<u32>,
pub pointer_location: (f64, f64),
pub cursor_status: Arc<Mutex<CursorImageStatus>>,
pub seat_name: String,
@ -165,6 +166,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
socket_name,
pointer,
keyboard,
suppressed_keys: Vec::new(),
cursor_status,
pointer_location: (0.0, 0.0),
seat_name,