This was kind of a pain in the neck, so I'm collecting my experiences into
one Googleable post for the sake of the next person.
I just bought a Microsoft Trackball Optical for use with my Debian/unstable
system. Installation was a breeze - I just plugged it in to the USB port
and it instantly worked, scroll wheel and all. However, my particular
model had two extra narrow buttons on the left and right outside edges. By
default they were set to emulate a middle-click and right-click (left and
right "extra" buttons respectively). Since that was hardly useful I
decided to put them to better use.
*** Step 1: Configuring X
I slightly modified the "mouse" section of /etc/X11/XF86Config by changing
the "Protocol" from "Auto" to "ExplorerPS/2", disabled "Emulate3Buttons",
and set the number of "Buttons" to "7":
Section "InputDevice"
Identifier "Microsoft Trackball Optical"
Driver "mouse"
Option "CorePointer"
Option "Device" "/dev/input/mice"
Option "Protocol" "ExplorerPS/2"
Option "Buttons" "7"
Option "ZAxisMapping" "6 7"
Option "Emulate3Buttons" "no"
EndSection
*** Step 2: Configuring Xmodmap
By setting the number of buttons to 7 in XF86Config, the up and down scroll
wheel movements got bumped from buttons 4 and 5 to buttons 6 and 7.
However, almost all X apps expect them to be on 4 and 5. I
created /etc/X11/Xmodmap with the contents below to reorder the mouse
button numbers so that the scroll wheel once again controls 4 and 5, and 6
and 7 are mapped to the "extra" buttons.
$ cat /etc/X11/Xmodmap
! Re-order the mouse buttons
pointer = 1 2 3 6 7 4 5
Note that I haven't explicitly loaded the new mapping yet; that comes in the
next step.
*** Step 3: Configuring imwheel
Now that X sent the appropriate events in response to button presses, I
wanted to make them actually do something. The easiest (only?) way I know
of is with the program "imwheel", which intercepts mouse button press
events and replaces them with configurable keyboard events.
First, I ran "apt-get install imwheel".
Second, I made my own personal ~/.imwheelrc configuration file. I could
have just as easily used (or edited) the
systemwide /etc/X11/imwheel/imwheelrc file, but I wanted to keep my
modifications to myself to avoid confusing the heck out of anyone else who
happened to be using my machine.
The syntax of this file was a little confusing at first, but it's really
pretty simple. The first line of each section is a regular expression to
match the title of the window that the mouse is in when you press a button
(so that you can send different keystroke combinations to each
application). Following is a series of lines mapping a keyboard modifier
plus mouse button combination to a series of keystrokes. In my config
file, "None" means that I'm not required to hold down any key while
pressing the mouse buttons. This way, you can easily specify one action if
the shift key is pressed, another for the control key, etc. The second
field is the name of the button press to match. "Up" corresponds to the
left outer button, and "Down" matches the right outer button. The final
field is the keypress combination to send.
My file currently looks like this:
$ cat ~/.imwheelrc
"^konsole$"
None, Up, Shift_L|Left
None, Down, Shift_L|Right
"^konqueror$"
None, Up, Control_L|Page_Up
None, Down, Control_L|Page_Down
"^Firefox-bin$"
None, Up, Control_L|Page_Up
None, Down, Control_L|Page_Down
In other words, if my mouse is over a window with the internal name of
"konsole", and I'm not holding down any modifier key on the keyboard, and I
click the left outer mouse button, then imwheel sends shift+left to the
window. This corresponds to "Go To Previous Session" in my Konsole
shortcuts, and acts as expected. The other definitions are variations on
the same theme.
To see what a window is called, I ran 'imwheel -D -d -k -b "67"' to kill the
currently running imwheel daemon, dump debugging information to stdout, and
only intercept buttons 6 and 7. Then I went to the interesting window,
clicked either of the right or left outer buttons, and read the debug
output to see what the name of that window was.
*** Step 4: Running it all at login
I edited /etc/X11/imwheel/startup.conf to change the lines:
IMWHEEL_START=0
#IMWHEEL_PARAMS="-b "67""
to:
IMWHEEL_START=1
IMWHEEL_PARAMS="-b "67""
Then, I made a symlink from /usr/share/doc/imwheel/61imwheel_load-xmodmap
into /etc/X11/Xsession.d (the imwheel packages doesn't install it by
default). Now, whenever any user logs in, the session manager launched
imwheel with that users ~/.imwheelrc (or /etc/X11/imwheel/imwheelrc if they
don't have one). Then, it loads the /etc/X11/Xmodmap file I defined in
step 2. You can also execute the scripts in /etc/X11/Xsession.d manually
if you're already logged in and you want to make sure that they work as
expected.
*** Step 5: Profit!
Now I enjoy the use of those extra little buttons that I'd otherwise be
ignoring. In Firefox and Konqueror, they quickly switch between open tabs.
In Konsole, they flip between running sessions. I'm only owned the
trackball for about two hours total at this point so I imagine I'll find
more uses for them as I get used to it.
So, in recap, I made a small edit to XF86Config. Then I created config
files for xmodmap and imwheel. Finally, made sure that both of those
commands are run at login so that my mouse settings are always available.
Although each step turned out to be pretty easy and logical, they weren't
terribly obvious to me at first. I thought I'd save others the aggravation
by sharing the steps that worked for me. In a nutshell, if you're
considering a multi-button mouse or trackball but don't know if you could
use all of the extra buttons, the answer is probably "yes". For my
Microsoft Trackball Optical, that's definitely true.
Enjoy!
--
Kirk Strauser
Attachment:
pgpeJHasaqaTy.pgp
Description: signature