From 5f9afc849b52d7ab734839aaef2574c48821733d Mon Sep 17 00:00:00 2001 From: luveti Date: Fri, 1 Sep 2023 13:57:06 -0400 Subject: [PATCH 1/3] input: Only forward modifiers in KeyboardInnerHandle::set_focus --- src/input/keyboard/mod.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/input/keyboard/mod.rs b/src/input/keyboard/mod.rs index 534194251473..3733dea150f5 100644 --- a/src/input/keyboard/mod.rs +++ b/src/input/keyboard/mod.rs @@ -26,6 +26,23 @@ pub use modifiers_state::ModifiersState; mod xkb_config; pub use xkb_config::XkbConfig; +const MODIFIER_KEYSYMS: [Keysym; 14] = [ + xkb::KEY_Shift_L, + xkb::KEY_Shift_R, + xkb::KEY_Control_L, + xkb::KEY_Control_R, + xkb::KEY_Caps_Lock, + xkb::KEY_Shift_Lock, + xkb::KEY_Meta_L, + xkb::KEY_Meta_R, + xkb::KEY_Alt_L, + xkb::KEY_Alt_R, + xkb::KEY_Super_L, + xkb::KEY_Super_R, + xkb::KEY_Hyper_L, + xkb::KEY_Hyper_R, +]; + /// Trait representing object that can receive keyboard interactions pub trait KeyboardTarget: IsAlive + PartialEq + Clone + fmt::Debug + Send where @@ -751,14 +768,16 @@ impl<'a, D: SeatHandler + 'static> KeyboardInnerHandle<'a, D> { .inner .pressed_keys .iter() - .map(|keycode| { - KeysymHandle { - // Offset the keycode by 8, as the evdev XKB rules reflect X's - // broken keycode system, which starts at 8. - keycode: keycode + 8, - state: &self.inner.state, - keymap: &self.inner.keymap, - } + .filter_map(|keycode| { + MODIFIER_KEYSYMS.contains(keycode).then(|| { + KeysymHandle { + // Offset the keycode by 8, as the evdev XKB rules reflect X's + // broken keycode system, which starts at 8. + keycode: keycode + 8, + state: &self.inner.state, + keymap: &self.inner.keymap, + } + }) }) .collect(); focus.enter(self.seat, data, keys, serial); From 0206978532e69fb932ea4908ca1fcf40ca70ccf9 Mon Sep 17 00:00:00 2001 From: luveti Date: Fri, 1 Sep 2023 15:32:04 -0400 Subject: [PATCH 2/3] input: Forward no keys in KeyboardInnerHandle::set_focus --- src/input/keyboard/mod.rs | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/input/keyboard/mod.rs b/src/input/keyboard/mod.rs index 3733dea150f5..fafea87fefcb 100644 --- a/src/input/keyboard/mod.rs +++ b/src/input/keyboard/mod.rs @@ -26,23 +26,6 @@ pub use modifiers_state::ModifiersState; mod xkb_config; pub use xkb_config::XkbConfig; -const MODIFIER_KEYSYMS: [Keysym; 14] = [ - xkb::KEY_Shift_L, - xkb::KEY_Shift_R, - xkb::KEY_Control_L, - xkb::KEY_Control_R, - xkb::KEY_Caps_Lock, - xkb::KEY_Shift_Lock, - xkb::KEY_Meta_L, - xkb::KEY_Meta_R, - xkb::KEY_Alt_L, - xkb::KEY_Alt_R, - xkb::KEY_Super_L, - xkb::KEY_Super_R, - xkb::KEY_Hyper_L, - xkb::KEY_Hyper_R, -]; - /// Trait representing object that can receive keyboard interactions pub trait KeyboardTarget: IsAlive + PartialEq + Clone + fmt::Debug + Send where @@ -764,22 +747,7 @@ impl<'a, D: SeatHandler + 'static> KeyboardInnerHandle<'a, D> { // set new focus self.inner.focus = focus.map(|f| (f, serial)); if let Some((focus, _)) = self.inner.focus.as_mut() { - let keys = self - .inner - .pressed_keys - .iter() - .filter_map(|keycode| { - MODIFIER_KEYSYMS.contains(keycode).then(|| { - KeysymHandle { - // Offset the keycode by 8, as the evdev XKB rules reflect X's - // broken keycode system, which starts at 8. - keycode: keycode + 8, - state: &self.inner.state, - keymap: &self.inner.keymap, - } - }) - }) - .collect(); + let keys = Vec::new(); focus.enter(self.seat, data, keys, serial); focus.modifiers(self.seat, data, self.inner.mods_state, serial); }; From 6e63f32ff9821e9579de8f6b80f9e81574d7efad Mon Sep 17 00:00:00 2001 From: luveti Date: Mon, 4 Sep 2023 13:37:18 -0400 Subject: [PATCH 3/3] input: Send forwarded pressed keys in KeyboardInnerHandle::set_focus --- src/input/keyboard/mod.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/input/keyboard/mod.rs b/src/input/keyboard/mod.rs index fafea87fefcb..965c1322f017 100644 --- a/src/input/keyboard/mod.rs +++ b/src/input/keyboard/mod.rs @@ -59,6 +59,7 @@ pub(crate) struct KbdInternal { pub(crate) focus: Option<(::KeyboardFocus, Serial)>, pending_focus: Option<::KeyboardFocus>, pub(crate) pressed_keys: HashSet, + pub(crate) forwarded_pressed_keys: HashSet, pub(crate) mods_state: ModifiersState, context: xkb::Context, pub(crate) keymap: xkb::Keymap, @@ -75,6 +76,7 @@ impl fmt::Debug for KbdInternal { .field("focus", &self.focus) .field("pending_focus", &self.pending_focus) .field("pressed_keys", &self.pressed_keys) + .field("forwarded_pressed_keys", &self.forwarded_pressed_keys) .field("mods_state", &self.mods_state) .field("keymap", &self.keymap.get_raw_ptr()) .field("state", &self.state.get_raw_ptr()) @@ -103,6 +105,7 @@ impl KbdInternal { focus: None, pending_focus: None, pressed_keys: HashSet::new(), + forwarded_pressed_keys: HashSet::new(), mods_state: ModifiersState::default(), context, keymap, @@ -518,6 +521,15 @@ impl KeyboardHandle { return Some(val); } + match state { + KeyState::Pressed => { + guard.forwarded_pressed_keys.insert(keycode); + } + KeyState::Released => { + guard.forwarded_pressed_keys.remove(&keycode); + } + }; + // forward to client if no keybinding is triggered let seat = self.get_seat(data); let modifiers = mods_changed.then_some(guard.mods_state); @@ -747,7 +759,20 @@ impl<'a, D: SeatHandler + 'static> KeyboardInnerHandle<'a, D> { // set new focus self.inner.focus = focus.map(|f| (f, serial)); if let Some((focus, _)) = self.inner.focus.as_mut() { - let keys = Vec::new(); + let keys = self + .inner + .forwarded_pressed_keys + .iter() + .map(|keycode| { + KeysymHandle { + // Offset the keycode by 8, as the evdev XKB rules reflect X's + // broken keycode system, which starts at 8. + keycode: keycode + 8, + state: &self.inner.state, + keymap: &self.inner.keymap, + } + }) + .collect(); focus.enter(self.seat, data, keys, serial); focus.modifiers(self.seat, data, self.inner.mods_state, serial); };