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