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
This commit is contained in:
parent
f3b20b482e
commit
a039c2760f
3 changed files with 34 additions and 9 deletions
|
@ -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)
|
||||
|
|
30
xkb.cpp
30
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
|
||||
|
|
11
xkb.h
11
xkb.h
|
@ -93,6 +93,11 @@ public:
|
|||
QMap<xkb_layout_index_t, QString> 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
|
||||
|
|
Loading…
Reference in a new issue