'Duplicate scroll events from GTK
I've been trying to process scroll-event
s from a GTK window. I have a custom scrollbar that handles smooth scrolling events and non-smooth scrolling events differently, and simulates smooth scrolling for non-smooth scrolling events. I learned from the docs that GDK sets GdkEventScroll::direction
to GDK_SCROLL_SMOOTH
for smooth scroll events. However, I noticed that when I scroll the middle mouse button (my mouse does not support smooth scrolling), GTK sends two separate events:
- one event with
direction
set toGDK_SCROLL_UP
orGDK_SCROLL_DOWN
anddelta_y
set to 0, and - one event with
direction
set toGDK_SCROLL_SMOOTH
anddelta_y
set to 1 or -1.
Before adding the special handing I relied solely on delta_y
which happened to work fine for me. Now that I've started treating smooth and non-smooth scrolling differently, I need a reliable way to distinguish between these kinds of events.
- Is there a flag that I can set to have GDK send only non-smooth scrolling events for non-smooth scrolling, and vice versa? That would be my preferred solution.
- If the previous one is not possible, is there any way I can tell that two scroll events are actually the same event? I see that there's a
time
field in the event structure, but I doubt it'll be reliable.
Thank you.
Solution 1:[1]
You mentioned it yourself: the time
field is the key. If Gtk generates multiple events from the same “real” event, the time
will be the same.
It has millisecond resolution, so I’m pretty sure you will not see multiple real events on the same millisecond. It will be hard to scroll that fast on the mouse to do it the same millisecond.—I have not checked the code, but Gtk should flatten multiple smooth device events so that multiple of those will not have the same millisecond either.
Gtk will send both types of events for both kind of devices (one real and one fake) so that applications work if they handle only one type.—You can go for the device
field to see if you get scrolling from multiple devices.
Out of curiosity: do you have a single device with sends both smooth and non-smooth events!?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Robert Siemer |