Bug 438326

Summary: Using KWin for wayland, GTK scroll events report wrong scroll distance.
Product: [Plasma] kwin Reporter: Emilio Cobos Álvarez (:emilio) <emilio>
Component: libinputAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: normal CC: emilio, nate
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Sample python application that shows the issue.
Err, program that actually reproduces the issue

Description Emilio Cobos Álvarez (:emilio) 2021-06-09 13:55:53 UTC
Created attachment 139141 [details]
Sample python application that shows the issue.

SUMMARY

Using a mousewheel on Plasma 5 (under Wayland), gtk applications receive scroll events with odd deltas.

On Gnome 40 or Plasma on X11, a single wheel tick reports a GdkScrollEvent.delta_y value of 1, while on plasma it reports 1.5. This causes GTK apps to scroll faster than usual.

STEPS TO REPRODUCE
1. Run the application attached in Plasma with wayland
2. Use the mousewheel

OBSERVED RESULT

Note the scroll deltas:

> scroll 0.0 1.5

EXPECTED RESULT

> Scroll 0.0 1.0

SOFTWARE/OS VERSIONS

Operating System: Fedora 34
KDE Frameworks Version: 5.82.0
Qt Version: 5.15.2
Kernel Version: 5.12.9-300.fc34.x86_64
OS Type: 64-bit
Graphics Platform: Wayland

ADDITIONAL INFORMATION

I found this when trying to make Firefox scroll a bit faster: https://bugzilla.mozilla.org/show_bug.cgi?id=1715513

The patch there causes Gnome to work great, but on Plasma+Wayland the scroll speed is too high because of this bug.
Comment 1 Emilio Cobos Álvarez (:emilio) 2021-06-09 14:06:23 UTC
(Let me know if I got the component wrong or what not btw)
Comment 2 Emilio Cobos Álvarez (:emilio) 2021-06-09 15:18:16 UTC
I realized that the number you get is affected by the scroll factor in the mouse system settings (but I don't think I ever changed them, and in fact it seems there's no tick in the range slider to make this go to "1", so I suspect something else is going on...)
Comment 3 Emilio Cobos Álvarez (:emilio) 2021-06-21 10:39:27 UTC
Created attachment 139569 [details]
Err, program that actually reproduces the issue

For some reason the file I attached was just a dummy GTK app, not the thing I was using for testing.
Comment 4 Emilio Cobos Álvarez (:emilio) 2022-01-08 01:40:06 UTC
If someone can point me into the right direction I'm happy to try fixing this, fwiw :)
Comment 5 Emilio Cobos Álvarez (:emilio) 2022-01-09 01:44:30 UTC
Ok, KWin does expose the discrete event as well, so we can listen to that.
Comment 6 Vlad Zahorodnii 2022-01-10 08:58:23 UTC
(In reply to Emilio Cobos Álvarez (:emilio) from comment #4)
> If someone can point me into the right direction I'm happy to try fixing
> this, fwiw :)

Does GDK divide delta values, e.g. by 10? KWin simply forwards delta values from libinput. On my machine, a single wheel click produces an axis event with a delta of 15. If GDK divides that value by 10, it could explain 1.5.
Comment 7 Emilio Cobos Álvarez (:emilio) 2022-01-10 09:04:55 UTC
(In reply to Vlad Zahorodnii from comment #6)
> (In reply to Emilio Cobos Álvarez (:emilio) from comment #4)
> Does GDK divide delta values, e.g. by 10? KWin simply forwards delta values
> from libinput. On my machine, a single wheel click produces an axis event
> with a delta of 15. If GDK divides that value by 10, it could explain 1.5.

That's exactly right: https://gitlab.gnome.org/GNOME/gtk/-/blob/6bd96522e87682d48d9f1218050cff9f7b0bb3ae/gdk/wayland/gdkdevice-wayland.c#L1753-1764
Comment 8 Emilio Cobos Álvarez (:emilio) 2022-01-10 09:07:51 UTC
And mutter sends always 10 for discrete events: https://gitlab.gnome.org/GNOME/mutter/-/blob/bb6ae40a0feb93727dff8c51bf0560279d8d89db/src/wayland/meta-wayland-pointer.c#L73
Comment 9 Vlad Zahorodnii 2022-01-10 09:34:21 UTC
As far as I know, "10" is not enforced by the core spec, i.e. kwin is not in the wrong. Using discrete delta might be a better option indeed, note that it will be obsolete with wl_pointer.axis_v120.
Comment 10 Emilio Cobos Álvarez (:emilio) 2022-01-10 11:04:26 UTC
(In reply to Vlad Zahorodnii from comment #9)
> As far as I know, "10" is not enforced by the core spec, i.e. kwin is not in
> the wrong. Using discrete delta might be a better option indeed, note that
> it will be obsolete with wl_pointer.axis_v120.

Oh, do you have a link for that? I have a patch to use the discrete deltas here: https://phabricator.services.mozilla.com/D135453.

I guess we could check the GTK source being `MOUSE`, and force the delta to 1, or we can just WONTFIX https://bugzilla.mozilla.org/show_bug.cgi?id=1749169 and claim we're not doing anything wrong because the KWin delta is just higher than the Mutter delta, but both of those feel a bit unfortunate.
Comment 11 Vlad Zahorodnii 2022-01-10 11:27:01 UTC
(In reply to Emilio Cobos Álvarez (:emilio) from comment #10)
> Oh, do you have a link for that? I have a patch to use the discrete deltas
> here: https://phabricator.services.mozilla.com/D135453.

https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/72

It's equivalent to axis_discrete in some way. 1 axis_discrete == 120 axis_v120
Comment 12 Emilio Cobos Álvarez (:emilio) 2022-01-10 12:00:04 UTC
(In reply to Vlad Zahorodnii from comment #11)
> (In reply to Emilio Cobos Álvarez (:emilio) from comment #10)
> https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/72
> 
> It's equivalent to axis_discrete in some way. 1 axis_discrete == 120
> axis_v120

Ah, ok, I see. As long as we can get the discrete events somehow from GTK should be fine, thanks.