Using a mouse with more than 5 buttons

If you have a mouse with more than 5 buttons or with a scroll-wheel and extra buttons, you may have wondered how to set this up with the X-server. This page will go through some of the caveats that you may encounter when trying to solve this issue. I spent hours trying to get the "thumb"-button on my Logitech Cordless MouseMan Wheel behave correctly, while also having the scroll-wheel work. This page was made to save you the trouble of discovering what I found out.

The important issue is that the original Xserver specifications only allows up to five buttons. Most programs issue the same behaviour, although this can be handled by remapping the buttons through the window manager.

First we need to change the Xserver configuration. Make sure you have the following section in /etc/X11/XF86Config-4:
Section "InputDevice"
        Identifier      "Logitech Cordless Mouseman Wheel"
        Driver          "mouse"
        Option          "Device"                "/dev/mouse"
        Option          "Protocol"              "MouseManPlusPS/2"
        Option          "Emulate3Buttons"       "no"
        Option          "Buttons"               "6"
        Option          "ZAxisMapping"          "5 6"
EndSection

You should also edit the ServerLayout section to use the mouse you have defined:

InputDevice "Logitech Cordless Mouseman Wheel" "CorePointer"

Of course the name should reflect whatever you have chosen for the identifier in the InputDevice section.

Now let's take a look at the configuration. /dev/mouse is the device to use. In fact this is a symlink to /dev/psaux, since I use the PS/2-connector for my mouse. The protocol depends on the kind of mouse you have. MouseManPlusPS/2 is the protocol used by Logitech's wheel-mice. If you have a Microsoft mouse, you should propably try IMPS/2 for the IntelliMouse-driver. Then there is the number of buttons. You must select the number of virtual buttons, which includes the scroll-wheel. Since the wheel can normally be pressed, this counts as 3 buttons, and with the left, right and thumb-buttons, we get a total of 6.

The ZAxisMapping is where most people make the mistake of putting "4 5". While this is true under normal circumstances, we will need to use the first non-physical buttons for the Z-axis. Again, with a click on the wheel being button 2, and the thumb button being button 4, the first non-physical button is number 5.

If you restart the X-server now, you should see that all buttons have distinct functions. This can be tested with xev. You will notice, however, that the scroll-wheel does not behave correctly. This is because almost any program expects the mouse-wheel to be buttons 4 and 5. So why did i tell you to assign it to 5 and 6? Well, as I said, there will be a conflict if we use any of the physical buttons (this results in the thumb-button sending the same event as the scroll-wheel, thus making it unusable). To fix this, we turn to xmodmap. Xmodmap handles the various input-events for the mouse and keyboard. To make the mouse-buttons behave correctly, we add the following line to /etc/X11/Xmodmap (if you do not want the configuration to be system-wide, you can edit ~/.xmodmap instead):

pointer = 1 2 3 6 4 5

This will reassign the mouse-buttons. The first three numbers provide the default behaviour for the left, middle (wheel click) and right buttons. If you are left-handed, you may have seen a configuration starting with 3 2 1, which will reverse the left and right mouse buttons. Now, the last three numbers will asign the 4th physical button (e.g. the thumb-button) to the mouse event btn6. The non-physical, but emulated button 5, which is one direction on the scroll-wheel, will be assigned to btn4 event, and the other direction on the scroll-wheel is assigned the btn5-event. All in all, this results in the scroll-wheel generating the expected events 4 and 5, while the thumb-switch will generate an event as the 6th mouse button.

Now, as I said, a lot of programs do not know what the 6th mouse button is supposed to do. In some cases you may be able to get some special behaviour by adding strange commands to some configuration file. For instance putting this in ~/.Xdefaults will make Netscape go back if you press the thumb button:

Netscape*drawingArea.translations:  #replace    \
	<Btn6Down>: xfeDoCommand(back)\n\

Similarly, you can put the line:

(global-set-key [mouse-6] 'yank)

in ~/.emacs to have the thumb-button paste selected test. (OK, maybe this was not the best example, since this is already bound to the middle mouse button).

Unfortunately these configurations work only for a few programs, and you have to set it up manually for each. If you want a global behaviour, you may be able to bind the event in the window managers configuration. If you are using Gnome and Sawfish, this is accomplished through the Gnome Control Center. This can be found either from the Gnome-menu (Programs → Utilities → GNOME Control Center), or by typing gnomecc in a terminal. Now go to "Sawfish Window Manager" and "Shortcuts". Here, the button can be bound to any of the Sawfish-functions. I have not been able to make the "grab"-function work for the 6th mouse button, but since it works for button 1, I simply use this, and then manually edit the input field to read "Button1-Click1". Beware that the window-manager processes the events before the program gets them, so assigning a behaviour here disables any programs that would otherwise get the button 6 event.

I have not been able to find any way of customizing the mouse behaviour of the Galeon web browser (other than the normal left and right button behavoiurs, which are set in the mouse-properties window). If anyone knows how to assign button 6 to go back to the previous page, I'm keen to find out how. Please contact me if you know.

Last updated: 2005.05.28