From b274fb9297ba38692f6c523abae2d40156ea1176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 2 Jul 2013 12:16:03 +0200 Subject: [PATCH] InputRedirection emits a signal when the modifiers change Used by Cursor to properly emit the mouseChanged signal which for historic reasons includes the keyboard modifiers. Again some fiddling around with the autotests and kcmrules needed to make it compile. This needs improvement! --- autotests/CMakeLists.txt | 1 - autotests/test_client_machine.cpp | 14 ++++---------- cursor.cpp | 13 +++++++++++-- cursor.h | 1 + input.cpp | 4 ++++ input.h | 10 ++++++++++ kcmkwin/kwinrules/kwinsrc.cpp | 5 +++++ 7 files changed, 35 insertions(+), 13 deletions(-) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 1ab8842d52..038a26d0d9 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -44,7 +44,6 @@ set( testClientMachine_SRCS ../client_machine.cpp ../utils.cpp ../atoms.cpp # needed by utils.cpp - ../cursor.cpp # needed by utils.cpp ) add_executable( testClientMachine ${testClientMachine_SRCS} ) diff --git a/autotests/test_client_machine.cpp b/autotests/test_client_machine.cpp index 309c00e00f..549b7fcbdf 100644 --- a/autotests/test_client_machine.cpp +++ b/autotests/test_client_machine.cpp @@ -20,8 +20,7 @@ along with this program. If not, see . #include "testutils.h" // KWin #include "../atoms.h" // needed for utils to compile -#include "../input.h" // needed for cursor to compile -#include "../main.h" // needed for cursor to compile +#include "../cursor.h" // needed for utils to compile #include "../client_machine.h" #include "../utils.h" #include "../xcbutils.h" @@ -40,15 +39,10 @@ namespace KWin { // just to make the linker of utils happy Atoms* atoms; -Application::OperationMode Application::operationMode() const +Cursor *Cursor::s_self = nullptr; +QPoint Cursor::pos() { - return Application::OperationModeX11; -} - -InputRedirection *InputRedirection::s_self = NULL; -Qt::MouseButtons InputRedirection::qtButtonStates() const -{ - return Qt::NoButton; + return QPoint(); } } diff --git a/cursor.cpp b/cursor.cpp index 33a46167f2..20ab785e4c 100644 --- a/cursor.cpp +++ b/cursor.cpp @@ -361,6 +361,10 @@ InputRedirectionCursor::InputRedirectionCursor(QObject *parent) connect(input(), SIGNAL(globalPointerChanged(QPointF)), SLOT(slotPosChanged(QPointF))); connect(input(), SIGNAL(pointerButtonStateChanged(uint32_t,InputRedirection::PointerButtonState)), SLOT(slotPointerButtonChanged())); +#ifndef KCMRULES + connect(input(), &InputRedirection::keyboardModifiersChanged, + this, &InputRedirectionCursor::slotModifiersChanged); +#endif } InputRedirectionCursor::~InputRedirectionCursor() @@ -377,8 +381,13 @@ void InputRedirectionCursor::slotPosChanged(const QPointF &pos) { const QPoint oldPos = currentPos(); updatePos(pos.toPoint()); - // TODO: add keyboard modifiers - emit mouseChanged(pos.toPoint(), oldPos, m_currentButtons, m_oldButtons, Qt::NoModifier, Qt::NoModifier); + emit mouseChanged(pos.toPoint(), oldPos, m_currentButtons, m_oldButtons, + input()->keyboardModifiers(), input()->keyboardModifiers()); +} + +void InputRedirectionCursor::slotModifiersChanged(Qt::KeyboardModifiers mods, Qt::KeyboardModifiers oldMods) +{ + emit mouseChanged(currentPos(), currentPos(), m_currentButtons, m_currentButtons, mods, oldMods); } void InputRedirectionCursor::slotPointerButtonChanged() diff --git a/cursor.h b/cursor.h index ab5cd9a26a..18871270be 100644 --- a/cursor.h +++ b/cursor.h @@ -252,6 +252,7 @@ protected: private Q_SLOTS: void slotPosChanged(const QPointF &pos); void slotPointerButtonChanged(); + void slotModifiersChanged(Qt::KeyboardModifiers mods, Qt::KeyboardModifiers oldMods); private: explicit InputRedirectionCursor(QObject *parent); Qt::MouseButtons m_oldButtons; diff --git a/input.cpp b/input.cpp index 6b31ff3726..93a1a7f33f 100644 --- a/input.cpp +++ b/input.cpp @@ -295,7 +295,11 @@ void InputRedirection::processKeyboardModifiers(uint32_t modsDepressed, uint32_t { // TODO: send to proper Client and also send when active Client changes #if HAVE_XKB + Qt::KeyboardModifiers oldMods = keyboardModifiers(); m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group); + if (oldMods != keyboardModifiers()) { + emit keyboardModifiersChanged(keyboardModifiers(), oldMods); + } #endif } diff --git a/input.h b/input.h index ef231b1855..ddcdf5b14b 100644 --- a/input.h +++ b/input.h @@ -135,6 +135,16 @@ Q_SIGNALS: * @param delta The delta of the event. */ void pointerAxisChanged(InputRedirection::PointerAxis axis, qreal delta); + /** + * @brief Emitted when the modifiers changes. + * + * Only emitted for the mask which is provided by Qt::KeyboardModifiers, if other modifiers + * change signal is not emitted + * + * @param newMods The new modifiers state + * @param oldMods The previous modifiers state + */ + void keyboardModifiersChanged(Qt::KeyboardModifiers newMods, Qt::KeyboardModifiers oldMods); private: static QEvent::Type buttonStateToEvent(PointerButtonState state); diff --git a/kcmkwin/kwinrules/kwinsrc.cpp b/kcmkwin/kwinrules/kwinsrc.cpp index 8e5a63998f..d19d8ee30a 100644 --- a/kcmkwin/kwinrules/kwinsrc.cpp +++ b/kcmkwin/kwinrules/kwinsrc.cpp @@ -33,3 +33,8 @@ Qt::MouseButtons KWin::InputRedirection::qtButtonStates() const { return Qt::NoButton; } + +Qt::KeyboardModifiers KWin::InputRedirection::keyboardModifiers() const +{ + return Qt::NoModifier; +}