Add event filter for key press/release events while KWin grabbed keyboard on root window
Summary: The modifier-only-shortcuts break as soon as KWin grabs the keyboard (e.g. alt+tab, present windows, etc.). The investigation shows that in that case KWin does not get any raw key events any more and thus gets confused about the state of the hold modifiers. E.g. alt+tab has the alt key pressed, but we miss the release as the keyboard is grabbed. This change addresses the problem by installing an additional event filter for key press and release event which only filters for key events on the root window. That way we can be sure that it only operates when KWin grabbed the keyboard on the root window. Note: the problem only exists when grabbing on the root window. If the grab is on another window (e.g. moving a window) we still do get all events. The problem also seems to not happen if another application grabbed keys on the root window. E.g. for key combinations grabbed by kglobalaccel the correct sequence of key press/release as raw events are reported. Also while the screen is locked the evemts are reported and kscreenlocker grabs the keyboard on the root window. Test Plan: Used Alt+Tab and Present Windows and tried to activate launcher afterwards. Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D2980
This commit is contained in:
parent
db2ff13d4f
commit
66d1a0cc7a
2 changed files with 36 additions and 0 deletions
|
@ -132,6 +132,35 @@ private:
|
|||
Xkb *m_xkb = nullptr;
|
||||
};
|
||||
|
||||
class XKeyPressReleaseEventFilter : public X11EventFilter
|
||||
{
|
||||
public:
|
||||
XKeyPressReleaseEventFilter(uint32_t type)
|
||||
: X11EventFilter(type)
|
||||
{}
|
||||
~XKeyPressReleaseEventFilter() = default;
|
||||
|
||||
bool event(xcb_generic_event_t *event) override {
|
||||
xcb_key_press_event_t *ke = reinterpret_cast<xcb_key_press_event_t *>(event);
|
||||
if (m_xkb && ke->event == ke->root) {
|
||||
const uint8_t eventType = event->response_type & ~0x80;
|
||||
if (eventType == XCB_KEY_PRESS) {
|
||||
m_xkb->updateKey(ke->detail - 8, InputRedirection::KeyboardKeyPressed);
|
||||
} else {
|
||||
m_xkb->updateKey(ke->detail - 8, InputRedirection::KeyboardKeyReleased);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void setXkb(Xkb *xkb) {
|
||||
m_xkb = xkb;
|
||||
}
|
||||
|
||||
private:
|
||||
// TODO: QPointer
|
||||
Xkb *m_xkb = nullptr;
|
||||
};
|
||||
|
||||
XInputIntegration::XInputIntegration(QObject *parent)
|
||||
: QObject(parent)
|
||||
|
@ -207,6 +236,10 @@ void XInputIntegration::startListening()
|
|||
m_xiEventFilter.reset(new XInputEventFilter(m_xiOpcode));
|
||||
m_xiEventFilter->setCursor(m_x11Cursor);
|
||||
m_xiEventFilter->setXkb(m_xkb);
|
||||
m_keyPressFilter.reset(new XKeyPressReleaseEventFilter(XCB_KEY_PRESS));
|
||||
m_keyPressFilter->setXkb(m_xkb);
|
||||
m_keyReleaseFilter.reset(new XKeyPressReleaseEventFilter(XCB_KEY_RELEASE));
|
||||
m_keyReleaseFilter->setXkb(m_xkb);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace KWin
|
|||
{
|
||||
|
||||
class XInputEventFilter;
|
||||
class XKeyPressReleaseEventFilter;
|
||||
class X11Cursor;
|
||||
class Xkb;
|
||||
|
||||
|
@ -58,6 +59,8 @@ private:
|
|||
Xkb *m_xkb = nullptr;
|
||||
|
||||
QScopedPointer<XInputEventFilter> m_xiEventFilter;
|
||||
QScopedPointer<XKeyPressReleaseEventFilter> m_keyPressFilter;
|
||||
QScopedPointer<XKeyPressReleaseEventFilter> m_keyReleaseFilter;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue