Razer mouse battery detected as keyboard
Hi, I have Razer Deathadder V2 X Hyperspeed wireless mouse that is detected as a keyboard by UPower.
Device: /org/freedesktop/UPower/devices/battery_razermouse_battery_0
native-path: razermouse_battery_0
model: Razer DeathAdder V2 X HyperSpeed
serial: PM000398700245
power supply: no
updated: Thu 15 Feb 2024 11:19:42 CET (12 seconds ago)
has history: yes
has statistics: yes
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 99%
icon-name: 'battery-full-symbolic'
History (charge):
1707992382 99.000 discharging
1707992382 0.000 unknown
1707992351 99.000 discharging
1707992351 0.000 unknown
1707992321 99.000 discharging
1707992321 0.000 unknown
1707992291 99.000 discharging
1707992291 0.000 unknown
History (rate):
1707992382 0.000 unknown
1707992351 0.000 unknown
1707992321 0.000 unknown
1707992291 0.000 unknown
The reason seems to be that the USB dongle reports itself as both a mouse and a keyboard (see attached udevadm
dump), and the code in src/linux/up-device-supply.c
prefers keyboard over mouse if it finds both...
According to this thread, the dongle can be paired with multiple Razer devices (at least on Windows, the Linux driver doesn't support it), which is probably why it reports itself as both mouse and keyboard. At the same time it mentions that the dongle keeps reporting the original device it came with as its name, so some kind of name-based heuristics wouldn't work here (wouldn't work for this mouse anyway, since it doesn't say "mouse" anywhere in its name).
I looked at the code, it looks like UPower find the battery device:
/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2.2/1-2.2.2:1.0/0003:1532:009C.003D/power_supply/razermouse_battery_0
And then considers the following devices as its siblings:
/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2.2/1-2.2.2:1.0/0003:1532:009C.003D/input/input149 (ID_INPUT_MOUSE=1)
/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2.2/1-2.2.2:1.1/0003:1532:009C.0039/input/input145 (ID_INPUT_MOUSE=1, ID_INPUT_KEY=1, ID_INPUT_KEYBOARD=1)
/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2.2/1-2.2.2:1.2/0003:1532:009C.0038/input/input144 (ID_INPUT_KEY=1, ID_INPUT_KEYBOARD=1)
/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2.2/1-2.2.2:1.3/0003:1532:009C.003C/input/input148 (ID_INPUT_KEY=1)
The keyboard one ultimately wins, since keyboard UP_DEVICE_KIND_KEYBOARD
has higher preference than UP_DEVICE_KIND_MOUSE
.
I wonder whether the detection could be made smarter and in case of such dilemma could only consider input devices of the same HID device as the battery, instead of looking at all input devices of the entire USB dongle. In my case that would be /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2.2/1-2.2.2:1.0/0003:1532:009C.003D/
, which would only yield the input149
input device as a sibling and that one we know is a mouse).