Fixing natural scrolling in Ubuntu 12.04

I recently “upgraded” my HP laptop from Fedora 16 to Ubuntu 12.04 and, as I always do, tried to set up natural scrolling on it. Obviously, I had to run into a problem – in this case, the new “smooth scrolling” implementation Ubuntu uses.

Smooth scrolling was introduced in GTK 3.4, which a few things (like the file manager) use now. However, it doesn’t rely on the standard “button”-based scrolling standard (you roll the scroll wheel a bit, the mouse sends it as a button press), but on a more precise reporting of scroll distance that some touchpads provide. Only Synaptics touchpads are supported for now, I think.

Anyway, my previous natural scrolling method hacks into the “normal” scrolling method, and not the one used by GTK 3.4, so a new approach is needed. Enter xinput.

$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜   ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad id=11 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
    (...)

$ xinput list-props 11 | grep "Scrolling Distance"
    Synaptics Scrolling Distance (288): 106, 106
    Synaptics Circular Scrolling Distance (301): 0.100000

So, what did I do there? The first step is, obviously, to open a terminal window so you can copy-paste those things. With Unity, just hit the Super/Windows key, type “terminal” and hit Enter.

Then you’ll have to copy-paste the first command, xinput list, and hit Enter. Two notes I want to make here, for terminal newbies: firstly, don’t copy the $ – that represents the prompt you should already have on your screen. Secondly, paste using the right click menu in a terminal, not Ctrl-V.

Look around the listing for your Synaptics touchpad – I’ve put mine in italics. If you don’t find one, smooth scrolling should be off, and you should be able to use these instructions to set natural scrolling up. If you do find one, make a note of its ID (in my case, it was 11).

Next, you’ll have to run the second command, xinput list-props 11 | grep "Scrolling Distance", replacing the 11 in italics with the ID you found in the previous step. Another note for terminal newbies: use the arrow keys to move through the pasted command. You should get one or two lines as a reply – make a note of the number in parentheses next to “Synaptics Scrolling Distance” – mine was 288 – and the previous values – mine were both 106.

Next up, open the file manager and create a new empty file somewhere (I have it in my ~/Scripts directory). Call it, say, NaturalScrolling.sh. Open it up in gedit and copy-paste this in it, replacing the italicized properties with the numbers you found in the previous steps:

#!/bin/sh
xinput set-prop 11 288 -106 -106
nautilus -q
nautilus -n &

(The last two lines quit the file manager, and then restart it in desktop-only mode, which should work around all possible related bugs.)

Save it, right click it in the file manager, go to the Permissions tab and check “Allow this file to be executed” (or something along those lines – I’m not on my Ubuntu machine). This script will set the new scrolling distance properties (which are basically the negatives of the previous ones) and restart the file manager.

Now, we need to set this to run on boot. Thankfully, Ubuntu makes that easy – just go to the system menu in the top right corner, click “Startup Applications”, click the “Add” button, give the entry a name (say, “Natural Scrolling”) and browse to wherever you saved the script.

Next, reboot and enjoy – it’ll hopefully work now. You could do worse than leave a comment if I helped. Note that this could also work on Fedora 17 and other distros implementing GTK 3.4’s smooth scrolling – no guarantees though, and you’ll have to tweak at least the “run on boot” part of the instructions.

If you run into any problems, first make sure you have no .Xmodmap file in your home folder (you could have one if, say, you followed my other natural scrolling setup guide), that your system is up to date (this fix only works with new versions of the Synaptics driver), and reboot again for good measure. If it doesn’t work after that, leave a comment and I’ll try to help you.

The obligatory hat tip goes to “RAOF” from the Ars Technica forums, who seems to be the first to have come up with this fix.

About these ads

31 Comments on “Fixing natural scrolling in Ubuntu 12.04”

  1. rue says:

    Any idea on how to apply this if you’re only using a USB mouse on a desktop PC, without any touchpad?

  2. JP says:

    absolutely genius, thx so much !

  3. WonYong Jung says:

    Thanks for easy and good solution.
    I’m using ubuntu 12.10 on Lenovo G580 and I found that device id and property id changed every login or reboot.
    And it work even if I do not restart nautilus. (usershare error occured)

    So I created simple script to get variable ids.
    In case of Ubuntu 12.10, startup application setting menu is not on top right menu, but on dash -> application -> type “startup” (search “startup”)

    NaturalScrolling.sh
    ————————————————————————-
    #!/bin/sh
    DEV_NO=`xinput list | grep “ETPS/2 Elantech Touchpad” | sed ‘s/.*id=\([0-9]*\).*/\1/g’`
    PROP_NO=`xinput list-props ${DEV_NO} | grep “Synaptics Scrolling Distance” | sed ‘s/.*(\([0-9]*\)).*/\1/g’`
    xinput set-prop ${DEV_NO} ${PROP_NO} -106 -106
    ————————————————————————-

  4. Hi,
    I just started in a new office today where they run Ubuntu 12.04. I am not very familiar with Ubuntu (was using openSUSE and Mac OSX before), but I guess it is the Unity GUI, not Gnome…However, the .Xmodmap solution worked for me, except for the file browser (is it also this nautilus in Unity?) and gedit. I tried your solution to invert my mouse wheel

    #!/bin/sh
    xinput set-prop 9 279 0, 0, 5, 4
    nautilus -q
    nautilus -n &

    But for some reason I can not execute it. Unfortunately our system administrator won’t return before Friday, but I am curious what this message means:

    ponto:~/Scripts> sh NaturalScrolling.sh
    Initializing nautilus-gdu extension
    Shutting down nautilus-gdu extension
    ponto:~/Scripts> Initializing nautilus-gdu extension
    Nautilus-Share-Message: Called “net usershare info” but it failed: ‘net usershare’ returned error 255: net usershare: cannot open usershare directory /var/lib/samba/usershares. Error No such file or directory
    Please ask your system administrator to enable user sharing.

    I hope someone can provide me with a little bit of insight.

  5. [...] Andy C. found the definitive solution which completely avoided the xmodmap quirk. Great! It’s a little « manual » each person must dive into xinput to find their own numbers and values, but that’s not a real problem. BTW, my solution is this one, for my MacbookAir3,2: [...]

  6. [...] you’re trying, like me, to enable “natural scrolling” on Ubuntu 12.04 with a synaptics touchpad (I happen to be running on a 2010 macbook laptop), do this. I tried a few [...]

  7. EpixStudios says:

    [...] This caused the old method to break, but now we have a much better method. I won’t repeat the process but you can read how to set it up at Andy C.’s Blog. [...]

  8. JFYK, to open a terminal window one can type Ctrl+Alt+T

  9. Eliran Malka says:

    Thank you, Andy, for providing an elegant, system wide solution. I ported your solution to askubuntu.com for the benefit of the Ubuntu community, hope you don’t mind (of course, attribution is granted and this post is linked as a source).

  10. noah says:

    For me, everything seemed to work great when I first did it. But after restarting I found that the property id can change each time, so the script had to be modified to take that into account. The device id never changed, though I suppose it could and the script could be modified to take that into consideration. Here is the script that I ended up writing:

    #!/bin/bash
    xinput list-props 11 | awk ‘BEGIN {FS=” “;} /Synaptics Scrolling Distance \([0-9]*\)\:\t[0-9]+, [0-9]+/ {gsub(/(\(|\)|\:)/, “”,$4); gsub(/,/, “”, $5); print $0; print “xinput set-prop 11 ” $4 ” -” $5 ” -” $6;}’ | /bin/bash
    nautilus -q
    nautilus -n &

    • There is a bug in this script. I get this error:

      /home/steven/Scripts/NaturalScrolling.sh: line 2: syntax error near unexpected token `}’
      /home/steven/Scripts/NaturalScrolling.sh: line 2: `xinput list-props 10 | awk ‘BEGIN {FS=” “;} /Synaptics Scrolling Distance \([0-9]*\)\:\t[0-9]+, [0-9]+/ {gsub(/(\(|\)|\:)/, “”,$4); gsub(/,/, “”, $5); print $0; print “xinput set-prop 10 ” $4 ” -” $5 ” -” $6;}’ | /bin/bash’

      Can you please fix this?
      Thanks!!

    • Andy C. says:

      That’s odd. The only time it changed for me was when I plugged in a USB mouse, and even then I recall it reverted after a restart.

  11. noah says:

    Works perfect for the Apple Magic Trackpad! I’ve been looking for this solution for weeks. Thanks!

  12. Etra Adisal says:

    It did work for the Nautilus, but it reversed Google Chrome’s direction. Small, sub-windows (such as the artist selector in Rhythmbox) is also affected too, rendering them “un-natural”.

    Any fix?

    • Etra Adisal says:

      I redone the .Xmodmap solution and it worked out for the Google Chrome.
      As for the sub-window, it seems I’m going to live with that for a moment.

      Thanks for the tip! :-)

  13. [...] 출처는 http://andym3.wordpress.com/2012/05/27/fixing-natural-scrolling-in-ubuntu-12-04/ Posted 6 24 , 2012 Categorized: 분류되지 않음 Tagged: IT, 전체 [...]

  14. Alex says:

    It would be easier to put

    Option “VertScrollDelta” “-106″

    in /usr/share/X11/xorg.conf.d/50-synaptics.conf

  15. Jonathan David says:

    my scroll goes from one end to another without stopping!

    • Andy C. says:

      Well, that didn’t happen for me, but I apparently some others ran into this problem before.
      Run xinput list-props 11 | grep "Coasting", replacing 11 with your device’s id of course, get the “Synaptics Coasting Speed” property’s id (mine was 306), and then run xinput set-prop 11 306 0 0, replacing 11 and 306 with your values. That should fix it.

  16. Jonathan David says:

    doesn’t work for me on my Ubuntu 12.04

  17. Jack says:

    Sry but this doesn’t work for me, I don’t have Synaptic touchpad listed after typing “xinput list”
    I have a MacBookPro and there is this:

    $ xinput list
    ⎡ Virtual core pointer id=2 [master pointer (3)]
    ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
    ⎜ ↳ bcm5974 id=10 [slave pointer (2)]
    ⎜ ↳ Mouseemu virtual mouse id=13 [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)]
    ↳ Power Button id=7 [slave keyboard (3)]
    ↳ Sleep Button id=8 [slave keyboard (3)]
    ↳ Apple, Inc. Apple Internal Keyboard / Trackpad id=9 [slave keyboard (3)]
    ↳ Built-in iSight id=11 [slave keyboard (3)]
    ↳ Mouseemu virtual keyboard id=12 [slave keyboard (3)]

    “Scrolling Distance” is not available in any of them.

    • Andy C. says:

      Macs seem to be… complicated. From what I could gather, they have a Broadcom touchpad, they use a different driver, yet their touchpads are used by X as if they were Synaptics touchpads.
      Hmm… try running xinput list-props 10, see if there’s anything that seems relevant there.

      • Jack says:

        Hey cool, you are right.
        It is there, but following your tutorial afterwards doesn’t chnage anything for me. strange

        Synaptics Click Action (276): 1, 3, 0
        Synaptics Circular Scrolling (277): 0
        Synaptics Circular Scrolling Distance (278): 0.100000
        Synaptics Circular Scrolling Trigger (279): 0

      • Jack says:

        Synaptics Scrolling Distance (265): 235, 235

        • Jack says:

          omg it works, this is the best day of my life. forget what I said. It works!

  18. Thanks a lot! A few notes. 1) The newlines weren’t interpreted correctly when creating the script (not sure if it matters) and 2) The Display directive didn’t work for me. Kept saying it couldn’t find the X server. I removed that portion and it seemed to fix it. Thanks again!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.