Use an InputEventSpy to notify about key and modifier state changes
Summary: Instead of emitting the key state changed and modifier state changed signals from the right point before processing the events, let's use an InputEventSpy to do that. The spies were introduced to be called directly before the event processing. So the contract still holds. Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D4128
This commit is contained in:
parent
32f4e115e2
commit
437edb45ca
2 changed files with 57 additions and 9 deletions
|
@ -506,10 +506,64 @@ KeyboardInputRedirection::KeyboardInputRedirection(InputRedirection *parent)
|
||||||
|
|
||||||
KeyboardInputRedirection::~KeyboardInputRedirection() = default;
|
KeyboardInputRedirection::~KeyboardInputRedirection() = default;
|
||||||
|
|
||||||
|
class KeyStateChangedSpy : public InputEventSpy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KeyStateChangedSpy(InputRedirection *input)
|
||||||
|
: m_input(input)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyEvent(KeyEvent *event) override
|
||||||
|
{
|
||||||
|
if (event->isAutoRepeat()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit m_input->keyStateChanged(event->nativeScanCode(), event->type() == QEvent::KeyPress ? InputRedirection::KeyboardKeyPressed : InputRedirection::KeyboardKeyReleased);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
InputRedirection *m_input;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ModifiersChangedSpy : public InputEventSpy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ModifiersChangedSpy(InputRedirection *input)
|
||||||
|
: m_input(input)
|
||||||
|
, m_modifiers()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void keyEvent(KeyEvent *event) override
|
||||||
|
{
|
||||||
|
if (event->isAutoRepeat()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateModifiers(event->modifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateModifiers(Qt::KeyboardModifiers mods)
|
||||||
|
{
|
||||||
|
if (mods == m_modifiers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit m_input->keyboardModifiersChanged(mods, m_modifiers);
|
||||||
|
m_modifiers = mods;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
InputRedirection *m_input;
|
||||||
|
Qt::KeyboardModifiers m_modifiers;
|
||||||
|
};
|
||||||
|
|
||||||
void KeyboardInputRedirection::init()
|
void KeyboardInputRedirection::init()
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_inited);
|
Q_ASSERT(!m_inited);
|
||||||
m_inited = true;
|
m_inited = true;
|
||||||
|
m_input->installInputEventSpy(new KeyStateChangedSpy(m_input));
|
||||||
|
m_modifiersChangedSpy = new ModifiersChangedSpy(m_input);
|
||||||
|
m_input->installInputEventSpy(m_modifiersChangedSpy);
|
||||||
|
|
||||||
// setup key repeat
|
// setup key repeat
|
||||||
m_keyRepeat.timer = new QTimer(this);
|
m_keyRepeat.timer = new QTimer(this);
|
||||||
|
@ -644,12 +698,7 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!autoRepeat) {
|
if (!autoRepeat) {
|
||||||
emit m_input->keyStateChanged(key, state);
|
|
||||||
const Qt::KeyboardModifiers oldMods = modifiers();
|
|
||||||
m_xkb->updateKey(key, state);
|
m_xkb->updateKey(key, state);
|
||||||
if (oldMods != modifiers()) {
|
|
||||||
emit m_input->keyboardModifiersChanged(modifiers(), oldMods);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const xkb_keysym_t keySym = m_xkb->currentKeysym();
|
const xkb_keysym_t keySym = m_xkb->currentKeysym();
|
||||||
|
@ -686,11 +735,8 @@ void KeyboardInputRedirection::processModifiers(uint32_t modsDepressed, uint32_t
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: send to proper Client and also send when active Client changes
|
// TODO: send to proper Client and also send when active Client changes
|
||||||
Qt::KeyboardModifiers oldMods = modifiers();
|
|
||||||
m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group);
|
m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group);
|
||||||
if (oldMods != modifiers()) {
|
m_modifiersChangedSpy->updateModifiers(modifiers());
|
||||||
emit m_input->keyboardModifiersChanged(modifiers(), oldMods);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardInputRedirection::processKeymapChange(int fd, uint32_t size)
|
void KeyboardInputRedirection::processKeymapChange(int fd, uint32_t size)
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
class InputRedirection;
|
class InputRedirection;
|
||||||
|
class ModifiersChangedSpy;
|
||||||
class Toplevel;
|
class Toplevel;
|
||||||
|
|
||||||
namespace LibInput
|
namespace LibInput
|
||||||
|
@ -179,6 +180,7 @@ private:
|
||||||
quint32 time = 0;
|
quint32 time = 0;
|
||||||
QTimer *timer = nullptr;
|
QTimer *timer = nullptr;
|
||||||
} m_keyRepeat;
|
} m_keyRepeat;
|
||||||
|
ModifiersChangedSpy *m_modifiersChangedSpy = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
Loading…
Reference in a new issue