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!
This commit is contained in:
Martin Gräßlin 2013-07-02 12:16:03 +02:00
parent b57885a1bf
commit b274fb9297
7 changed files with 35 additions and 13 deletions

View file

@ -44,7 +44,6 @@ set( testClientMachine_SRCS
../client_machine.cpp ../client_machine.cpp
../utils.cpp ../utils.cpp
../atoms.cpp # needed by utils.cpp ../atoms.cpp # needed by utils.cpp
../cursor.cpp # needed by utils.cpp
) )
add_executable( testClientMachine ${testClientMachine_SRCS} ) add_executable( testClientMachine ${testClientMachine_SRCS} )

View file

@ -20,8 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "testutils.h" #include "testutils.h"
// KWin // KWin
#include "../atoms.h" // needed for utils to compile #include "../atoms.h" // needed for utils to compile
#include "../input.h" // needed for cursor to compile #include "../cursor.h" // needed for utils to compile
#include "../main.h" // needed for cursor to compile
#include "../client_machine.h" #include "../client_machine.h"
#include "../utils.h" #include "../utils.h"
#include "../xcbutils.h" #include "../xcbutils.h"
@ -40,15 +39,10 @@ namespace KWin {
// just to make the linker of utils happy // just to make the linker of utils happy
Atoms* atoms; Atoms* atoms;
Application::OperationMode Application::operationMode() const Cursor *Cursor::s_self = nullptr;
QPoint Cursor::pos()
{ {
return Application::OperationModeX11; return QPoint();
}
InputRedirection *InputRedirection::s_self = NULL;
Qt::MouseButtons InputRedirection::qtButtonStates() const
{
return Qt::NoButton;
} }
} }

View file

@ -361,6 +361,10 @@ InputRedirectionCursor::InputRedirectionCursor(QObject *parent)
connect(input(), SIGNAL(globalPointerChanged(QPointF)), SLOT(slotPosChanged(QPointF))); connect(input(), SIGNAL(globalPointerChanged(QPointF)), SLOT(slotPosChanged(QPointF)));
connect(input(), SIGNAL(pointerButtonStateChanged(uint32_t,InputRedirection::PointerButtonState)), connect(input(), SIGNAL(pointerButtonStateChanged(uint32_t,InputRedirection::PointerButtonState)),
SLOT(slotPointerButtonChanged())); SLOT(slotPointerButtonChanged()));
#ifndef KCMRULES
connect(input(), &InputRedirection::keyboardModifiersChanged,
this, &InputRedirectionCursor::slotModifiersChanged);
#endif
} }
InputRedirectionCursor::~InputRedirectionCursor() InputRedirectionCursor::~InputRedirectionCursor()
@ -377,8 +381,13 @@ void InputRedirectionCursor::slotPosChanged(const QPointF &pos)
{ {
const QPoint oldPos = currentPos(); const QPoint oldPos = currentPos();
updatePos(pos.toPoint()); updatePos(pos.toPoint());
// TODO: add keyboard modifiers emit mouseChanged(pos.toPoint(), oldPos, m_currentButtons, m_oldButtons,
emit mouseChanged(pos.toPoint(), oldPos, m_currentButtons, m_oldButtons, Qt::NoModifier, Qt::NoModifier); 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() void InputRedirectionCursor::slotPointerButtonChanged()

View file

@ -252,6 +252,7 @@ protected:
private Q_SLOTS: private Q_SLOTS:
void slotPosChanged(const QPointF &pos); void slotPosChanged(const QPointF &pos);
void slotPointerButtonChanged(); void slotPointerButtonChanged();
void slotModifiersChanged(Qt::KeyboardModifiers mods, Qt::KeyboardModifiers oldMods);
private: private:
explicit InputRedirectionCursor(QObject *parent); explicit InputRedirectionCursor(QObject *parent);
Qt::MouseButtons m_oldButtons; Qt::MouseButtons m_oldButtons;

View file

@ -295,7 +295,11 @@ void InputRedirection::processKeyboardModifiers(uint32_t modsDepressed, uint32_t
{ {
// TODO: send to proper Client and also send when active Client changes // TODO: send to proper Client and also send when active Client changes
#if HAVE_XKB #if HAVE_XKB
Qt::KeyboardModifiers oldMods = keyboardModifiers();
m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group); m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group);
if (oldMods != keyboardModifiers()) {
emit keyboardModifiersChanged(keyboardModifiers(), oldMods);
}
#endif #endif
} }

10
input.h
View file

@ -135,6 +135,16 @@ Q_SIGNALS:
* @param delta The delta of the event. * @param delta The delta of the event.
*/ */
void pointerAxisChanged(InputRedirection::PointerAxis axis, qreal delta); 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: private:
static QEvent::Type buttonStateToEvent(PointerButtonState state); static QEvent::Type buttonStateToEvent(PointerButtonState state);

View file

@ -33,3 +33,8 @@ Qt::MouseButtons KWin::InputRedirection::qtButtonStates() const
{ {
return Qt::NoButton; return Qt::NoButton;
} }
Qt::KeyboardModifiers KWin::InputRedirection::keyboardModifiers() const
{
return Qt::NoModifier;
}