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
This commit is contained in:
Martin Gräßlin 2016-12-26 14:19:56 +01:00
parent d1fdb9a02f
commit 58361213de
7 changed files with 46 additions and 6 deletions

View file

@ -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<KeyEvent*>(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<KeyEvent*>(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<KeyEvent*>(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<MouseEvent*>(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<WheelEvent*>(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);

View file

@ -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);
/**

View file

@ -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();
};
}

View file

@ -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());

View file

@ -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);

View file

@ -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));
}

View file

@ -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;
}