track suppressed keys and...
...forward non suppressed keys on release fixes #242
This commit is contained in:
parent
69543c0cfa
commit
4cb03a1d0d
|
@ -30,6 +30,7 @@ impl<Backend> AnvilState<Backend> {
|
||||||
let log = &self.log;
|
let log = &self.log;
|
||||||
let time = Event::time(&evt);
|
let time = Event::time(&evt);
|
||||||
let mut action = KeyAction::None;
|
let mut action = KeyAction::None;
|
||||||
|
let suppressed_keys = &mut self.suppressed_keys;
|
||||||
self.keyboard
|
self.keyboard
|
||||||
.input(keycode, state, serial, time, |modifiers, keysym| {
|
.input(keycode, state, serial, time, |modifiers, keysym| {
|
||||||
debug!(log, "keysym";
|
debug!(log, "keysym";
|
||||||
|
@ -37,15 +38,33 @@ impl<Backend> AnvilState<Backend> {
|
||||||
"mods" => format!("{:?}", modifiers),
|
"mods" => format!("{:?}", modifiers),
|
||||||
"keysym" => ::xkbcommon::xkb::keysym_get_name(keysym)
|
"keysym" => ::xkbcommon::xkb::keysym_get_name(keysym)
|
||||||
);
|
);
|
||||||
action = process_keyboard_shortcut(*modifiers, keysym);
|
|
||||||
// forward to client only if action == KeyAction::Forward
|
// If the key is pressed and triggered a action
|
||||||
// both for pressed and released, to avoid inconsistencies
|
// we will not forward the key to the client.
|
||||||
matches!(action, KeyAction::Forward)
|
// 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
|
||||||
|
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
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if let KeyState::Released = state {
|
|
||||||
// only process special actions on key press, not release
|
|
||||||
return KeyAction::None;
|
|
||||||
}
|
|
||||||
action
|
action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ pub struct AnvilState<BackendData> {
|
||||||
// input-related fields
|
// input-related fields
|
||||||
pub pointer: PointerHandle,
|
pub pointer: PointerHandle,
|
||||||
pub keyboard: KeyboardHandle,
|
pub keyboard: KeyboardHandle,
|
||||||
|
pub suppressed_keys: Vec<u32>,
|
||||||
pub pointer_location: (f64, f64),
|
pub pointer_location: (f64, f64),
|
||||||
pub cursor_status: Arc<Mutex<CursorImageStatus>>,
|
pub cursor_status: Arc<Mutex<CursorImageStatus>>,
|
||||||
pub seat_name: String,
|
pub seat_name: String,
|
||||||
|
@ -165,6 +166,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
|
||||||
socket_name,
|
socket_name,
|
||||||
pointer,
|
pointer,
|
||||||
keyboard,
|
keyboard,
|
||||||
|
suppressed_keys: Vec::new(),
|
||||||
cursor_status,
|
cursor_status,
|
||||||
pointer_location: (0.0, 0.0),
|
pointer_location: (0.0, 0.0),
|
||||||
seat_name,
|
seat_name,
|
||||||
|
|
Loading…
Reference in New Issue