Set up two mice on login
ANOTHER UPDATE: bizarre! When I first power-up and log in the script either doesn't fire or just doesn't work. If I log out and back in - it does! WTF?
UPDATE: this is an annoyingly difficult thing to nail down, but I think I've got it now.
I wrote a script called mice and put it in my path at: /usr/local/bin/mice
Then, I add it to my startup applications pref panel like this:
sh -c '/usr/local/bin/mice'
And it seems to work.
Here's the script I wrote
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/bash
# get ID and current set up for each input device
emID=`xinput list|grep 'Kensington Kensington Expert Mouse'|cut -d "[" -f1|grep -o [0-9].`
stID=`xinput list|grep 'Kensington Kensington Slimblade Trackball'|cut -d "[" -f1|grep -o [0-9].`
emButtonMap=`xinput --get-button-map 'Kensington Kensington Expert Mouse'`
stButtonMap=`xinput --get-button-map 'Kensington Kensington Slimblade Trackball'`
emAccel=`xinput --list-props 'Kensington Kensington Expert Mouse'|grep 'Constant'|tr "\t" "|"|cut -d "|" -f3`
stAccel=`xinput --list-props 'Kensington Kensington Slimblade Trackball'|grep 'Constant'|tr "\t" "|"|cut -d "|" -f3`
emBMap="3 2 1 5 4 6 7 8 9 10 11 12"
stBMap="1 8 3 4 5 6 7 2 9 10 11 12"
emDACD="3.000000"
stDACD="3.000000"
# check current settings against desired setup and change if necessary
if [ "$emButtonMap" != "$emBMap" ]; then
xinput --set-button-map $emID $emBMap
emBmapCurr=`xinput --get-button-map 'Kensington Kensington Expert Mouse'`
tsEm=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$tsEm] set Expert Mouse (device ID: $emID) button map to $emBMapCurr">> /home/gregster/.hcmc/mice.log
fi
if [ "$stButtonMap" != "$stBMap" ]; then
xinput --set-button-map $stID $stBMap
stBMapCurr=`xinput --get-button-map 'Kensington Kensington Slimblade Trackball'`
tsSt=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$tsSt] set Slimblade Trackball (device ID: $stID) button map to $stBMapCurr" >> /home/gregster/.hcmc/mice.log
fi
if [ "$emAccel" != "$emDACD" ]; then
xinput --set-prop $emID 'Device Accel Constant Deceleration' 3
emDACDCurr=`xinput --list-props 'Kensington Kensington Expert Mouse'|grep 'Constant'|tr "\t" "|"|cut -d "|" -f3`
tsEmAc=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$tsEmAc] set Expert Mouse (device ID: $emID) acceleration to $emDACDCurr" >> /home/gregster/.hcmc/mice.log
fi
if [ "$stAccel" != "$stDACD" ]; then
xinput --set-prop $stID 'Device Accel Constant Deceleration' 3
stDACDCurr=`xinput --list-props 'Kensington Kensington Slimblade Trackball'|grep 'Constant'|tr "\t" "|"|cut -d "|" -f3`
tsStAc=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$tsStAc] set Slimblade Trackball (device ID: $stID) acceleration to $stDACDCurr" >> /home/gregster/.hcmc/mice.log
fi
exit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In order to get my two trackballs working as I like (one left-handed, one right-handed) I tried a few ways but ended up going with adding instructions to the System > Preferences > Startup applications applet. (BTW, this adds .desktop files to ~/.config/autostart/ directory).
The trick is to get your syntax just right. Running something at the terminal is not simply duplicated in the Startup applications applet. I ended up creating one startup app for each instruction (doing many in one eluded me). This is what I put in the "command" field for each one (that is, each of the following lines is the meat of one startup app):
sh -c "xinput --set-prop 'Kensington Kensington Expert Mouse' 'Device Accel Constant Deceleration' 4"
sh -c 'xinput --set-button-map 'Kensington Kensington Expert Mouse' 3 2 1 5 4 6 7 8'
sh -c "xinput --set-prop 'Kensington Kensington Slimblade Trackball' 'Device Accel Constant Deceleration' 4"
sh -c 'xinput --set-button-map 'Kensington Kensington Slimblade Trackball' 1 8 3 4 5 6 7 2'
You have to use an invocation like sh to get it to run, and sh needs the -c flag to know that it's operating the stuff after it outside of the context of standard input (ie. running it directly from the CLI). Also, strings with spaces (e.g. Device Accel Constant Deceleration) need to be enclosed in SINGLE-QUOTES. Standard practice seems to put the entire command following sh -c in single-quotes, but in this case I use double-quotes to avoid painful escaping.
So, one of my .desktop files looks like this:
[Desktop Entry]
Type=Application
Exec=sh -c "xinput --set-prop 'Kensington Kensington Expert Mouse' 'Device Accel Constant Deceleration' 4"
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_CA]=Add accel for ExpertMouse
Name=Add trackball configs
Comment[en_CA]=accel for ExpertMouse
Comment=eccel for ExpertMouse
NOTE: unfortunately, this does not work all the time. Re-investigating.
UPDATE: this is ridiculously hard. It looks like even if I put the commands in my .profile something else resets the button-mapping. I'm going to try udev again. Of course, the problem I see with this actually working is that it's a system level adjustment, and it *should* be per-user.
Anyway, here's the way I'm proceeding:
1) Gather info on the device by running this:
udevadm info -a -p $(udevadm info -q path -n /dev/input/by-id/usb-Kensington_Kensington_Slimblade_Trackball-mouse)
2) Unplugging/plugging a mouse while tailing the Xorg log gets this output:
[ 28709.701] (II) config/udev: removing device Kensington Kensington Expert Mouse
[ 28709.702] (II) Kensington Kensington Expert Mouse: Close
[ 28709.702] (II) UnloadModule: "evdev"
[ 28717.858] (II) config/udev: Adding input device Kensington Kensington Expert Mouse (/dev/input/mouse0)
[ 28717.859] (II) No input driver/identifier specified (ignoring)
[ 28717.859] (II) config/udev: Adding input device Kensington Kensington Expert Mouse (/dev/input/event2)
[ 28717.859] (**) Kensington Kensington Expert Mouse: Applying InputClass "evdev pointer catchall"
[ 28717.859] (**) Kensington Kensington Expert Mouse: always reports core events
[ 28717.859] (**) Kensington Kensington Expert Mouse: Device: "/dev/input/event2"
[ 28717.880] (II) Kensington Kensington Expert Mouse: Found 8 mouse buttons
[ 28717.880] (II) Kensington Kensington Expert Mouse: Found scroll wheel(s)
[ 28717.880] (II) Kensington Kensington Expert Mouse: Found relative axes
[ 28717.880] (II) Kensington Kensington Expert Mouse: Found x and y relative axes
[ 28717.880] (II) Kensington Kensington Expert Mouse: Configuring as mouse
[ 28717.880] (**) Kensington Kensington Expert Mouse: YAxisMapping: buttons 4 and 5
[ 28717.880] (**) Kensington Kensington Expert Mouse: EmulateWheelButton: 4, EmulateWheelInertia: 10, EmulateWheelTimeout: 200
[ 28717.881] (II) XINPUT: Adding extended input device "Kensington Kensington Expert Mouse" (type: MOUSE)
[ 28717.881] (II) Kensington Kensington Expert Mouse: initialized for relative axes.
Some links I've been using:
http://reactivated.net/writing_udev_rules.html
https://wiki.ubuntu.com/X/Config/Input
https://wiki.kubuntu.org/X/InputConfiguration