Natural Scrolling in linux desktop

If you ever wanted to enable natural scrolling also called reverse scrolling on your linux desktop that doesn't have a touch pad, you will notice that mouse and touch pad settings does not have the option to enable natural scrolling like you would on a laptop.

There are plenty of tutorials on the internet that will show various ways to enable this feature. For example, using xmodmap by creating a ~/.Xmodmap file and putting pointer = 1 2 3 5 4 7 6 8 9 10 11 12 in that file. This pretty much swaps the order of buttons declared in synaptics. This works half way, at least on a Gnome desktop. You will notice that all applications except for the ones built with GTK are working just fine. All GTK applications will not honor the settings inside ~/.Xmodmap for natural scrolling.

There are other articles on the internet that instruct to use dconf-editor and set natural scrolling like the following.

$: gsettings set org.gnome.desktop.peripherals.mouse.natural-scroll true

or

$: gsettings set org.gnome.desktop.peripherals.touchpad.natural-scroll true

None of the above solutions have completely worked for me.

Now on to the solution. To enable system-wide natural scrolling, do the following.

Please note that the X11/Xorg configuration paths are relative to Arch Linux. The X11/Xorg configuration paths may be different in the distribution you are using.

  1. Find the mouse's device id
    $: xinput list
    ⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
    ⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
    ⎜   ↳ Logitech M705                           	id=9	[slave  pointer  (2)]
    ⎜   ↳ Logitech M510                           	id=10	[slave  pointer  (2)]
    ⎜   ↳ Logitech K750                           	id=11	[slave  pointer  (2)]
    ⎜   ↳ MCE IR Keyboard/Mouse (nuvoton-cir)     	id=14	[slave  pointer  (2)]
    ⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
        ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
        ↳ Power Button                            	id=6	[slave  keyboard (3)]
        ↳ Video Bus                               	id=7	[slave  keyboard (3)]
        ↳ Power Button                            	id=8	[slave  keyboard (3)]
        ↳ CMEDIA USB2.0 High-Speed True HD Audio  	id=12	[slave  keyboard (3)]
        ↳ Nuvoton w836x7hg Infrared Remote Transceiver	id=13	[slave  keyboard (3)]

    In my case, my mouse's id is 9.

  2. Now lets find the Scrolling Distance property of the mouse.
    $: xinput list-props 9 | grep "Scrolling Distance"
    	Evdev Scrolling Distance (271):	1, 1, 1

    The scrolling distance for my mouse happened to be 1 but yours might be some other number. The trick is negate that number and store that as ScrollDeltas in xorg configuration for mouse that we will create in the next step.

  3. Now lets create the xorg configuration file that will enable system wide natural scrolling. I am using vim as my editor of choice, you can choose the one you prefer. Also notice the number -1 in Vert/Horiz/Dial deltas.. make sure to use the negated number that you got from Step 2.
    $: sudo vim /etc/X11/xorg.conf.d/20-natural-scrolling.conf
  4. Add the following content to the editor.
    Section "InputClass"
            Identifier "Natural Scrolling"
            MatchIsPointer "on"
            MatchDevicePath "/dev/input/event*"
            Option "VertScrollDelta" "-1"
            Option "HorizScrollDelta" "-1"
            Option "DialDelta" "-1"
    EndSection
  5. Save the file and reboot

Now you should have system-wide natural scrolling.