Bug 99079

Summary: kernel: Improve Surface Pro Type Cover 2 support
Product: Wayland Reporter: defree
Component: libinputAssignee: Wayland bug list <wayland-bugs>
Status: RESOLVED NOTOURBUG QA Contact:
Severity: normal    
Priority: medium CC: benjamin.tissoires, defree, peter.hutterer
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: evemu record log of movement on 4.10
evemu record log of tap on 4.10

Description defree 2016-12-14 09:17:02 UTC
Using Surface Pro 2 is a bit painful due to some problems with input devices.

I would like to help / provide patches to improve this. Being new to libinput, wayland, and more generally freedesktop workflow, I am not sure how to approach the problem and I will appreciate some help to get started.

Below I report the output of libinput-debug-events when I trigger the problematic behaviors.

# Touchpad

model: Microsoft Type Cover 2 Japanese version (but I suspect it happens with western version(s) too)
usb-id: 045e:07aa Microsoft Corp. 
libinput-name: MICROSOFT SAM

## Problems

Spurious KEY_F23 event when clicking (that is a single click produces mouse button + keypress events). (+ pad disabled notification)

Clunky scroll:
- not always detected
- take time to start then scroll by one big chunk

No tap and drag feature, this is critical for usability.

# Touchscreen

usb-id: 03eb:8209 Atmel Corp. 
libinput-name: Atmel Atmel maXTouch Digitizer 

## Problem

I am not familiar with touchscreen, so maybe the behavior I am about to describe is normal and the bug elsewhere.

A sequence for a click is TOUCH_DOWN, TOUCH_FRAME, TOUCH_UP.
During motion, every TOUCH_MOTION is interleaved with a TOUCH_FRAME.

This seems to confuse software a lot (Gnome 3, Firefox, Chrome, both under xorg and wayland/xwayland).

I cannot tell if the bug is in these software or in the input library, but basically actions are missed. For instance, a touch doesn't turn into an actual click or does so unreliably.

I tested the same software on another laptop with touchscreen and the same actions were not so unreliable.  However I didn't think about tracing events at that time, so I cannot tell if the problem is at this level or not.

# Software versions

The computer is running Manjaro with a kernel 4.6 patched to enable USB quirks on the Type Cover 2 JP.
Other software are manjaro stable versions, that is at the time of writing:
libinput-1.5.3
wayland-1.12
gnome-3.22
xorg-1.18
xf86-input-libinput-0.22
Comment 1 defree 2016-12-14 09:19:41 UTC
In "clunky scroll" I refer to two fingers scrolling.
Comment 2 Peter Hutterer 2016-12-15 09:07:58 UTC
(In reply to defree from comment #0)
> ## Problems
> 
> Spurious KEY_F23 event when clicking (that is a single click produces mouse
> button + keypress events). (+ pad disabled notification)

if you see KEY_F23 then that's a hardware issue. something isn't initialized correctly by the kernel, libinput doesn't generate those by itself.

> Clunky scroll:
> - not always detected
> - take time to start then scroll by one big chunk
> 
> No tap and drag feature, this is critical for usability.

is the touchpad detected as a touchpad or just as a mouse-like device? If the former, you'll have to enable tapping, libinput has it disabled by default.

an evemu-record of a scroll sequence should tell us what's going on there.


> # Touchscreen
> 
> usb-id: 03eb:8209 Atmel Corp. 
> libinput-name: Atmel Atmel maXTouch Digitizer 
> 
> ## Problem
> 
> I am not familiar with touchscreen, so maybe the behavior I am about to
> describe is normal and the bug elsewhere.
> 
> A sequence for a click is TOUCH_DOWN, TOUCH_FRAME, TOUCH_UP.
> During motion, every TOUCH_MOTION is interleaved with a TOUCH_FRAME.

yeah, that's correct and is the expected behaviour. TOUCH_FRAME is needed to group frames. either way, short answer here is: touchscreen gestures like tap-to-click is something that needs to be performed on the client-side, i.e. in the application. recent GNOME3 should do this but otherwise it depends on the toolkit.
Comment 3 defree 2016-12-20 12:21:23 UTC
(In reply to Peter Hutterer from comment #2)
> (In reply to defree from comment #0)
> > ## Problems
> > 
> > Spurious KEY_F23 event when clicking (that is a single click produces mouse
> > button + keypress events). (+ pad disabled notification)
> 
> if you see KEY_F23 then that's a hardware issue. something isn't initialized
> correctly by the kernel, libinput doesn't generate those by itself.

Yes that's what I expected. Fyi, here are various dumps of a click:

usbhid-record
        002:010:002:STREAM             1482233549.032873
         01 00 72 00 00 00 00 00 00 00 00 00
        
        002:010:002:STREAM             1482233549.034870
         02 01 00 00 00 00
        
        002:010:002:STREAM             1482233549.052872
         01 00 00 00 00 00 00 00 00 00 00 00
        
        002:010:002:STREAM             1482233549.420859
         02 00 00 00 00 00

evemu-record
        E: 2.422037 0004 0004 458866    # EV_MSC / MSC_SCAN             458866
        E: 2.422037 0001 00c1 0001      # EV_KEY / KEY_F23              1
        E: 2.422037 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +2422ms
        E: 2.424030 0004 0004 589825    # EV_MSC / MSC_SCAN             589825
        E: 2.424030 0001 0110 0001      # EV_KEY / BTN_LEFT             1
        E: 2.424030 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +2ms
        E: 2.441998 0004 0004 458866    # EV_MSC / MSC_SCAN             458866
        E: 2.441998 0001 00c1 0000      # EV_KEY / KEY_F23              0
        E: 2.441998 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +17ms
        E: 4.794013 0004 0004 589825    # EV_MSC / MSC_SCAN             589825
        E: 4.794013 0001 0110 0000      # EV_KEY / BTN_LEFT             0
        E: 4.794013 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +2353ms

So this device need some hack for proper support?
Either a custom initialization procedure or just filtering some packets.
(Is it reasonable to expect that kind of hack into the kernel? Given the huge number of clunky usb devices, it seems one would need a dedicated database for handling that).

> > Clunky scroll:
> > - not always detected
> > - take time to start then scroll by one big chunk
> > 
> > No tap and drag feature, this is critical for usability.
> 
> is the touchpad detected as a touchpad or just as a mouse-like device? If
> the former, you'll have to enable tapping, libinput has it disabled by
> default.

Here is the report by libinput-list-devices, I should have thought about sending that earlier sorry:
        Device:           MICROSOFT SAM
        Kernel:           /dev/input/event10
        Group:            5
        Seat:             seat0, default
        Capabilities:     keyboard pointer 
        Tap-to-click:     n/a
        Tap-and-drag:     n/a
        Tap drag lock:    n/a
        Left-handed:      disabled
        Nat.scrolling:    disabled
        Middle emulation: disabled
        Calibration:      n/a
        Scroll methods:   button
        Click methods:    none
        Disable-w-typing: n/a
        Accel profiles:   flat *adaptive
        Rotation:         n/a

Note that tap to click works as expected, it is the tap and drag which is not available (I cannot enable it with xinput either).

(If I understand correctly, keyboard and touchpad are exposed by the same device, this seems confirmed by the evemu-record and usbhid-dump's).

> an evemu-record of a scroll sequence should tell us what's going on there.

Using usbhid-dump, I can see that the touchpad doesn't send anything for a few hundred milliseconds when scrolling.
I guess it is just low quality touchpad, there is not much to do to fix that (this could match complains I have heard from Windows users).

For information, here is a scroll sequence recorded, normal I guess:

        E: 0.731920 0002 0000 -001      # EV_REL / REL_X                -1
        E: 0.731920 0002 0001 0003      # EV_REL / REL_Y                3
        E: 0.731920 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +731ms
        E: 0.829912 0002 0001 0001      # EV_REL / REL_Y                1
        E: 0.829912 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +98ms
        E: 0.841890 0002 0001 0001      # EV_REL / REL_Y                1
        E: 0.841890 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +12ms
        E: 0.872882 0002 0001 0001      # EV_REL / REL_Y                1
        E: 0.872882 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +31ms
        E: 0.886920 0002 0001 0001      # EV_REL / REL_Y                1
        E: 0.886920 0000 0000 0000      # ------------ SYN_REPORT (0) ---------- +14ms

> > # Touchscreen
> > 
> > usb-id: 03eb:8209 Atmel Corp. 
> > libinput-name: Atmel Atmel maXTouch Digitizer 
> > 
> > ## Problem
> > 
> > I am not familiar with touchscreen, so maybe the behavior I am about to
> > describe is normal and the bug elsewhere.
> > 
> > A sequence for a click is TOUCH_DOWN, TOUCH_FRAME, TOUCH_UP.
> > During motion, every TOUCH_MOTION is interleaved with a TOUCH_FRAME.
> 
> yeah, that's correct and is the expected behaviour. TOUCH_FRAME is needed to
> group frames. either way, short answer here is: touchscreen gestures like
> tap-to-click is something that needs to be performed on the client-side,
> i.e. in the application. recent GNOME3 should do this but otherwise it
> depends on the toolkit.

Ok, I will adjust desktop environment then.
Thank you.
Comment 4 Peter Hutterer 2016-12-20 21:42:00 UTC
(In reply to defree from comment #3)
> So this device need some hack for proper support?
> Either a custom initialization procedure or just filtering some packets.
> (Is it reasonable to expect that kind of hack into the kernel? Given the
> huge number of clunky usb devices, it seems one would need a dedicated
> database for handling that).

yes. CC-ing benjamin, he's done work on the type covers before and knows the current state.

as for tap-to-click and scrolling: the device just looks like a normal mouse with a scroll wheel. tapping is implemented in the firmware, we don't have access to it. here too we'd need the kernel to support this properly and expose it as a touchpad device.

We can put a quickfix in for the F23 though. In libinput's
evdev_pre_configure_model_quirks() put in a call to 

   libevdev_disable_event_code(device->evdev, EV_KEY, KEY_F23);

and see if that has any side-effects. as you noticed, F23 is used for touchpad disabling, so let's see what happens if we just completely filter this out.
Comment 5 defree 2016-12-26 14:42:18 UTC
Filtering F23 works quite well.
Afaict, only effect is to remove the touchpad disabled notification, it is much more comfortable.
Comment 6 Peter Hutterer 2017-01-04 21:58:25 UTC
update: benjamin thinks this should be fixed with v4.1 where the type cover is switched to proper multitouch. If you could confirm this with a pre-release kernel that'd be great.
Comment 7 defree 2017-01-07 19:49:45 UTC
First, about the touchscreen problem, I confirm it is related to handling of events higher in the stack (works fine with a clean gnome-shell 3.22, fails under some circumstances with other GTK apps or Chrome...). Solved as far as input system is concerned :).

I tested with 4.10-rc2 (not manually built but taken from Manjaro's unstable repository). Behavior is quite chaotic. I will try to summarize:
- regression on suspend/resume (4.9 release has the best/correct behavior)
- USB initialization is indeed different, but unreliable.

Cursor behavior is changed:
1) Tap-to-click no longer works (but according to our discussion, it used to be hardware emulation).
2) Movement is still relative but in a weird way. As if coordinates delta were interpreted in a wrong system (the closest I felt was with a wacom mouse which movement was interpreted relative to the tablet and not to the orientation of the mouse itself).
3) Yet libinput-list-devices and xinput list-props reports are the same.

Furthermore, on kernel side device initialization works rarely:
- I have to plug/unplug many times or reboot the device to get it initialized.
- after being initialized with 4.10 kernel, the changes in behavior survive a reboot and change to kernel 4.9. I have to unplug the usb or power off the system to get back to the clean behavior.

This "reboot survival" surprised me the most but I was able to reproduce multiple times.
Comment 8 Peter Hutterer 2017-02-20 23:43:45 UTC
can you give me an evemu-record for a tap and a movement sequence please? Thanks.
Comment 9 defree 2017-02-23 18:07:06 UTC
Today I tried with a kernel 4.10.0 (with manjaro patches, previous tests were on a custom built 4.10rc2), libinput 1.6.1.

All new bugs I complained about are gone (tap-to-click works again, movement are corrects again, and the unrelated suspend-and-resume bug is fixed).

The rest didn't change much: device initialization is still chaotic, most settings are unavailable/fixed by touchpad (no tap-to-drag, etc).

So more or a less a status quo.

To get a comfortable experience, I still have to patch kernel with usb quirks and libinput to filter F23. It is pretty decent with these settings.
Comment 10 defree 2017-02-23 18:08:12 UTC
Created attachment 129880 [details]
evemu record log of movement on 4.10

The movement recording you asked for.
Comment 11 defree 2017-02-23 18:08:43 UTC
Created attachment 129881 [details]
evemu record log of tap on 4.10

The tap record you asked for.
Comment 12 Peter Hutterer 2017-03-13 05:06:03 UTC
sorry for the delay. the two evemu records show relative movement only, so the device is not properly initiated as touchpad on this kernel
Comment 13 Peter Hutterer 2017-05-16 04:25:20 UTC
closing this, mostly so I don't keep looking at this bug when there's nothing we can do in libinput. Benjamin, anything you actually need from this bug? Or can we move this to the kernel?
Comment 14 Benjamin Tissoires 2017-05-16 07:53:16 UTC
IIRC  the surface 2 cover had a wrong HID report descriptor. I am not sure about the F23 key but I wouldn't be surprised if this was related to it too.

I don't want to fix bad report descriptors in hid-multitouch, because that would just open a can of worms. So the status quo is a little bit disappointing, but I don't want to spend too much time fixing a 4 year old device.

If someone has the time to do it, I think it should be done in hid-microsoft.

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.