Xorg and 5-button mice
From TLUGWiki
Right, so everyone has seen how Edwin made more than one mouse work. Everyone has managed to get three button+scroller button mice working. Now, I've finally managed to get my 5-button mouse with a scroller working in a sensible manner. What one needs to do is notify that one has 5 buttons, but the imps/2 protocol doesn't support more than 5 buttons (and we would like to have 7 since the scroller counts as two). Luckily there is an improved protocol called ExplorerPS/2. Thus after updating my xorg.conf the mouse section looks as follows:
Section "InputDevice"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "ExplorerPS/2"
Option "Device" "/dev/mouse"
Option "Buttons" "7"
Option "ZAxisMapping" "6 7"
EndSection
Yea, I know this seems weird, I'm saying 5 buttons yet I spec 7. This is because the scroller also counts as two buttons. Right, the ZAxisMapping differs from the usual "4 5", this is because the two side buttons now takes up 4 5 and you can't map those (well, at least not in xorg.conf) and and we need to uniquely identify these buttons.
In Edwin's mighty mouse he uses /dev/input/mice. /dev/mouse is a symlink to /dev/psaux to /dev/misc/psaux. This is in fact the same device as /dev/input/mice (I've been doing a little too much rtfs'ing in the kernel sources). Either one of the two will work.
At this point in time you should note that things are a bit wacked. Specifically the side buttons act as if they are the scroller and the wheel acts as if it a horisontal scroller (or forward and back in mozilla - ask Edwin about his anoyances with synaptics which has horisontal scroll).
Right to fix that we need to do a bit of remapping of the buttons. So how do we do that? Well, xmodmap to the rescue again. So we remap things a bit, specifically we need to alter the pointer mapping. We can do this by creating a file containing:
pointer = 1 2 3 6 7 4 5
Which is what I'm using at the moment. This effectively swaps buttons 4 and 6, and 5 and 7. This takes the wheel back to being a vertical scroller and the buttons on the sides to being a horisontal "wheel", although they really are only buttons.
If you don't want the "scrolling" effect then you can also replace the 6 and 7 with 8 and 9 which will then register as buttons 8 and 9 to applications. The disadvantage with this is that I'm not aware of any applications that really knows how to configure buttons to do weird things (You could take a look at [1]).
This last also allows you to for example make the thumb button the middle button by mapping it to button two, and the middle button to be something else, for example:
pointer = 1 6 3 2 7 4 5
will let the left and right buttons register as usual, the thumb button will register as event 2 (middle button), the middle button will act like "scroll left"/back (mozilla), the little finger button will act like "scroll right"/forward (mozilla) and the wheel will act like expected.
Now the question that nags everyone. How do you make this mapping effective? Well a simple
$ xmodmap filename
will do. How do you make this permanent? Simply put this line in /etc/X11/Xmodmap (create it if it doesn't exist). My /etc/X11/Xmodmap now looks like:
pointer = 1 2 3 6 7 4 5 keycode 234=F15 keycode 233=F16 keycode 232=F17 keycode 236=F18 keycode 229=F19 keycode 230=F20 keycode 178=F21 keycode 235=F22 keycode 161=F23 keycode 223=F24
Which sommer includes the keycode mappings for my multimedia keys on my keyboard. I suspect Derick has mentioned it before, you can get those numbers using the xev command.
Note: on some distros /etc/X11/Xmodmap won't automatically be executed when X starts. In this case, you might need to find another way to run "xmodmap /etc/X11/Xmodmap", for example in a .xsession file in your home directory, or in Gnome or KDE startup scripts (e.g. for KDE you can make an executable script in ~/.kde/Autostart to accomplish this).
You can find more information about mouse buttons and config examples in
[1] /usr/share/doc/<your-X-version>/README.mouse; and
[2] http://xorg.freedesktop.org/X11R6.8.0/doc/mouse.html.

