SDL
SDL copied to clipboard
Natural scrolling in Gnome...
Upgraded to Ubuntu 21.10, and noticed that Gnome offers "natural scrolling" (the reverse direction mousewheel thing that Apple does).
I don't know how one accesses this information, but in theory this means we can set the direction
field of SDL_MouseWheelEvent on x11, at least in some instances.
This information can be grabbed at the command line from gsettings, and the checkbox in the system preferences UI toggles this value.
gsettings get org.gnome.desktop.peripherals.touchpad natural-scroll
So we can probably talk to d-bus to acquire this information at runtime, in some form.
Note that it's mouse
instead of touchpad
for...mice, I guess. It's a separate setting! It's not clear to me yet how we tell which kind of device we're talking to.
@icculus What if we don't have dbus on the target system?
@icculus What if we don't have dbus on the target system?
This is the standard interface Gnome uses to publish this information, all I could do without a D-Bus connection is just not report natural scrolling state, I assume.
So the goal is to offer natural scrolling for both touchpad and mouse seperately and modifying the SDL_MouseWheelEvent accordingly? Are you already working on it or can I have a look at it?
The goal is to report the information in a way that matches Gnome settings...but I don't know how to decide what Gnome thinks is a touchpad or mouse under X11 and Wayland.
This is not unknowable, I just don't know it. I assume we can find a way to determine it.
If you want to work on it: go ahead!
The setting in GNOME changes the events you get from X11 automatically, which means that you don't have to change anything manually. So if you just wanna report the information, we could - as you already mentioned - just get them through dbus. But what would be the usecase anyways?
The setting in GNOME changes the events you get from X11 automatically,
Huh, I was surprised to discover this today!
SDL still has a flag it sends with the event to say "this is reporting a scroll down, but we think the user physically scrolled up and the OS reversed it for 'natural' scrolling support" and it would be nice to support that part, too.
Alright, I'll be working on it when I figured out a way to differentiate between mousepad-caused events and normal mousewheel events. Apparently GNOME allows you to have different settings for these two simultaneously. I have to dig a little deeper.
I'll be uploading an SDL implementation of my solution in the near future. I still have to read through all of the X11 code of SDL2 to get a better understanding, where what is and how SDL2 itself is structured. With my solution we are then able to correctly set the direction flag based on what is set in the OS settings and what device the event was generated with and not just always set the direction to SDL_MOUSEWHEEL_NORMAL. We could then slowly add more and more desktop environment settings to this code (e.g. XFCE, which has the "Reverse scroll direction" option) to basically reach full support for all X desktop environments. (at least the major ones) Maybe I'll find an even better solution, we'll see.