Skip to content

Add the GdkScrollDeltaUnit api and implement it in GtkScrolledWindow

panoplie requested to merge panoplie/gtk:gdk-scroll-delta-unit into gtk-3-24

This merge request follows !3845 (closed) which itself follows !3766 (closed). It concerns #3631 (closed) which follows #1308 (closed).

It introduces the GdkScrollDeltaUnit enum in GdkEventScroll to help GDK clients to correctly implements the touchpad scroll. The goal is to have a touchpad scroll which follows libinput recommendations i.e. which have the same sensitivity as the unaccelerated touchpad mouse pointer.

Currently the scroll events comme like this from GDK:

  • mouse wheel event : 1 per mouse wheel notch actioned (so 1 for 1 notch motion, 3 for 3...)
  • touchpad scroll : 1/10 per micro-motion. (it's the unaccelerated mouse pointer unit divided per 10)

The touchpad scroll deltas are divided per 10 because mutter sends mouse deltas by multiple of 10 degrees. So they are divided per 10 to get 1 positive or negative unit per actioned wheel notch. However, touchpad scroll deltas come from mutter not divided per 10 but as screen coordinates to scroll directly. Touchpad deltas are nevertheless divided per 10 too like as if they were coming from the mouse.

The problem is that the GDK clients (example : GtkScrolledWindow) can't determine the incoming events deltas unit. So touchpad scroll events are treated in mouse wheel events unit on the GTK (or other stacks) side. That's why a lot of people find the touchpad scroll far too fast on GDK apps.

After this patch, the scroll events will comme like this from GDK:

  • mouse wheel event : 1 per mouse wheel notch actioned (so 10 for 1 notch motion, 30 for 3...) (unchanged)
  • touchpad scroll : 1 per micro-motion. (it's the unaccelerated mouse pointer unit not divided per 10 this time i.e. the direct number of "pixels" to scroll on screen)

But the GdkScrollDeltaUnit delta_unit variable will indicate to clients the good delta unit and so how to threat the deltas. As suggested by @djrenren and to not break existings apps which may be waiting for divided per 10 touchpad scroll deltas, the correct undivided by 10 pixels deltas will be provided in new pixels_delta_x and pixels_delta_y fields.

GtkScrolledWindow directly use this new variables but not the other GDK third-party clients like Firefox. If this merge request is accepted, these apps will need to update to support GdkScrollDeltaUnit and provide a clean touchpad scroll experience.

Don't forget that the scroll delta unit is independant of the scroll device. For example on Mac OS, all scroll events are in pixels unit even those from mouse wheel as suggested by the ifndef GDK_WINDOWING_QUARTZ condition in GtkScrolledWindow (before this merge request).

This new API only concerns Wayland for the moment but could be implemented on X11 if approved. The behavior on other platforms is normally unchanged.

This merge request targets GTK 3 to impact the most apps for the moment and will be submited on GTK 4 if accepted.

Thanks you!

Edited by panoplie

Merge request reports