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.
Did I help you?
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
I’m glad that I could make your day Tom. 🙂
Please let me know if the solution works for you.
Hi Chris, Your solution worked for me too, so thank you for the information.
Tom
Thanks for the feedback Thomas. I’m glad that it worked for you. 🙂
Hi, Chris.
This worked for me too! Thank you for your solution very much!!
Regards, Dmitriy.
p.s. sorry for my english…
You’re welcome Dmitriy.
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
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.
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.
Thanks! 🙂
Thanks mate, fast and perfect tutorial. My G5, with some tweak to ur cfg, now works perfect! 🙂
Happy to help Mastro.
very easy to follow very precise thank you…
You’re welcome robbie.
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 😮
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?
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.
I jst try to reset xorg and nothing happen! xev can see all button, with or without my xorg, except the thumb one 🙁
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.
Glad to help Happy.
Hey mate, I just reinstall all and everything is now ok =)
I have to say that I was completely stumped, and nothing I read led me to a potential solution.
I’m glad that you got it sorted. 🙂
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… 🙁
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.
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.
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.
You’re welcome rotwang. Happy mouse navigating. 🙂
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!!!
Glad to help ajgreeny.
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.
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.
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!
Glad to help Nicholas.
Great instructions,
thank you very much
You’re welcome Trausti.
This worked for me, Linux Mint 7, no problems:) Thank you very much for a good tutorial. It was much appreciated.
Glad to do it Martin.
Awesome how to!!! Very nice little fix.
Shane
I also would like to say that this is a very helpful article and this should indeed actually be a default feature in Nautilus.
A great writeup, gave me a new hope for being a complete tuxer someday =)
Thank you for the guide.
Been bugging me since I installed a few weeks ago, slowly getting everything transferred to linux… Games are the only thing I have a windows partition anymore. ;D
Thanks for the howto!
Done and Done.
[…] After a bit of searching I found a great guide here. […]
hello … i just installed Kubuntu a few days ago. Then I found that the mouse does not work well. Your instructions really great. although i get the error when the code is not showing when I click my / rev buttons. I ignore and continue with your key bindings. I think it does not work. but then when I restart my PC and navigate using the dolphin without me realizing it work. thank you
p / s: – google translate;)
Thanks for this useful post, Chris. There’s just one problem with this method. Before binding the back and forward buttons to keystrokes, they used to send events to the window under the mouse cursor (like the mouse wheel). Now events are always sent to the focused window.
This is really bugging me, as I often have some small windows (like the calculator or a terminal) open over a fullscreen browser window. I used to be able to navigate back and forward in the browser while keeping focus on the small windows. This is not possible any more after applying this fix. Every time you wish to go back or forward in the browser, you need to first focus its window, hiding the smaller windows behind it.
Do you happen to have a solution for this problem? Something like making xvkbd send the keystrokes to the window under the mouse cursor instead of the focused window.
To my knowledge, there isn’t a way to make this work.
xvkbd
has an argument that allows you to target a specific window. This means that all that is needed to make this an ideal solution is to have something that can tell the script the ID of the window that the mouse is currently over.xwininfo
is a good tool to use to get information about a window, but it is limited in that it requires the window to be clicked on in order to get the details. So, a different solution is required.wininfo
shows the full details of any window you put your mouse over, but it is a GUI application and not a command-line tool (at least, I can’t find any command-line access for it). This means that it can’t work either.To my knowledge there isn’t a program that command-line access to getting details of the window that the mouse is over without requiring some additional interaction by the user.
I’ve come to a similar conclusion myself. Thanks for taking the time to investigate anyway.
Thank you for this. I know it’s an old thread, but I wanted to report that following your instructions in Linux Mint 15 and with my Microsoft Intellimouse Optical USB ancient mouse, the side “back” and “forward” keys now work within Dolphin and several other apps that were frustrating me.
Much appreciated!
Cheers!
Thanks a lot, worked like a charm!
Excellent. I was messing with xbindkeys mapping button 8 to the “go up” command in Krusader. It worked but then I was disappointed to see that button 8 didn’t work in Firefox unless I killed xbindkeys. I stumbled upon your post and you nailed it. So simple and so well thought out. Since all apps, AFAIK, use Alt + left to navigate back this shouldn’t break existing functionality like my hack did.
Kudos to you and thank you very much!!!!
I’m glad that it worked for you kirm.
after hours of searching, i finally searched on exactly what I was wanting, forward/back remap, (should have done that sooner), and your code works perfectly. I remapped 8,9 to Home/End. Thank you!
Glad to help.