Chris Jean's Blog

Linux, WordPress, programming, anime, and other stuff.
twitter
rss
Feb
13

Navigate in Ubuntu Nautilus Using the Mouse Back/Forward Buttons

Categories : Linux, Tips 'n Tricks
Navigate in Ubuntu Nautilus Using the Mouse Back/Forward Buttons

I’m used to my back and forward buttons on my mice being able to move backwards and forwards through file browsers. However, this function doesn’t work in Nautilus for Gnome, which is the default file browser for Ubuntu. Naturally, I started to dig into the problem.

I found out that I’m not the only one who is irritated by the lack of back/forward navigation via the mouse. On the Ubuntu Brainstorm site where people share ideas on how to improve Ubuntu, there is an idea topic and three duplicate topics all talking about adding this feature.

I have also discovered that there is a way to add this functionality. It isn’t pretty, but it does work.

Solution Basics

The solution is quite simple. Just like Firefox and many other applications, Nautilus has keyboard shortcuts that can be used to navigate backwards and forward through your directory path navigation. You can use Alt+Left to go back and Alt+Right to go forward.

The solution is to add software that can listen for the mouse buttons and send the corresponding keystrokes when a button is pressed.

Installing Required Packages

To add this functionality, we’re going to use xvkbd and xbindkeys. xbindkeys is a program that can be configured to run commands when certain key events are seen. xvkbd is a command line program that can emulate key presses. Combining the two gives us the functionality we are looking for.

To install the packages in Ubuntu (or other APT-based distros such as Linux Mint, Debian, etc), simply run the following command in Terminal (Applications > Accessories > Terminal):

sudo apt-get install xvkbd xbindkeys x11-utils

Note: In Ubuntu versions before 9.04 (Jaunty Jackalope), the x11-utils package needs to be swapped for xev.

The xev program provided by the x11-utils package will be used in the next step to find out your individual mouse button codes for use later.

If the packages install successfully, you’re ready for the next step. If you get errors, leave a comment with the errors you received, and I’ll see if I can help you out.

Finding the Mouse Button Codes

Each mouse button has a specific code. This code will vary based upon the model of mouse you have and how many buttons it has.

Load up Terminal and run the following command:

xev | grep ', button'

This will run the xev program which will pop up a window with a little box in it. Since xev outputs large amounts of data when the mouse interacts with the window, I filtered the output through grep to only show the specific lines that we are interested in.

Hover your mouse over this new window and press the mouse button to be mapped to back and then the one to be mapped to forward. If you can see your Terminal while you do this, you should see output being generated.

When I ran this on my system with a Logitech MX518, the following output was generated:

state 0x10, button 8, same_screen YES
state 0x10, button 8, same_screen YES
state 0x10, button 9, same_screen YES
state 0x10, button 9, same_screen YES

Close the window to stop xev and return control to the command line.

Notice that each button press caused two lines to be output. One line is for the event caused when the button was pressed down and the other event is when you released the button.

As can be clearly seen, my back button is button 8 and my forward button is button 9.

Configuring xbindkeys

Back in terminal, we need to create a new file to configuration xbindkeys.

gedit ~/.xbindkeysrc

This will load up Gedit to add content to the new file. This file needs to contain the following:

"/usr/bin/xvkbd -xsendevent -text "\[Alt_L]\[Left]""
  m:0x0 + b:8
"/usr/bin/xvkbd -xsendevent -text "\[Alt_L]\[Right]""
  m:0x0 + b:9

Notice the “b:8″ and “b:9″ portions of the text. This is where I configure my mouse buttons. So, if your mouse buttons are 6 and 7, then you need to change “b:8″ and “b:9″ to “b:6″ and “b:7″, respectively.

Save the document and close out Gedit.

Testing

Back in Terminal, run the following command:

xbindkeys

This command won’t produce any output, so having a new prompt as the only reply is normal.

After running the command, load up Nautilus, browse around some directories, and try out the back and forward keys.

If the buttons work properly, go to the next section.

If they don’t work, go back to the “Finding the Mouse Button Codes” and make sure you got the right codes. Also make sure that you copied and used the supplied configuration exactly as it is while only modifying the button numbers to match your’s.

Running xbindkeys at Startup

Now we just need to tell Gnome to run this program each time we start a new session.

Load up the Gnome Sessions Preferences window (System > Preferences > Sessions) (Note: In 9.04+ (Jaunty Jackalope), Sessions is now Startup Applications). Click the Add button. Give the program a name; I simply called mine “xbindkeys” so that I wouldn’t confuse it with anything else. “xbindkeys” (without quotes of course) needs to be entered in the Command field. The Comment field is optional and is mainly helpful for reminding you what the command does. Click the Add button to save the new Startup Program.

At this point, it’s a good idea to make sure that everything works. Log out or reboot your system and ensure that everything works properly when you load back into your user session.

Conclusion

This change will work for any application that uses the Alt+Left/Alt+Right key combinations to navigate back and forth through the navigation history, such as Epiphany or Konqueror.

I hope that the developers add native support for this feature in the future, since not having it is very unpleasant. Plus, the solution is somewhat difficult and more or less a hack rather than a proper solution.

In addition to the forward/back issue, I’d like to see Nautilus support scrolling a view left/right with the standard mouse wheel when there is a horizontal scrollbar but not a vertical one. I found some discussion about this that dates back quite a while, so it’s anyone’s guess when the feature might be implemented. Again, not having this functionality can create an odd feeling when a user is accustomed to most applications doing this by design.

Tags: , , , , ,

Related Posts

Receive Updates

New posts on chrisjean.com delivered directly to your email.

Email:

38 Comments

  • Thomas McNicholas says:

    Hi Chris,
    Finding this document has really made my day, I was seriously miss not being able to navigate nautilus with my mouse back and forward buttons so I’m looking forward to finding the time to implement your settings on my own system.
    Regards
    Tom

  • Dmitriy says:

    Hi, Chris.
    This worked for me too! Thank you for your solution very much!!
    Regards, Dmitriy.
    p.s. sorry for my english…

  • Jeff Powers says:

    Alot of great comments and tips here!I can really learn alot from these suggestions and hope that i can contribute as well.keep up the good work

  • ralph says:

    wow thanks this was a problem for many years for me now, this works ;) Why is this not a default setting? inside KDE and gnome.

    • gaarai says:

      I agree that it should work by default. I’ve found a number of suggestions made for the different file managers that it should be enabled by default, but it has yet to be approved or implemented.

  • Anonymous says:

    Thanks! :)

  • MastroPino says:

    Thanks mate, fast and perfect tutorial. My G5, with some tweak to ur cfg, now works perfect! :)

  • robbie says:

    very easy to follow very precise thank you…

  • MastroPino says:

    Hello mate, I have got a problem in my fresh installation of Ubi9.04, I can’t use thumb button and xev can’t see it :o

    this is my xorg

    Section “InputDevice”
    Identifier “Logitech G5″
    Driver “evdev”
    Option “CorePointer”
    Option “Device” “/dev/input/by-id/usb-Logitech_USB_Gaming_Mouse-event-mouse”
    Option “ZAxisMapping” “invert”
    Option “Emulate3Buttons” “false”
    Option “Buttons” “12″
    Option “Resolution” “800″
    EndSection

    do u have any idea?

    • gaarai says:

      Hello again Mastro. :) Sorry to hear that you’re having problems.

      It’s been a while since I’ve dug around in xorg.conf stuff, and I’ve yet to encounter a situation where xev didn’t read a key. Do all the other buttons show up in xev properly?

      Also, automatic configuration of xorg is really good these days. Have you tried creating a backup of your current xorg.conf, removing the entire “Input Device” section from the file, and rebooting to see if everything is auto-detected correctly? You never know, it may “just work” if you rip that out.

  • MastroPino says:

    I jst try to reset xorg and nothing happen! xev can see all button, with or without my xorg, except the thumb one :(

  • Happy navigator says:

    Thankyou for this great guide, i have tried many in the past and all have failed. This was my major gripe with linux but thanks to your help i can use the mouse the way i want and it also works on opera browser :)

    Thanx again.

  • MastroPino says:

    Hey mate, I just reinstall all and everything is now ok =)

  • MastroPino says:

    I just reformatted and it don’r work again… sometime I hate linux!
    The only different between this os and the other one (where it worked) is the filesystem. Where it work was Ext4 and now is Ext3…

    I can’t understand… :(

  • Ry says:

    Man thank you so much. Very well explained and written up. The only thing that might need updating is that xev is apart of x11-utils now so apt-get doesn’t recognise xev. But it was really easy for me because we have the exact same mouse I didn’t have to change anything. Anywho kudos and bookmarked.

    • gaarai says:

      Not a problem Ry. I had a note under the apt-get install command noting the change in 9.04, but I went ahead and swapped the package and note around to have the command 9.04+ centric while having a note about pre-9.04. Thanks for the heads-up.

  • rotwang says:

    This bugged me for a while, and I just decided to see what I could do about it. Thanks so much so this- worked perfectly. My buttons were even 8 & 9.

  • ajgreeny says:

    Thanks so much for this tutorial on mouse navigation setup, which I dropped into just by accident.

    My mouse is not even a Logitech but an old Trust Ami Mouse Dual Scroll, with two side buttons. In Firefox they have worked for backwards/forwards for a couple of Ubuntu versions, but not in nautilus. Now the buttons work in nautilus, konqueror, dolphin, and perhaps all the other apps that need a backwards/forwards navigation.

    Terrific!!!

  • fox says:

    Please make a bug report, and post this patch to the bug, so Ubuntu (and others) can add this to the distribution. It’s so strange that it is not at the moment.

    • gaarai says:

      The steps I’ve taken here isn’t something that could easily be patched in since it is using specific mouse inputs that may not work for all mice. The problem is that software, such as Nautilus, has not yet implemented some of the features I talk about in my post. There are plenty of feature requests on both the Ubuntu and Nautilus bug trackers that are asking for these features to be added. Some of the requests go back years. Since this is the case and I don’t have the ability to code an actual solution that could be a patch, the best I could do was offer this hacky solution.

  • fox says:

    to bad…. Why can nobody of kde or Gnome take the time to code this :(

    O well thanks for the quick reply.

  • Wow thanks!
    This tutorial was really easy to follow
    worked for me, well written and easily understood
    many thanks!

  • Trausti says:

    Great instructions,
    thank you very much

  • Martin says:

    This worked for me, Linux Mint 7, no problems:) Thank you very much for a good tutorial. It was much appreciated.

  • Shane says:

    Awesome how to!!! Very nice little fix.

    Shane

Leave a Reply