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.
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.
Back in terminal, we need to create a new file to configuration xbindkeys.
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.
Back in Terminal, run the following command:
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.
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.