From 8fdcc24b058fc44818a27bc9edc3e71740efc428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 15 Sep 2016 08:47:01 +0200 Subject: [PATCH] Better handling for forwarding key events to Wayland Server A new protected method is added to InputEventFilter to forward a QKeyEvent to the Wayland server. Several input filters need to forward the event to have a proper state of the events. E.g. the TabBox filter, but also the internal window filter and effects filter. It's important to update all events even if the events are not forwarded to a surface. This new method takes care of the general handling like ignoring key repeats, etc. Reviewed-By: bshah --- input.cpp | 42 ++++++++++++++++++++++-------------------- input.h | 3 +++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/input.cpp b/input.cpp index 17edd484b7..058cf02b6f 100644 --- a/input.cpp +++ b/input.cpp @@ -160,6 +160,24 @@ bool InputEventFilter::swipeGestureCancelled(quint32 time) return false; } +void InputEventFilter::passToWaylandServer(QKeyEvent *event) +{ + Q_ASSERT(waylandServer()); + if (event->isAutoRepeat()) { + return; + } + switch (event->type()) { + case QEvent::KeyPress: + waylandServer()->seat()->keyPressed(event->nativeScanCode()); + break; + case QEvent::KeyRelease: + waylandServer()->seat()->keyReleased(event->nativeScanCode()); + break; + default: + break; + } +} + #if HAVE_INPUT class VirtualTerminalFilter : public InputEventFilter { public: @@ -341,6 +359,7 @@ public: return false; } waylandServer()->seat()->setFocusedKeyboardSurface(nullptr); + passToWaylandServer(event); static_cast< EffectsHandlerImpl* >(effects)->grabbedKeyboardEvent(event); return true; } @@ -511,6 +530,7 @@ class InternalWindowEventFilter : public InputEventFilter { event->setAccepted(false); if (QCoreApplication::sendEvent(found, event)) { waylandServer()->seat()->setFocusedKeyboardSurface(nullptr); + passToWaylandServer(event); return true; } return false; @@ -748,16 +768,7 @@ public: seat->setFocusedKeyboardSurface(nullptr); // pass the key event to the seat, so that it has a proper model of the currently hold keys // this is important for combinations like alt+shift to ensure that shift is not considered pressed - switch (event->type()) { - case QEvent::KeyPress: - seat->keyPressed(event->nativeScanCode()); - break; - case QEvent::KeyRelease: - seat->keyReleased(event->nativeScanCode()); - break; - default: - break; - } + passToWaylandServer(event); if (event->type() == QEvent::KeyPress) { TabBox::TabBox::self()->keyPress(event->modifiers() | event->key()); @@ -920,16 +931,7 @@ public: auto seat = waylandServer()->seat(); input()->keyboard()->update(); seat->setTimestamp(event->timestamp()); - switch (event->type()) { - case QEvent::KeyPress: - seat->keyPressed(event->nativeScanCode()); - break; - case QEvent::KeyRelease: - seat->keyReleased(event->nativeScanCode()); - break; - default: - break; - } + passToWaylandServer(event); return true; } bool touchDown(quint32 id, const QPointF &pos, quint32 time) override { diff --git a/input.h b/input.h index f8863a65dd..a80009e4fd 100644 --- a/input.h +++ b/input.h @@ -298,6 +298,9 @@ public: virtual bool swipeGestureUpdate(const QSizeF &delta, quint32 time); virtual bool swipeGestureEnd(quint32 time); virtual bool swipeGestureCancelled(quint32 time); + +protected: + void passToWaylandServer(QKeyEvent *event); }; class InputDeviceHandler : public QObject