xcb: Ignore XI2 LMB mouse events from touch screens

157ee01a8d was trying to
minimize some side effects of the bug in the evdev driver
(https://bugs.freedesktop.org/show_bug.cgi?id=98188) by
not changing mouse button state on motion.
Unfortunately it resurrected bugs that were fixed by
76de1ac0a4.
Filter out mouse events from touch screens instead.
This change reverts 157ee01a8d.

Task-number: QTBUG-32609
Task-number: QTBUG-35065
Task-number: QTBUG-43776
Task-number: QTBUG-44166
Task-number: QTBUG-44231
Task-number: QTBUG-56156
Change-Id: Ie17710d94beabeb08681d669a9d8309be9b44e73
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
bb10
Alexander Volkov 2016-12-22 15:12:28 +03:00
parent 69ce68cb89
commit 73dafaf265
4 changed files with 24 additions and 17 deletions

View File

@ -517,6 +517,7 @@ public:
#ifdef XCB_USE_XINPUT22
bool xi2MouseEvents() const;
bool isTouchScreen(int id) const;
#endif
protected:

View File

@ -1025,6 +1025,13 @@ Qt::MouseButton QXcbConnection::xiToQtMouseButton(uint32_t b)
return Qt::NoButton;
}
bool QXcbConnection::isTouchScreen(int id) const
{
auto device = m_touchDevices.value(id);
return device && device->qtTouchDevice
&& device->qtTouchDevice->type() == QTouchDevice::TouchScreen;
}
static QTabletEvent::TabletDevice toolIdToTabletDevice(quint32 toolId) {
// keep in sync with wacom_intuos_inout() in Linux kernel driver wacom_wac.c
switch (toolId) {

View File

@ -2423,22 +2423,27 @@ static inline int fixed1616ToInt(FP1616 val)
return int((qreal(val >> 16)) + (val & 0xFFFF) / (qreal)0xFFFF);
}
void QXcbWindow::handleXIMouseButtonState(const xcb_ge_event_t *event)
{
QXcbConnection *conn = connection();
const xXIDeviceEvent *ev = reinterpret_cast<const xXIDeviceEvent *>(event);
if (ev->buttons_len > 0) {
unsigned char *buttonMask = (unsigned char *) &ev[1];
for (int i = 1; i <= 15; ++i)
conn->setButton(conn->translateMouseButton(i), XIMaskIsSet(buttonMask, i));
}
}
// With XI 2.2+ press/release/motion comes here instead of the above handlers.
void QXcbWindow::handleXIMouseEvent(xcb_ge_event_t *event, Qt::MouseEventSource source)
{
QXcbConnection *conn = connection();
xXIDeviceEvent *ev = reinterpret_cast<xXIDeviceEvent *>(event);
if (ev->buttons_len > 0) {
unsigned char *buttonMask = (unsigned char *) &ev[1];
// There is a bug in the evdev driver which leads to receiving mouse events without
// XIPointerEmulated being set: https://bugs.freedesktop.org/show_bug.cgi?id=98188
// Filter them out by other attributes: when their source device is a touch screen
// and the LMB is pressed.
if (XIMaskIsSet(buttonMask, 1) && conn->isTouchScreen(ev->sourceid)) {
if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
qCDebug(lcQpaXInput, "XI2 mouse event from touch device %d was ignored", ev->sourceid);
return;
}
for (int i = 1; i <= 15; ++i)
conn->setButton(conn->translateMouseButton(i), XIMaskIsSet(buttonMask, i));
}
const Qt::KeyboardModifiers modifiers = conn->keyboard()->translateModifiers(ev->mods.effective_mods);
const int event_x = fixed1616ToInt(ev->event_x);
const int event_y = fixed1616ToInt(ev->event_y);
@ -2458,23 +2463,18 @@ void QXcbWindow::handleXIMouseEvent(xcb_ge_event_t *event, Qt::MouseEventSource
switch (ev->evtype) {
case XI_ButtonPress:
handleXIMouseButtonState(event);
if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
qCDebug(lcQpaXInputEvents, "XI2 mouse press, button %d, time %d, source %s", button, ev->time, sourceName);
conn->setButton(button, true);
handleButtonPressEvent(event_x, event_y, root_x, root_y, ev->detail, modifiers, ev->time, source);
break;
case XI_ButtonRelease:
handleXIMouseButtonState(event);
if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
qCDebug(lcQpaXInputEvents, "XI2 mouse release, button %d, time %d, source %s", button, ev->time, sourceName);
conn->setButton(button, false);
handleButtonReleaseEvent(event_x, event_y, root_x, root_y, ev->detail, modifiers, ev->time, source);
break;
case XI_Motion:
// Here we do NOT call handleXIMouseButtonState because we don't expect button state change to be bundled with motion.
// When a touchscreen is pressed, an XI_Motion event occurs in which XIMaskIsSet says the left button is pressed,
// but we don't want QGuiApplicationPrivate::processMouseEvent() to react by generating a mouse press event.
if (Q_UNLIKELY(lcQpaXInputEvents().isDebugEnabled()))
qCDebug(lcQpaXInputEvents, "XI2 mouse motion %d,%d, time %d, source %s", event_x, event_y, ev->time, sourceName);
handleMotionNotifyEvent(event_x, event_y, root_x, root_y, modifiers, ev->time, source);

View File

@ -139,7 +139,6 @@ public:
void handleFocusOutEvent(const xcb_focus_out_event_t *event) override;
void handlePropertyNotifyEvent(const xcb_property_notify_event_t *event) override;
#ifdef XCB_USE_XINPUT22
void handleXIMouseButtonState(const xcb_ge_event_t *);
void handleXIMouseEvent(xcb_ge_event_t *, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized) override;
void handleXIEnterLeave(xcb_ge_event_t *) override;
#endif