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)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 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);
|
action = process_keyboard_shortcut(*modifiers, keysym);
|
||||||
|
|
||||||
// forward to client only if action == KeyAction::Forward
|
// forward to client only if action == KeyAction::Forward
|
||||||
// both for pressed and released, to avoid inconsistencies
|
let forward = matches!(action, KeyAction::Forward);
|
||||||
matches!(action, KeyAction::Forward)
|
|
||||||
});
|
if !forward {
|
||||||
if let KeyState::Released = state {
|
suppressed_keys.push(keysym);
|
||||||
// only process special actions on key press, not release
|
|
||||||
return KeyAction::None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
forward
|
||||||
|
} else {
|
||||||
|
let suppressed = suppressed_keys.contains(&keysym);
|
||||||
|
|
||||||
|
if suppressed {
|
||||||
|
suppressed_keys.retain(|k| *k != keysym);
|
||||||
|
}
|
||||||
|
|
||||||
|
!suppressed
|
||||||
|
}
|
||||||
|
});
|
||||||
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