Primary button goes back to default on external mouse
Solution 1:
I use a KVM switcher box and so I have the same issue every time I switch since upgrading.
At the moment I have this quick and dirty script. Run it in a terminal as the logged in user;
xinput list | grep Mouse | sed -nre 's/^.*\sid=([0-9]+)\s.*$/\1/p' | xargs -r -I '{}' echo xinput set-button-map {} 3 2 1
Hope to get something better but should be useful for now.
For completeness, it's worth noting that you can also use the mouse settings UI tool, and change the primary button to right handed and then back to left handed.
UPDATE/EDIT BELOW
I now have a more convenient solution that is automated for each kvm switch, but it's still a hacky/dirty solution, and I run a script after login...
Customise the following for your vendor id and product id, based on output of lsusb
. Where the hex number with a colon in the middle is the {idvendor}:{idproduct} for your mouse. Also, as flipjacob adds, customise "Mouse" string in the grep statement to your match what you get from xinput
.
Create a file (as root) /etc/udev/rules.d/80-force-left-handed-mouse-on-plugin-event.rules
with the following contents
ATTRS{idVendor}=="045e", ATTRS{idProduct}=="0047", ACTION=="bind", RUN+="/root/notify-mouse-plugged.sh"
Create the script that it will run (as root) /root/notify-mouse-plugged.sh
.
#!/bin/bash
umask 0000
echo $ACTION >> /tmp/mouse-flag
date >> /tmp/mouse-flag
And finally create the script to pick up the 'notification' in the context of the logged in user. I run this after logging in in a terminal and leave it running there.
Listener script $HOME/listen-for-mouse-plugged.sh
.
#!/bin/bash
echo "" > /tmp/mouse-flag
tail -qfn 0 /tmp/mouse-flag 2>/dev/null | while read s
do
#inotifywait -e create /tmp/mouse-flag
echo reset mouse $s
xinput list | grep Mouse | sed -nre 's/^.*\sid=([0-9]+)\s.*$/\1/p' | xargs -I '{}' xinput set-button-map {} 3 2 1
#sleep 5
done
It fires the listener loop 3 times for me, but that is of little consequence for something I hope to throw away soon.
Solution 2:
I had the same issue and after much searching, this worked for me: Open Startup Applications Preferences and Add the following command
xmodmap -e "pointer = 3 2 1"
This worked immediately and persists after a re-start, and persists when the bluetooth mouse re-awakens from inactivity.
Running 20.10 - hope this bug gets fixed soon.