SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Natural scrolling in Gnome...

Open icculus opened this issue 3 years ago • 9 comments

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.

icculus avatar Dec 04 '21 17:12 icculus

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 avatar Feb 07 '22 05:02 icculus

@icculus What if we don't have dbus on the target system?

Axilot avatar Jul 23 '22 16:07 Axilot

@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.

icculus avatar Jul 24 '22 05:07 icculus

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?

Axilot avatar Jul 24 '22 09:07 Axilot

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!

icculus avatar Jul 25 '22 03:07 icculus

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?

Axilot avatar Jul 25 '22 17:07 Axilot

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.

icculus avatar Jul 25 '22 21:07 icculus

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.

Axilot avatar Jul 26 '22 08:07 Axilot

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.

Axilot avatar Jul 26 '22 18:07 Axilot