From a039c2760f6458059dfc91b035a5e03022a31d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 14 Apr 2017 21:01:20 +0200 Subject: [PATCH] Handle modifier updates in the same sequence as Wayland does Summary: Consider the case that capslock gets pressed and released. In the case of Weston we have a sequence of: 1. Key press event 2. Modifier changed event 3. Key release event 4. Modifier changed event KWin however used to send the events in the following sequence: 1. Modifier changed event (on key press) 2. Key press event 3. Modifier changed event (on key release) 4. Key release event It looks like Xwayland is not able to properly process the sequence sent by KWin. And in fact KWin's sequence is wrong as it sends a state which does not match. We report that the caps lock is pressed in the modifiers prior to the application getting informed about the key press of caps lock. This change aligns KWin's implementation to the behavior of Weston. The main difference is that when modifiers change Xkb internally caches the serialized modifier states. And KeyboardInputRedirection just forwards the modifiers to KWayland::Server::SeatInterface once the processing has finished. SeatInterface ignores the forwarding if no states changes, so it is fine to do it that way. BUG: 377155 Test Plan: Not yet tested with an affected Xwayland as I only have 1.18 and the problem started with 1.19. But verified the sequence of events with WAYLAND_DEBUG and caps lock stil working in QtWayland clients and Xwayland 1.18 Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D5452 --- keyboard_input.cpp | 2 ++ xkb.cpp | 30 +++++++++++++++++++++--------- xkb.h | 11 +++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/keyboard_input.cpp b/keyboard_input.cpp index 97107b72a6..5f55cb3847 100644 --- a/keyboard_input.cpp +++ b/keyboard_input.cpp @@ -235,6 +235,8 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa return; } m_input->processFilters(std::bind(&InputEventFilter::keyEvent, std::placeholders::_1, &event)); + + m_xkb->forwardModifiers(); } void KeyboardInputRedirection::processModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group) diff --git a/xkb.cpp b/xkb.cpp index 1171118ca7..f8dc6ed219 100644 --- a/xkb.cpp +++ b/xkb.cpp @@ -213,7 +213,12 @@ void Xkb::updateKeymap(xkb_keymap *keymap) m_currentLayout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE); + m_modifierState.depressed = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_DEPRESSED)); + m_modifierState.latched = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LATCHED)); + m_modifierState.locked = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED)); + createKeymapFile(); + forwardModifiers(); } void Xkb::createKeymapFile() @@ -260,6 +265,7 @@ void Xkb::updateModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t } xkb_state_update_mask(m_state, modsDepressed, modsLatched, modsLocked, 0, 0, group); updateModifiers(); + forwardModifiers(); } void Xkb::updateKey(uint32_t key, InputRedirection::KeyboardKeyState state) @@ -324,16 +330,21 @@ void Xkb::updateModifiers() emit m_input->keyboard()->ledsChanged(m_leds); } - const xkb_layout_index_t layout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE); - if (layout != m_currentLayout) { - m_currentLayout = layout; - } - if (waylandServer()) { - waylandServer()->seat()->updateKeyboardModifiers(xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_DEPRESSED)), - xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LATCHED)), - xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED)), - layout); + m_currentLayout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE); + m_modifierState.depressed = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_DEPRESSED)); + m_modifierState.latched = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LATCHED)); + m_modifierState.locked = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED)); +} + +void Xkb::forwardModifiers() +{ + if (!waylandServer()) { + return; } + waylandServer()->seat()->updateKeyboardModifiers(m_modifierState.depressed, + m_modifierState.latched, + m_modifierState.locked, + m_currentLayout); } QString Xkb::layoutName() const @@ -472,6 +483,7 @@ void Xkb::switchToLayout(xkb_layout_index_t layout) const xkb_mod_mask_t locked = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED)); xkb_state_update_mask(m_state, depressed, latched, locked, 0, 0, layout); updateModifiers(); + forwardModifiers(); } quint32 Xkb::numberOfLayouts() const diff --git a/xkb.h b/xkb.h index 940ebf486b..db1f4e0e24 100644 --- a/xkb.h +++ b/xkb.h @@ -93,6 +93,11 @@ public: QMap layoutNames() const; quint32 numberOfLayouts() const; + /** + * Forwards the current modifier state to the Wayland seat + **/ + void forwardModifiers(); + private: xkb_keymap *loadKeymapFromConfig(); xkb_keymap *loadDefaultKeymap(); @@ -124,6 +129,12 @@ private: } m_compose; LEDs m_leds; KSharedConfigPtr m_config; + + struct { + xkb_mod_index_t depressed = 0; + xkb_mod_index_t latched = 0; + xkb_mod_index_t locked = 0; + } m_modifierState; }; inline