From 21d0219809acad2c8a50bc9df9409f6c4d0d0f1b Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 10 May 2016 14:43:24 +0200 Subject: [PATCH 1/2] hidpp20: add new special action in G900 Signed-off-by: Benjamin Tissoires --- src/hidpp20.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hidpp20.c b/src/hidpp20.c index c999fd52..93b268cf 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -1884,8 +1884,9 @@ static const enum ratbag_button_action_special hidpp20_profiles_specials[] = { [0x09] = RATBAG_BUTTON_ACTION_SPECIAL_INVALID, [0x0a] = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP, [0x0b] = RATBAG_BUTTON_ACTION_SPECIAL_SECOND_MODE, + [0x0c] = RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL, - [0x0c ... 0xff] = RATBAG_BUTTON_ACTION_SPECIAL_INVALID, + [0x0d ... 0xff] = RATBAG_BUTTON_ACTION_SPECIAL_INVALID, }; enum ratbag_button_action_special From aef7b3e9bb8fb04044599acba9d5a0dc069f3ef0 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Wed, 11 May 2016 13:58:44 +0200 Subject: [PATCH 2/2] hidpp20drv: add support for the G900 over wireless We need the same setting that we have on the hidpp10 side. Signed-off-by: Benjamin Tissoires --- hwdb/70-libratbag-mouse.hwdb | 6 ++++++ src/driver-hidpp20.c | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/hwdb/70-libratbag-mouse.hwdb b/hwdb/70-libratbag-mouse.hwdb index f4362ad4..2953cbd3 100644 --- a/hwdb/70-libratbag-mouse.hwdb +++ b/hwdb/70-libratbag-mouse.hwdb @@ -165,6 +165,12 @@ mouse:usb:v046dpc080:name:*: mouse:usb:v046dp4011:name:*: RATBAG_DRIVER=hidpp20 +# G900 over wireless USB +mouse:usb:v046dpc539:name:*: + RATBAG_DRIVER=hidpp20 + RATBAG_HIDPP20_INDEX=1 + + ########################################## # Roccat ########################################## diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 2ff5e6bb..4cb0037e 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -812,6 +812,9 @@ hidpp20drv_probe(struct ratbag_device *device) struct hidpp20drv_data *drv_data; struct hidpp_device base; struct hidpp20_device *dev; + const char *prop; + int device_idx = HIDPP_RECEIVER_IDX; + int nread = 0; rc = ratbag_find_hidraw(device, hidpp20drv_test_hidraw); if (rc) @@ -822,7 +825,27 @@ hidpp20drv_probe(struct ratbag_device *device) hidpp_device_init(&base, device->hidraw.fd); hidpp_device_set_log_handler(&base, hidpp20_log, HIDPP_LOG_PRIORITY_RAW, device); - dev = hidpp20_device_new(&base, HIDPP_RECEIVER_IDX); + prop = ratbag_device_get_udev_property(device, "RATBAG_HIDPP20_INDEX"); + if (prop) { + sscanf(prop, "%d%n", &device_idx, &nread); + if (!nread || (prop[nread]) != '\0' || device_idx < 0) { + log_error(device->ratbag, + "Error parsing RATBAG_HIDPP20_INDEX: '%s' for %s\n", + prop, + device->name); + device_idx = HIDPP_RECEIVER_IDX; + } + } + + /* In the general case, we can treat all devices as wired devices + * here. If we talk to the correct hidraw device the kernel adjusts + * the device index for us, so even for unifying receiver devices + * we can just use 0xff as device index. + * + * If there is a special need like for G900, we can pass a + * udev prop RATBAG_HIDPP20_INDEX. + */ + dev = hidpp20_device_new(&base, device_idx); if (!dev) { rc = -ENODEV; goto err;