logitech mouse configuration, small linux headache

I like having my Logitech G903 mouse configured to have volume controls, next and previous button, and pause/play button. The strategy to get those bindings in my Linux environment is to boot into Windows and configure my mouse with those bindings and to store the configuration on the mouse's onboard memory. However, this particular mouse can be used in wired and wireless mode, and on my install of Arch / Xorg, the keys that I bound in Windows would only work in wired mode. The mouse still worked in wireless mode, and in fact I could even use Piper to configure the buttons to macros, but although I was able to bind the volume up / down successfully, when I tried to bind next, previous, or play/pause, the buttons I bound them to did nothing when pressed.

Using my Google-Foo, I was able to find a solution. If you're using any Logitech gaming mice, and can't bind your keys to macros to use in Linux, here's the solution.

The long and short of it, apparently, is that there is a kernel bug (feature?) that causes the Logitech Mice to no longer show up as a keyboard, and as a result, they lost their ability to send certain keys[0]. However, as mentioned in that forum post, it isn't too hard to fix it yourself. Removing and blacklisting the Logitech drivers hid_logitech_dj and hid_logitech_hidpp means happy times. First, use modprobe -r drivername on each driver, and then add the following lines your /etc/modprobe.d/blacklist.conf.
blacklist hid_logitech_dj\r install hid_logitech_dj /bin/true\r blacklist hid_logitech_hidpp\r install hid_logitech_hidpp /bin/true\r

Blacklisting those drivers prevents them from loading, and using the install option to /bin/true, prevents them from reinstalling. /bin/true is used in lieu of /bin/false to prevent any error messages[1].

The second problem was that the two modes, wired and wireless, now had different DPIs. I thought I might run into another bit of a headache, but it turns out that adjusting mouse DPI in Linux couldn't be simpler. Using mouse-dpi-tool, which is included with libevdev package on Arch, it's very simply to change mouse DPI settings.

Find your mouse's device node by using xinput to first find the id, then xinput list-props id which shows device node. My G903 is /dev/input/event19. Then run mouse-dpi-tool /dev/input/event19. Move your mouse around for a few seconds, then press C-c.
Mouse Logitech USB Receiver Mouse on /dev/input/event19\r Move the device 250mm/10in or more along the x-axis.\r Pause 3 seconds before movement to reset, Ctrl+C to exit.\r Covered distance in device units: 267 at frequency 1016.3Hz -^C\r Estimated sampling frequency: 1016Hz (mean 1000Hz)\r To calculate resolution, measure physical distance covered\r and look up the matching resolution in the table below\r 16mm 0.67in 400dpi\r 11mm 0.45in 600dpi\r 8mm 0.33in 800dpi\r 6mm 0.27in 1000dpi\r 5mm 0.22in 1200dpi\r 4mm 0.19in 1400dpi\r 4mm 0.17in 1600dpi\r 3mm 0.15in 1800dpi\r 3mm 0.13in 2000dpi\r 3mm 0.12in 2200dpi\r 2mm 0.11in 2400dpi\r If your resolution is not in the list, calculate it with:\r resolution=267/inches, or\r resolution=267 * 25.4/mm\r \r Entry for hwdb match (replace XXX with the resolution in DPI):\r mouse:usb:v046dpc539:name:Logitech USB Receiver Mouse:\r MOUSE_DPI=XXX@1016\r

Then it's as simple as copying the last two lines into /etc/udev/hwdb.d/71-mouse-local.hwdb and fill in the DPI you want[2]. Then, trigger the device using udevadm trigger /dev/input/event19 and off to the races. I repeated this with the wired and wireless configuration of my mouse and my resulting 71-mouse-local.hwdb looks like this:

mouse:usb:v046dpc539:name:Logitech USB Receiver Mouse:\r MOUSE_DPI=400@1000\r \r mouse:usb:v046dpc086:name:Logitech Logitech G903 Wired/Wireless Gaming Mouse:\r MOUSE_DPI=400@1000\r

Mouse macros working, DPI's synced across wired and wireless. Happy days of mouse media control ahead.

[0]: https://ask.fedoraproject.org/t/logitech-gaming-mouse-buttons-assigned-with-keyboard-bindings-no-longer-works/5305/9
[1]: https://github.com/ComplianceAsCode/content/issues/539
[2]: https://cgit.freedesktop.org/systemd/systemd/tree/hwdb/70-mouse.hwdb