Commit 0eba3f3c authored by Jesse Pullinen's avatar Jesse Pullinen

Fix TouchEvent::id() returning -1, fixes a crash

Libinput returns -1 when calling libinput_event_touch_get_slot on an event
from a single-touch touchscreen. The returned value is used in
DecorationEventFilter to determine the touch which is acting on it. The value -1
is used to signify that the decoration is not being acted on. Thus when
releasing the touch, it checks whether it was being dragged, and as it thinks
it isn't, it doesn't handle it and the decoration is still being dragged.
Clicking on the decoration then crashes kwin.

Test Plan: Move a window by dragging the decoration with a single-touch touchscreen.

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: graesslin, kwin, #kwin

Tags: #kwin

Differential Revision:
parent a5e523ca
......@@ -40,6 +40,7 @@ private Q_SLOTS:
void testType();
void testAbsoluteMotion_data();
void testAbsoluteMotion();
void testNoAssignedSlot();
libinput_device *m_nativeDevice = nullptr;
......@@ -126,5 +127,19 @@ void TestLibinputTouchEvent::testAbsoluteMotion()
QCOMPARE(te->absolutePos(QSize(1280, 1024)), QPointF(640, 512));
void TestLibinputTouchEvent::testNoAssignedSlot()
// this test verifies that touch events without an assigned slot get id == 0
libinput_event_touch *touchEvent = new libinput_event_touch;
touchEvent->type = LIBINPUT_EVENT_TOUCH_UP;
touchEvent->device = m_nativeDevice;
// touch events without an assigned slot have slot == -1
touchEvent->slot = -1;
QScopedPointer<Event> event(Event::create(touchEvent));
QCOMPARE(dynamic_cast<TouchEvent*>(>id(), 0);
#include "touch_event_test.moc"
......@@ -225,7 +225,10 @@ QPointF TouchEvent::absolutePos(const QSize &size) const
qint32 TouchEvent::id() const
return libinput_event_touch_get_slot(m_touchEvent);
const qint32 slot = libinput_event_touch_get_slot(m_touchEvent);
return slot == -1 ? 0 : slot;
GestureEvent::GestureEvent(libinput_event *event, libinput_event_type type)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment