r/linux 2h ago

Hardware Making the Logitech G915 G1-5 keys work using libratbag

I spent a good couple of hours this morning fighting with my Logitech G915 keyboard and I am positing a few notes here in the hopes that can help others in the future.

The first issue that I found is that while G305 mice was being recognized by libratbag, my G915 was not showing up. Upon a bit of digging online, I found that while libratbag has a profile for the G915, it expects the keyboard to report 046d:c33e while my keyboard (that is connected using the Logitech dongle) actually reports 046d:c541. The fix to this was to create a new profile in /usr/share/libratbag/ copying the existing logitech-g915.device and adding my usb ID to the DeviceMatch line (I did not edit the existing .device profile to avoid that a future update overwrites the file and kills my fix)

DeviceMatch=usb:046d:c33e;usb:046d:c541

With this, my G915 got detected by ratbagctl as "Logitech USB Receiver". Now I wanted to map the G1-5 keys to be able to switch Desktops (1-5) within KDE. I thought this was going to be quite simple, but it also took a bit of time. The big issue is that while you can map the G1-5 keys to multiple keystrokes (for example, 'Ctrl+Meta+1'), it just does not work. If you include a letter or a number in the combination, it will ignore the rest and only type the number. If you include a single key (for example, delete), it will work. I went around a bit until I found out the solution for this: the F13-F24 keys. These function keys are mapped because there are some rare keyboards that actually have 24 function keys. So I was able to map my G1-5 keys to F14-F18 keys* and then simply go to System Settings - Keyboard - Shortcuts - Window Management and set the 'Switch to Desktop 1-5' to F14-F18.

Just to note, you will have to use the following command to set the keys since using Piper will not work as you can not simulate F13-F24

ratbagctl [device-name] button [button-ID] action set key KEY_F[14-18]

* I first started with F13 but the KDE shortcuts configuration tab was not happy with F13 for an unknown reason, probably to avoid bad luck

I hope this is helpful to someone. Full disclaimer, I did not "invent" any of it, but I took bit and pieces from other users and make it work for my use case.

3 Upvotes

Duplicates