Eu tenho dois ratos, um que tem um problema em que o botão do meio e o botão6 são acionados simultaneamente. Então eu configurei o meu ~/.Xmodmap
para desativar este botão. Ao mesmo tempo, no entanto, eu queria poder ainda usar esse botão com meu outro mouse. Então, escrevi uma udev
regra que chamava xmodmap
para alterar o layout do botão, dependendo do mouse conectado.
Configuração
Esta é a minha configuração atual:
/etc/udev/rules.d/logitech-g7.rules :
# deactivate MB 6 when mouse 1 is connected
ACTION=="add", ENV{DEVTYPE}=="usb_device", ENV{ID_VENDOR_ID}=="046d", ENV{ID_MODEL_ID}=="c51a", RUN+="/home/user/.scripts/Troubleshooting/Bugfixes/mouseswitcher_wrapper 1", OWNER="user"
# restore defaults when mouse 1 is disconnected
ACTION=="remove", ENV{DEVTYPE}=="usb_device", ENV{ID_VENDOR_ID}=="046d", ENV{ID_MODEL_ID}=="c51a", RUN+="/home/user/.scripts/Troubleshooting/Bugfixes/mouseswitcher_wrapper 0", OWNER="user"
/home/user/.scripts/Trou Troubleshooting / Bugfixes / mouseswitcher_wrapper :
#!/bin/bash
/home/user/.scripts/Troubleshooting/Bugfixes/mouseswitcher "$1"&
/home/user/.scripts/Trou Troubleshooting/Bugfixes/mouseswitcher
#!/bin/bash
sleep 1
DISPLAY=":0.0"
HOME=/home/user/
XAUTHORITY=$HOME/.Xauthority
export DISPLAY XAUTHORITY HOME
if [[ "$1" == 1 ]] #differentiate between ADD (1) event and REMOVE (0) event
then
/usr/bin/xmodmap /home/user/.XmodmapG7 > /dev/null 2>&1
else
/usr/bin/xmodmap /home/user/.Xmodmap > /dev/null 2>&1
fi
Se isso parecer um pouco complicado demais, é apenas porque eu me deparei com vários problemas com o udev, xmodmap e a variável DISPLAY. Meus scripts são baseados nessas perguntas e respostas .
Estado atual
A ação ADD funciona bem, a ação REMOVE não. A execução manual de qualquer um dos comandos RUN em um terminal funciona bem.
O que eu tentei até agora
Encontrei este post do fórum descrevendo por que o udev tem problemas com ações de remoção e, portanto, substitui o ATTRS por variáveis ENV. Mas tudo isso foi inútil, o gatilho REMOVE ainda não funciona.
Tem que haver algo que estou fazendo errado. Eu realmente apreciaria se alguém por aqui, mais versado no udev e Linux em geral, pudesse dar uma olhada no meu caso.
Informação adicional
Saída de udevadm monitor --environment --udev
quando o receptor é conectado:
######ADD#######
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
UDEV [21728.392805] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3 (usb)
ACTION=add
BUSNUM=002
DEVNAME=/dev/bus/usb/002/037
DEVNUM=037
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_USB_INTERFACES=:030102:030000:
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
MAJOR=189
MINOR=164
PRODUCT=46d/c51a/4100
SEQNUM=3139
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
UPOWER_VENDOR=Logitech, Inc.
USEC_INITIALIZED=21727880859
UDEV [21728.393864] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0
DEVTYPE=usb_interface
INTERFACE=3/1/2
MODALIAS=usb:v046DpC51Ad4100dc00dsc00dp00ic03isc01ip02in00
PRODUCT=46d/c51a/4100
SEQNUM=3140
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=21728393779
UDEV [21728.395536] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1
DEVTYPE=usb_interface
INTERFACE=3/0/0
MODALIAS=usb:v046DpC51Ad4100dc00dsc00dp00ic03isc00ip00in01
PRODUCT=46d/c51a/4100
SEQNUM=3146
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=21728395426
UDEV [21728.395737] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004B (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004B
HID_ID=0003:0000046D:0000C51A
HID_NAME=Logitech USB Receiver
HID_PHYS=usb-0000:00:1d.0-1.3/input0
MODALIAS=hid:b0003g0001v0000046Dp0000C51A
SEQNUM=3141
SUBSYSTEM=hid
UDEV_LOG=3
USEC_INITIALIZED=21728395467
UDEV [21728.398102] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004C (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004C
HID_ID=0003:0000046D:0000C51A
HID_NAME=Logitech USB Receiver
HID_PHYS=usb-0000:00:1d.0-1.3/input1
MODALIAS=hid:b0003g0001v0000046Dp0000C51A
SEQNUM=3147
SUBSYSTEM=hid
UDEV_LOG=3
USEC_INITIALIZED=21728397927
UDEV [21728.398650] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004B/hidraw/hidraw2 (hidraw)
ACTION=add
DEVNAME=/dev/hidraw2
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004B/hidraw/hidraw2
MAJOR=251
MINOR=2
SEQNUM=3145
SUBSYSTEM=hidraw
UDEV_LOG=3
USEC_INITIALIZED=21728398188
UDEV [21728.399406] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004C/hidraw/hidraw3 (hidraw)
ACTION=add
DEVNAME=/dev/hidraw3
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004C/hidraw/hidraw3
MAJOR=251
MINOR=3
SEQNUM=3151
SUBSYSTEM=hidraw
UDEV_LOG=3
USEC_INITIALIZED=21728399273
UDEV [21728.400119] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/usbmisc/hiddev1 (usbmisc)
ACTION=add
DEVNAME=/dev/usb/hiddev1
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/usbmisc/hiddev1
MAJOR=180
MINOR=1
SEQNUM=3150
SUBSYSTEM=usbmisc
UDEV_LOG=3
USEC_INITIALIZED=21727874845
UDEV [21728.401438] add /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input73 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input73
EV=17
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:030000:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
KEY=ffff0000 0 0 0 0
MODALIAS=input:b0003v046DpC51Ae0111-e0,1,2,4,k110,111,112,113,114,115,116,117,118,119,11A,11B,11C,11D,11E,11F,r0,1,6,8,am4,lsfw
MSC=10
NAME="Logitech USB Receiver"
PHYS="usb-0000:00:1
Saída de udevadm monitor --environment --udev
ao remover o receptor:
#######REMOVE#######
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
UDEV [21800.789239] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input75/mouse1 (input)
ACTION=remove
DEVLINKS=/dev/input/by-id/usb-Logitech_USB_Receiver-mouse /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.3:1.0-mouse
DEVNAME=/dev/input/mouse1
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input75/mouse1
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:030000:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
MAJOR=13
MINOR=33
SEQNUM=3178
SUBSYSTEM=input
UDEV_LOG=3
USEC_INITIALIZED=21797014959
UDEV [21800.792866] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input75/event6 (input)
ACTION=remove
DEVLINKS=/dev/input/by-id/usb-Logitech_USB_Receiver-event-mouse /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.3:1.0-event-mouse
DEVNAME=/dev/input/event6
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input75/event6
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:030000:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
MAJOR=13
MINOR=70
SEQNUM=3179
SUBSYSTEM=input
UDEV_LOG=3
USEC_INITIALIZED=21797013896
UDEV [21800.797061] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input75 (input)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/input/input75
EV=17
ID_BUS=usb
ID_INPUT=1
ID_INPUT_MOUSE=1
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.0
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_0
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:030000:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
KEY=ffff0000 0 0 0 0 0 0 0 0
MODALIAS=input:b0003v046DpC51Ae0111-e0,1,2,4,k110,111,112,113,114,115,116,117,118,119,11A,11B,11C,11D,11E,11F,r0,1,6,8,am4,lsfw
MSC=10
NAME="Logitech USB Receiver"
PHYS="usb-0000:00:1d.0-1.3/input0"
PRODUCT=3/46d/c51a/111
PROP=0
REL=143
SEQNUM=3180
SUBSYSTEM=input
UDEV_LOG=3
UNIQ=""
USEC_INITIALIZED=21796479085
UDEV [21800.797132] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004D/hidraw/hidraw2 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw2
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004D/hidraw/hidraw2
MAJOR=251
MINOR=2
SEQNUM=3181
SUBSYSTEM=hidraw
UDEV_LOG=3
USEC_INITIALIZED=21800796369
UDEV [21800.797172] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004D (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C51A.004D
HID_ID=0003:0000046D:0000C51A
HID_NAME=Logitech USB Receiver
HID_PHYS=usb-0000:00:1d.0-1.3/input0
MODALIAS=hid:b0003g0001v0000046Dp0000C51A
SEQNUM=3182
SUBSYSTEM=hid
UDEV_LOG=3
USEC_INITIALIZED=21800796501
UDEV [21800.798537] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0
DEVTYPE=usb_interface
INTERFACE=3/1/2
MODALIAS=usb:v046DpC51Ad4100dc00dsc00dp00ic03isc01ip02in00
PRODUCT=46d/c51a/4100
SEQNUM=3183
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=21800796538
UDEV [21800.814181] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/input/input76/event7 (input)
ACTION=remove
DEVLINKS=/dev/input/by-id/usb-Logitech_USB_Receiver-event-if01 /dev/input/by-path/pci-0000:00:1d.0-usb-0:1.3:1.1-event
DEVNAME=/dev/input/event7
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/input/input76/event7
ID_BUS=usb
ID_INPUT=1
ID_INPUT_KEY=1
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.1
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_1
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:030000:
ID_USB_INTERFACE_NUM=01
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
MAJOR=13
MINOR=71
SEQNUM=3184
SUBSYSTEM=input
UDEV_LOG=3
USEC_INITIALIZED=21797013933
XKBLAYOUT=de
XKBMODEL=pc105
UDEV [21800.816765] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/input/input76 (input)
ABS=1 0
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/input/input76
EV=1f
ID_BUS=usb
ID_INPUT=1
ID_INPUT_KEY=1
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_PATH=pci-0000:00:1d.0-usb-0:1.3:1.1
ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3_1_1
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030102:030000:
ID_USB_INTERFACE_NUM=01
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
KEY=4837fff 72ff32d bf544446 0 0 1 20f90 8b17c000 677bfa d9415fed 9ed680 4400 0 10000002
MODALIAS=input:b0003v046DpC51Ae0111-e0,1,2,3,4,k71,72,73,74,77,80,82,83,85,86,87,88,89,8A,8B,8C,8E,90,96,98,9B,9C,9E,9F,A1,A3,A4,A5,A6,A7,A8,A9,AB,AC,AD,AE,B0,B1,B2,B5,B6,CE,CF,D0,D1,D2,D4,D8,D9,DB,DF,E4,E7,E8,E9,EA,EB,F1,100,161,162,166,16A,16E,172,174,176,178,179,17A,17B,17C,17D,17F,180,182,183,185,188,189,18C,18D,18E,18F,190,191,192,193,195,198,199,19A,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA,1AB,1AC,1AD,1AE,1B0,1B1,1B7,1BA,r6,a20,m4,lsfw
MSC=10
NAME="Logitech USB Receiver"
PHYS="usb-0000:00:1d.0-1.3/input1"
PRODUCT=3/46d/c51a/111
PROP=0
REL=40
SEQNUM=3185
SUBSYSTEM=input
UDEV_LOG=3
UNIQ=""
USEC_INITIALIZED=21796482192
UDEV [21800.817249] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/usbmisc/hiddev1 (usbmisc)
ACTION=remove
DEVNAME=/dev/usb/hiddev1
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/usbmisc/hiddev1
MAJOR=180
MINOR=1
SEQNUM=3186
SUBSYSTEM=usbmisc
UDEV_LOG=3
USEC_INITIALIZED=21800816392
UDEV [21800.818490] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004E/hidraw/hidraw3 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw3
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004E/hidraw/hidraw3
MAJOR=251
MINOR=3
SEQNUM=3187
SUBSYSTEM=hidraw
UDEV_LOG=3
USEC_INITIALIZED=21800816472
UDEV [21800.818536] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004E (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1/0003:046D:C51A.004E
HID_ID=0003:0000046D:0000C51A
HID_NAME=Logitech USB Receiver
HID_PHYS=usb-0000:00:1d.0-1.3/input1
MODALIAS=hid:b0003g0001v0000046Dp0000C51A
SEQNUM=3188
SUBSYSTEM=hid
UDEV_LOG=3
USEC_INITIALIZED=21800816908
UDEV [21800.818580] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1 (usb)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.1
DEVTYPE=usb_interface
INTERFACE=3/0/0
MODALIAS=usb:v046DpC51Ad4100dc00dsc00dp00ic03isc00ip00in01
PRODUCT=46d/c51a/4100
SEQNUM=3189
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
USEC_INITIALIZED=21800816945
UDEV [21800.818645] remove /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3 (usb)
ACTION=remove
BUSNUM=002
DEVNAME=/dev/bus/usb/002/038
DEVNUM=038
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=USB_Receiver
ID_MODEL_ENC=USB\x20Receiver
ID_MODEL_ID=c51a
ID_REVISION=4100
ID_SERIAL=Logitech_USB_Receiver
ID_USB_INTERFACES=:030102:030000:
ID_VENDOR=Logitech
ID_VENDOR_ENC=Logitech
ID_VENDOR_ID=046d
MAJOR=189
MINOR=165
PRODUCT=46d/c51a/4100
SEQNUM=3190
SUBSYSTEM=usb
TYPE=0/0/0
UDEV_LOG=3
UPOWER_VENDOR=Logitech, Inc.
USEC_INITIALIZED=21796488421
udevadm test --action=add $(udevadm info --query=path -n /dev/input/mouse0)