From 9c5f972c6a5a8f0ebd06db3249d8edd1ace7686c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 19 Aug 2016 16:56:21 +0200 Subject: [PATCH] Forward x11 raw pointer buttons to PointerInputRedirection Summary: The raw pointer button events intercepted in the XInput2 input filter get sent through the Platform to the PointerInputRedirection. This makes the PointerInputRedirection track the pointer button state and emit the signals for button changed and axis changed. These signals are used by the modifier-only shortcut detection to determine whether the shortcut should trigger. On X11 the "normal" input handling doesn't use the InputRedirection and the emitted signals are not consumed by anything else. As PointerInputRedirection is not inited the events are not forwarded to the input filter, thus won't be processed by other parts and won't interfere with the normal event processing on X11. Given that it also doesn't matter that the input filter does not apply the left-handed setting. The internal tracking will have a wrong mouse button, but nothing is going to do decisions based on the value of the pressed mouse button. For the moment all we are interested in is that a button is pressed. Test Plan: Pressed meta, clicked, scrolled, released meta: launcher did not open. Pressed meta, released meta: launcher opened Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D2506 BUG: 367730 --- .../x11/standalone/xinputintegration.cpp | 58 +++++++++++++++++++ pointer_input.cpp | 10 ++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/plugins/platforms/x11/standalone/xinputintegration.cpp b/plugins/platforms/x11/standalone/xinputintegration.cpp index 908b26ab26..ce4ceb88e6 100644 --- a/plugins/platforms/x11/standalone/xinputintegration.cpp +++ b/plugins/platforms/x11/standalone/xinputintegration.cpp @@ -18,7 +18,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "xinputintegration.h" +#include "main.h" #include "logging.h" +#include "platform.h" #include "x11cursor.h" #include "keyboard_input.h" @@ -28,6 +30,8 @@ along with this program. If not, see . #include #include +#include + namespace KWin { @@ -52,6 +56,60 @@ public: m_xkb->updateKey(reinterpret_cast(event)->detail - 8, InputRedirection::KeyboardKeyReleased); } break; + case XI_RawButtonPress: + if (m_xkb) { + auto e = reinterpret_cast(event); + switch (e->detail) { + // TODO: this currently ignores left handed settings, for current usage not needed + // if we want to use also for global mouse shortcuts, this needs to reflect state correctly + case XCB_BUTTON_INDEX_1: + kwinApp()->platform()->pointerButtonPressed(BTN_LEFT, e->time); + break; + case XCB_BUTTON_INDEX_2: + kwinApp()->platform()->pointerButtonPressed(BTN_MIDDLE, e->time); + break; + case XCB_BUTTON_INDEX_3: + kwinApp()->platform()->pointerButtonPressed(BTN_RIGHT, e->time); + break; + case XCB_BUTTON_INDEX_4: + case XCB_BUTTON_INDEX_5: + // vertical axis, ignore on press + break; + // TODO: further buttons, horizontal scrolling? + } + } + if (m_x11Cursor) { + m_x11Cursor->schedulePoll(); + } + break; + case XI_RawButtonRelease: + if (m_xkb) { + auto e = reinterpret_cast(event); + switch (e->detail) { + // TODO: this currently ignores left handed settings, for current usage not needed + // if we want to use also for global mouse shortcuts, this needs to reflect state correctly + case XCB_BUTTON_INDEX_1: + kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, e->time); + break; + case XCB_BUTTON_INDEX_2: + kwinApp()->platform()->pointerButtonReleased(BTN_MIDDLE, e->time); + break; + case XCB_BUTTON_INDEX_3: + kwinApp()->platform()->pointerButtonReleased(BTN_RIGHT, e->time); + break; + case XCB_BUTTON_INDEX_4: + kwinApp()->platform()->pointerAxisVertical(120, e->time); + break; + case XCB_BUTTON_INDEX_5: + kwinApp()->platform()->pointerAxisVertical(-120, e->time); + break; + // TODO: further buttons, horizontal scrolling? + } + } + if (m_x11Cursor) { + m_x11Cursor->schedulePoll(); + } + break; default: if (m_x11Cursor) { m_x11Cursor->schedulePoll(); diff --git a/pointer_input.cpp b/pointer_input.cpp index fdbd12c85c..7716a4e61e 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -179,10 +179,11 @@ void PointerInputRedirection::processMotion(const QPointF &pos, uint32_t time, L void PointerInputRedirection::processButton(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time, LibInput::Device *device) { + updateButton(button, state); + if (!m_inited) { return; } - updateButton(button, state); QEvent::Type type; switch (state) { @@ -210,15 +211,16 @@ void PointerInputRedirection::processButton(uint32_t button, InputRedirection::P void PointerInputRedirection::processAxis(InputRedirection::PointerAxis axis, qreal delta, uint32_t time, LibInput::Device *device) { - if (!m_inited) { - return; - } if (delta == 0) { return; } emit m_input->pointerAxisChanged(axis, delta); + if (!m_inited) { + return; + } + WheelEvent wheelEvent(m_pos, delta, (axis == InputRedirection::PointerAxisHorizontal) ? Qt::Horizontal : Qt::Vertical, m_qtButtons, m_input->keyboardModifiers(), time, device);