Bug 98188

Summary: xf86-input-evdev regression: every touchscreen movement is duplicated as a core pointer movement, without XIPointerEmulated being set
Product: xorg Reporter: s <s>
Component: Input/evdevAssignee: Peter Hutterer <peter.hutterer>
Status: RESOLVED FIXED QA Contact: Xorg Project Team <xorg-team>
Severity: normal    
Priority: medium CC: peter.hutterer
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments:
Description Flags
bugfix none

Description s@ecloud.org 2016-10-10 14:24:27 UTC
I believe this is the cause of https://bugreports.qt.io/browse/QTBUG-56156 , and also of a behavior I've been noticing for a while, that if you use a MultiPointTouchArea in QtQuick, you will have a duplicated touchpoint for the first finger which is pressed.  (This is because MPTA can handle the mouse as a fake "touchpoint".)

I used git bisect on xf86-input-evdev and narrowed it down to this:

d24431a1863c49aa9edcabf535ffa64bfa87053c is the first bad commit
commit d24431a1863c49aa9edcabf535ffa64bfa87053c
Author: Peter Hutterer <peter.hutterer@who-t.net>
Date:   Thu Jan 14 10:41:46 2016 +1000

    Restore wheel emulation for absolute devices
    
    Wheel emulation relies on oldVals, which stopped updating in 3dcf6f123c5.
    
    Since wheel emulation may filter the abs event, store the event before we do
    anything with it. If we really want the abs_event, abs_queued will be set to
    1, otherwise the value will be ignored.
    
    And now that we know abs_value is always valied, we can copy its value into
    old_vals, so that wheel emulation can calculate the delta correctly.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=93617
    
    Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

:040000 040000 4560fb98c990298ab34797ccf78b530863eff520 a83dc9b3430a117cfec3eeab3c6c00a0c255bcff M s

If I use libinput instead, I don't have this problem.  But libinput has another problem: on a system with multiple touchscreens, they aren't treated as unique devices.  I wanted to test that scenario, so went back to using evdev for a while... and then this bug came back into focus.

The entry point for Qt to handle the XI_Motion events is here:

http://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp?h=5.6#n546

and it's possible to add a qDebug there to watch it happen:

    if (xiDeviceEvent) {
        switch (xiDeviceEvent->evtype) {
        case XI_ButtonPress:
        case XI_ButtonRelease:
        case XI_Motion:
+ qDebug() << "xiDeviceEvent->dev" << hex << xiDeviceEvent->deviceid << "flags" << xiDeviceEvent->flags;
            if (xi2MouseEvents() && eventListener && !(xiDeviceEvent->flags & XIPointerEmulated))
                eventListener->handleXIMouseEvent(event);
            break;

then try the mouse and the touchscreen: both say that deviceid is 2 and flags are 0, so we can't tell the difference.  The XIPointerEmulated was supposed to be set so that we could ignore the core pointer movements coming from the touchscreen.
Comment 1 Peter Hutterer 2016-10-11 08:47:40 UTC
(In reply to s@ecloud.org from comment #0)
> If I use libinput instead, I don't have this problem.  But libinput has
> another problem: on a system with multiple touchscreens, they aren't treated
> as unique devices.  I wanted to test that scenario, so went back to using
> evdev for a while... and then this bug came back into focus.

I'll think about the rest some other time, but please file a bug against libipnut for this (right now I'm not sure what exactly the bug is you're describing here)
Comment 2 Alexander Volkov 2016-12-26 14:34:36 UTC
This bug is absolutely unrelated to libinput, it is specific for xf86-input-evdev.
You can reproduce it with 'xinput test-xi2':
EVENT type 19 (TouchUpdate)
    device: 12 (12)
    detail: 2
    root: 233.91/170.86
    event: 155.91/46.86
    buttons:
    modifiers: locked 0 latched 0 base 0 effective: 0
    group: locked 0 latched 0 base 0 effective: 0
    valuators:
        0: 499.00
        1: 648.00
        2: 5.00
        3: 3.00
        5: 499.00
        6: 648.00
    windows: root 0xd5 event 0x1e00001 child 0x1e00001
EVENT type 6 (Motion)
    device: 2 (12)
    detail: 0
    flags: emulated
    root: 233.91/170.86
    event: 155.91/46.86
    buttons: 1
    modifiers: locked 0 latched 0 base 0 effective: 0
    group: locked 0 latched 0 base 0 effective: 0
    valuators:
        0: 499.00
        1: 648.00
        2: 5.00
        3: 3.00
        5: 499.00
        6: 648.00
    windows: root 0xd5 event 0x1e00001 child 0x0
EVENT type 6 (Motion) !!! Oops, we should not receive it
    device: 12 (12)
    detail: 0
    flags: !!! emulated is not set
    root: 233.91/170.99
    event: 155.91/46.99
    buttons: 1
    modifiers: locked 0 latched 0 base 0 effective: 0
    group: locked 0 latched 0 base 0 effective: 0
    valuators:
        1: 694.00
    windows: root 0xd5 event 0x1e00001 child 0x0

xf86-input-evdev is sending motion events from the slave touch device and it's not possible to filter them out by the XIPointerEmulated flag.
Comment 3 Alexander Volkov 2016-12-26 14:49:02 UTC
Created attachment 128662 [details] [review]
bugfix
Comment 4 s@ecloud.org 2016-12-27 14:14:26 UTC
Alexander's patch seems to work for me.
Comment 5 Peter Hutterer 2017-01-03 01:31:54 UTC
Pushed as 231061d004ee4e924bb736adc428287367d2001c, thanks!

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.