From 58361213de59183be2e0c3cf1c51bd856b9f1c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 26 Dec 2016 14:19:56 +0100 Subject: [PATCH] Add the modifiers relevant for global shortcuts into the input Events Summary: Prior to this change various event filters performed deep calls into Xkb class to figure out the modifiers relevant for global shortcuts (aka consumed modifiers). This shows that this is a general useful information which should be available to all input event filters directly. Thus it's now added to the input events and exposed directly in InputRedirection so that the calls into Xkb are no longer needed. Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D3810 --- input.cpp | 15 ++++++++++----- input.h | 1 + input_event.h | 27 +++++++++++++++++++++++++++ keyboard_input.cpp | 1 + keyboard_input.h | 3 +++ pointer_input.cpp | 3 +++ tabbox/tabbox.cpp | 2 +- 7 files changed, 46 insertions(+), 6 deletions(-) diff --git a/input.cpp b/input.cpp index bbbd9c9078..cc35d18112 100644 --- a/input.cpp +++ b/input.cpp @@ -430,7 +430,7 @@ public: } else if (input()->pointer()->isConstrained()) { if (event->type() == QEvent::KeyPress && event->key() == Qt::Key_Escape && - input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts() == Qt::KeyboardModifiers()) { + static_cast(event)->modifiersRelevantForGlobalShortcuts() == Qt::KeyboardModifiers()) { // TODO: don't hard code m_timer->start(3000); input()->keyboard()->update(); @@ -686,7 +686,7 @@ public: } bool keyEvent(QKeyEvent *event) override { if (event->type() == QEvent::KeyPress) { - return input()->shortcuts()->processKey(input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts(), event->nativeVirtualKey(), event->key()); + return input()->shortcuts()->processKey(static_cast(event)->modifiersRelevantForGlobalShortcuts(), event->nativeVirtualKey(), event->key()); } return false; } @@ -1003,7 +1003,7 @@ public: if (event->type() == QEvent::KeyPress) { TabBox::TabBox::self()->keyPress(event->modifiers() | event->key()); - } else if (input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier) { + } else if (static_cast(event)->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier) { TabBox::TabBox::self()->modifiersReleased(); } return true; @@ -1046,7 +1046,7 @@ public: } bool wasAction = false; Options::MouseCommand command = Options::MouseNothing; - if (input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { + if (static_cast(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { wasAction = true; switch (event->button()) { case Qt::LeftButton: @@ -1081,7 +1081,7 @@ public: } bool wasAction = false; Options::MouseCommand command = Options::MouseNothing; - if (input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { + if (static_cast(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) { wasAction = true; command = options->operationWindowMouseWheel(-1 * event->angleDelta().y()); } else { @@ -1785,6 +1785,11 @@ Qt::KeyboardModifiers InputRedirection::keyboardModifiers() const return m_keyboard->modifiers(); } +Qt::KeyboardModifiers InputRedirection::modifiersRelevantForGlobalShortcuts() const +{ + return m_keyboard->modifiersRelevantForGlobalShortcuts(); +} + void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action) { m_shortcuts->registerShortcut(action, shortcut); diff --git a/input.h b/input.h index ba6c0fa5d6..167dbf5181 100644 --- a/input.h +++ b/input.h @@ -92,6 +92,7 @@ public: QPointF globalPointer() const; Qt::MouseButtons qtButtonStates() const; Qt::KeyboardModifiers keyboardModifiers() const; + Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const; void registerShortcut(const QKeySequence &shortcut, QAction *action); /** diff --git a/input_event.h b/input_event.h index bbb845da8b..f7a8e52531 100644 --- a/input_event.h +++ b/input_event.h @@ -53,11 +53,20 @@ public: return m_device; } + Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const { + return m_modifiersRelevantForShortcuts; + } + + void setModifiersRelevantForGlobalShortcuts(const Qt::KeyboardModifiers &mods) { + m_modifiersRelevantForShortcuts = mods; + } + private: QSizeF m_delta; QSizeF m_deltaUnccelerated; quint64 m_timestampMicroseconds; LibInput::Device *m_device; + Qt::KeyboardModifiers m_modifiersRelevantForShortcuts = Qt::KeyboardModifiers(); }; class WheelEvent : public QWheelEvent @@ -70,8 +79,17 @@ public: return m_device; } + Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const { + return m_modifiersRelevantForShortcuts; + } + + void setModifiersRelevantForGlobalShortcuts(const Qt::KeyboardModifiers &mods) { + m_modifiersRelevantForShortcuts = mods; + } + private: LibInput::Device *m_device; + Qt::KeyboardModifiers m_modifiersRelevantForShortcuts = Qt::KeyboardModifiers(); }; class KeyEvent : public QKeyEvent @@ -84,8 +102,17 @@ public: return m_device; } + Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const { + return m_modifiersRelevantForShortcuts; + } + + void setModifiersRelevantForGlobalShortcuts(const Qt::KeyboardModifiers &mods) { + m_modifiersRelevantForShortcuts = mods; + } + private: LibInput::Device *m_device; + Qt::KeyboardModifiers m_modifiersRelevantForShortcuts = Qt::KeyboardModifiers(); }; } diff --git a/keyboard_input.cpp b/keyboard_input.cpp index 5a39c4cc22..918d62e4cd 100644 --- a/keyboard_input.cpp +++ b/keyboard_input.cpp @@ -661,6 +661,7 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa autoRepeat, time, device); + event.setModifiersRelevantForGlobalShortcuts(m_xkb->modifiersRelevantForGlobalShortcuts()); if (state == InputRedirection::KeyboardKeyPressed) { if (m_xkb->shouldKeyRepeat(key) && waylandServer()->seat()->keyRepeatDelay() != 0) { m_keyRepeat.timer->setInterval(waylandServer()->seat()->keyRepeatDelay()); diff --git a/keyboard_input.h b/keyboard_input.h index 574ac20484..f473a569d4 100644 --- a/keyboard_input.h +++ b/keyboard_input.h @@ -159,6 +159,9 @@ public: Qt::KeyboardModifiers modifiers() const { return m_xkb->modifiers(); } + Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const { + return m_xkb->modifiersRelevantForGlobalShortcuts(); + } Q_SIGNALS: void ledsChanged(KWin::Xkb::LEDs); diff --git a/pointer_input.cpp b/pointer_input.cpp index 6f9f053b28..01d7397c34 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -228,6 +228,7 @@ void PointerInputRedirection::processMotion(const QPointF &pos, const QSizeF &de MouseEvent event(QEvent::MouseMove, m_pos, Qt::NoButton, m_qtButtons, m_input->keyboardModifiers(), time, delta, deltaNonAccelerated, timeUsec, device); + event.setModifiersRelevantForGlobalShortcuts(m_input->modifiersRelevantForGlobalShortcuts()); m_input->processFilters(std::bind(&InputEventFilter::pointerEvent, std::placeholders::_1, &event, 0)); } @@ -255,6 +256,7 @@ void PointerInputRedirection::processButton(uint32_t button, InputRedirection::P MouseEvent event(type, m_pos, buttonToQtMouseButton(button), m_qtButtons, m_input->keyboardModifiers(), time, QSizeF(), QSizeF(), 0, device); + event.setModifiersRelevantForGlobalShortcuts(m_input->modifiersRelevantForGlobalShortcuts()); m_input->processFilters(std::bind(&InputEventFilter::pointerEvent, std::placeholders::_1, &event, button)); } @@ -274,6 +276,7 @@ void PointerInputRedirection::processAxis(InputRedirection::PointerAxis axis, qr WheelEvent wheelEvent(m_pos, delta, (axis == InputRedirection::PointerAxisHorizontal) ? Qt::Horizontal : Qt::Vertical, m_qtButtons, m_input->keyboardModifiers(), time, device); + wheelEvent.setModifiersRelevantForGlobalShortcuts(m_input->modifiersRelevantForGlobalShortcuts()); m_input->processFilters(std::bind(&InputEventFilter::wheelEvent, std::placeholders::_1, &wheelEvent)); } diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index 43eb6736eb..41df699255 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -1075,7 +1075,7 @@ static bool areModKeysDepressedX11(const QKeySequence &seq) static bool areModKeysDepressedWayland(const QKeySequence &seq) { const int mod = seq[seq.count()-1] & Qt::KeyboardModifierMask; - const Qt::KeyboardModifiers mods = input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts(); + const Qt::KeyboardModifiers mods = input()->modifiersRelevantForGlobalShortcuts(); if ((mod & Qt::SHIFT) && mods.testFlag(Qt::ShiftModifier)) { return true; }