udev: touchscreen pointer never pressed/released correctly (KMS, UDEV_TOUCH_SUPPORT)

Open
#20,060 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, linux

Research direction

Start with the three reported locations in input/drivers/udev_input.c: pointer button state around line 2393, pointer state reporting around lines 3037-3041, and touch event handling around lines 2659-2729. Trace how touch contacts update pointer state and MT slots, then reproduce with the issue’s udev touchscreen setup. Done means taps register, pointer state follows contact press and release, and multi-touch scrolling produces no phantom releases.

Written by the indexing model from the issue text.

Description

Is there an existing issue for this?
  • This is a bug in RetroArch frontend
  • I have searched the existing issues
Description

With the udev input driver built with -DUDEV_TOUCH_SUPPORT, taps on a touchscreen do nothing in the menu. I found three bugs in input/drivers/udev_input.c. All three are still in master (49582a9, line numbers below are from that commit).

1. The simulated pointer is reported pressed after release (line 2393)

/* Release the pointer only after all contacts are released */
if (touch->pointer_enabled)
   touch->pointer_btn_pp = (touch->staging_active == 0);

staging_active has already been decremented here, so the condition is inverted: the pointer is pressed after the last finger is lifted and released while a finger is still down. The menu acts on release, so taps never register. Fix: (touch->staging_active > 0).

2. udev_input_touch_state() always returns 0 for the pointer (lines 3037-3041)

case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
   screen = (device == RARCH_DEVICE_MOUSE_SCREEN);
   break;
   switch (id)

The stray break leaves before switch (id), so pointer X/Y/pressed are never reported. The comparison also uses RARCH_DEVICE_MOUSE_SCREEN instead of RARCH_DEVICE_POINTER_SCREEN. Fix: remove the break and compare with RARCH_DEVICE_POINTER_SCREEN.

3. Single-touch emulation is mixed into MT slot 0 (ABS_X line 2659, ABS_Y around line 2683, BTN_TOUCH line 2729)

For multi-touch devices the kernel also sends single-touch emulation (ABS_X, ABS_Y, BTN_TOUCH) that follows the oldest active contact. The code writes it into slot 0 (BTN_TOUCH even into the current slot) on top of the MT slot data. When a second contact outlives the first one, the emulation jumps to it: slot 0 gets that position and a second touch up, the log shows Cannot report touch up since there are no active points. and the menu sees phantom releases and taps while scrolling. The MT slots carry the same data, so the fix is to skip these three events when the device has MT slots:

if (touch->info_slots.enabled && touch->info_slots.range > 1)
   break;

Single-touch devices (no ABS_MT_SLOT) are not affected by this change.

Bugs 1 and 2 seem to date back to the touch rewrite in #15282 (2023).

Side note: nothing in the build system defines UDEV_TOUCH_SUPPORT (configure, Makefile.common), so distribution builds have no touchscreen support in udev at all. Maybe it could become a configure option once these bugs are fixed.

I have patches against v1.20.0 tested on hardware and can open a PR against master if that helps:
https://github.com/cyryllo/banana-a20/tree/arkada20-v1.0-trixie-6.18.62/armbian-build/konsola/latki-retroarch (0001, 0002, 0007)

Expected behavior

A tap selects a menu entry, the pointer is pressed while a finger is down and released when the last finger is lifted.

Steps to reproduce the bug
  1. Build RetroArch for Linux with KMS and udev, CFLAGS=-DUDEV_TOUCH_SUPPORT.
  2. Run it on a device with a multi-touch touchscreen (evdev with ABS_MT_SLOT), input_driver = "udev", menu_pointer_enable = "true", input_touch_vmouse_pointer = "true".
  3. Tap a menu entry: nothing happens. With 1 and 2 fixed, taps work, but with two contacts the menu gets phantom releases (bug 3).
Version/Commit

1.20.0 (built from the v1.20.0 tag). The same code is in master 49582a9.

Bisect Results

Probably since #15282 (2023), not bisected.

Present in the nightly version

I don't know

Platform & operating system

Linux armhf, Debian 13 (Armbian), kernel 6.18.62, LeMaker Banana Pro (Allwinner A20)

Affected Cores

None (menu)

Environment information

KMS + EGL + OpenGL ES 2 (Mesa lima, Mali-400), udev input, no X11/Wayland. Touchscreen: FocalTech FT5x06 (edt-ft5x06 driver), 1024x600, multi-touch with slots.

Relevant log output
`[udev] Cannot report touch up since there are no active points.` (bug 3)
Dominant language
C
Stars
14.6k
Forks
2.4k
Avg merge
2d 5h
Merged PRs (30d)
63

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from libretro/RetroArch

All issues in libretro/RetroArch

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.