2

I want to make xinput settings for my usb mouse persist after it has been turned off and on again. How can I monitor this event?

This does not work, as I never unplug the usb receiver: How to make xinput settings persist after devices are unplugged, replugged, and after shutdown, restart, etc?

As far as I've understood, udev can be used for HW detection applications, but it doesn't seem to be able to detect state changes in the device such as a Logitech Unifying Receiver.

I guess the key to get this solved is to successfully track events in the Receiver and write a script to execute the xinput command. Would anyone know how I can detect this event? Solaar is off course able to detect this, but that doesn't mean it is simple for a non-expert Linux user.

Thanks!

  • I have the same problem. When I disconnect the mouse and reconnect it I have to run the xinput command again. I've been looking for a solution for weeks without success. Posted on unix stack exchange, linux mint, and all the answers here don't address this. – David Parks Jan 22 '17 at 20:09
  • What's the exact xinput command you use and the settings you're setting ? I think I can write a script for that purpose – Sergiy Kolodyazhnyy Jan 26 '17 at 7:28
  • I have a Logitech MX Pro Mouse and Logitech K800 backlit keyboard attached to unified receiver and there is no problem turning mouse off/on or keyboard or for that matter unplugging the USB dongle and plugging it back in. No special kernel modules were installed manually, everything simply worked out of the box.What kind of mouse do you have? – WinEunuuchs2Unix Jan 27 '17 at 2:18
  • @WinEunuuchs2Unix did you remap the keys using xinput? Do those key mappings persist across disconnecting the device and reconnecting it? – David Parks Feb 1 '17 at 2:21
0

I solved this issue based on a suggestion that came from another post in unix stack exchange.

In a nutshell I run a background shell script that loops every 2 seconds looking for a change in the mouse, when it find's one it re-runs the xinput command.

The original (and more simple) solution is posted here:

https://unix.stackexchange.com/questions/332573/how-to-make-xinput-commands-permanent/340594#340594

Here's the script I run in ~/.xinitrc:

# Map mouse button 8 (top right) to button 2 (top left) and vice versa, run when changes to the mouse occur
while true; do
        NEW_MOUSEID=$(xinput | grep "Expert Mouse" | grep -o -E '[0-9]+' | head -n 1)
        if [ "$MOUSEID" != "$NEW_MOUSEID" ]; then
                MOUSEID=$NEW_MOUSEID
                if [ "$MOUSEID" != "" ]; then
                        xinput --set-button-map $MOUSEID 1 8 3 4 5 6 7 2 9 10 11 12
                fi
        fi
        sleep 2
done &

Basic structure:

  • Watch for changes in the USB's ID from xinput every 2 seconds
  • If the mouse ID is blank, it's not connected, don't run xinput (you'll get an error if you do)
  • The parsing of the xinput command just returns the USB device ID for mouse "Expert Mouse", ex: "14"

Note that the original answer suggests monitoring for changes in lsusb and re-running the command then, that works just as well.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.