Skip to content

High-resolution scroll wheel support

Description:

Starting with Linux Kernel v5.0 two new axes are available for high-resolution wheel scrolling: REL_WHEEL_HI_RES and REL_HWHEEL_HI_RES. Both axes send data in fractions of 120 where each multiple of 120 amounts to one logical scroll event. Fractions of 120 indicate a wheel movement less than one detent. A "detent" is the named used in the Kernel for a mouse wheel click: https://www.kernel.org/doc/html/v5.11-rc7/input/event-codes.html#ev-rel

Three new events are now available on libinput: LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, LIBINPUT_EVENT_POINTER_SCROLL_FINGER, and LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS. These events replace the LIBINPUT_EVENT_POINTER_AXIS event, so new clients should simply ignore that event.

This LIBINPUT_EVENT_POINTER_SCROLL_WHEEL event adds a new API libinput_pointer_scroll_get_value_v120(). The libinput_pointer_scroll_get_value_v120() is a mirror from the kernel API (itself a copy of the Windows API). The new event is sent for all wheel events, even those that don't technically support high-resolution scrolling and even on older kernels that don't have this feature. So callers can simply ignore any LIBINPUT_EVENT_POINTER_AXIS event and use the new event types only.

For LIBINPUT_EVENT_POINTER_SCROLL_FINGER and LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS, as well as LIBINPUT_EVENT_POINTER_SCROLL_WHEEL, a new API is available: libinput_pointer_scroll_get_value(). This API is similar to libinput_pointer_axis_get_value().

Status

How to test it:

Clone and install my libinput branch: libinput/libinput!652 (merged)

Clone and install Peter's Wayland protocol: wayland/wayland!72 (merged)

Reboot.

tinywl has been updated in this PR, so you can test that scroll is still working with backends that support and don't support high-resolution scroll.

To test with a client that supports high-resolution scroll, clone my GTK branch: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3839

And run it:

$ meson build --prefix=`pwd`/build/install --buildtype=debug # Installing here to not replace your stable GTK
$ ninja -C build && \
   ninja -C build install && \
   GDK_BACKEND=wayland WAYLAND_DEBUG=1 XDG_DATA_DIRS=`pwd`/build/install/share:$XDG_DATA_DIRS LD_LIBRARY_PATH=`pwd`/build/install/lib64:$LD_LIBRARY_PATH ./build/install/bin/gtk4-demo

Of course, you'll need hardware to test it. Logitech mice are supported, otherwise any mouse that shows a ResolutionMultiplier in the hid-recorder output (most Microsoft-branded mice of the last decade). Or, if you happen to have an Apple Magic Mouse, I added support in the Kernel. You'll need to compile the Kernel with my patches, let me know if you need help.

For code reviewers

It's easier to review this PR commit by commit.

I hesitated a lot about "seat: support lo-res clients using hi-res backends". Placing the accumulators in wlr_seat_client is technically incorrect, there should be an accumulator for each pointer in wlr_seat_client->pointers.

However, given that the accumulator expires after one second of inactivity and given than using 2 or more mice at the same time is a niche use case, I decided to leave the accumulator there for the sake of simplicity. Also, the side effects of using multiple mice at the same time are really difficult to notice.

Keeping the PR as draft until there is a client to test with.

cc @emersion @whot

Edited by Simon Zeni

Merge request reports