From 4ebba2df74979b0695db7616eb6208bd991dce72 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 27 Nov 2015 09:40:45 +0100 Subject: [PATCH] hidpp10: add support for G700 over wireless The G700 can use a wireless receiver too. It is close enough to the normal Logitech Unifying receiver, but is truncated as it can not pair multiple devices. We currently don't treat it in the kernel as an Unifying device, and so giving the device index of 0x00 fails as the device is actually on 0x01. While there is no proper kernel solution (if there will ever be one), allow to add a parameter in the hwdb to specify the device index. We might need it for some other devices too, we will see. Signed-off-by: Benjamin Tissoires --- hwdb/70-libratbag-mouse.hwdb | 7 +++++++ src/driver-hidpp10.c | 27 ++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/hwdb/70-libratbag-mouse.hwdb b/hwdb/70-libratbag-mouse.hwdb index fce7ffa9..c2bcd5b8 100644 --- a/hwdb/70-libratbag-mouse.hwdb +++ b/hwdb/70-libratbag-mouse.hwdb @@ -115,6 +115,13 @@ mouse:usb:v046dpc06b:name:*: RATBAG_HIDPP10_DPI=0:5700@23.53 RATBAG_HIDPP10_PROFILE=G700 +# G700 over wireless USB +mouse:usb:v046dpc531:name:*: + RATBAG_DRIVER=hidpp10 + RATBAG_HIDPP10_DPI=0:5700@23.53 + RATBAG_HIDPP10_PROFILE=G700 + RATBAG_HIDPP10_INDEX=1 + # MX Master over unifying mouse:usb:v046dp4041:name:*: # MX Master over bluetooth diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index a3ddf945..3c37b763 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -302,6 +302,8 @@ hidpp10drv_probe(struct ratbag_device *device) struct hidpp_device base; enum hidpp10_profile_type type = HIDPP10_PROFILE_UNKNOWN; const char *prop; + int device_idx = HIDPP_WIRED_DEVICE_IDX; + int nread = 0; rc = ratbag_find_hidraw(device, hidpp10drv_test_hidraw); if (rc == -ENODEV) { @@ -326,12 +328,27 @@ hidpp10drv_probe(struct ratbag_device *device) else if (strcasecmp("G700", prop) == 0) type = HIDPP10_PROFILE_G700; } - /* 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 0x00 as device - * index. + + prop = ratbag_device_get_udev_property(device, "RATBAG_HIDPP10_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_HIDPP10_INDEX: '%s' for %s\n", + prop, + device->name); + device_idx = HIDPP_WIRED_DEVICE_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 0x00 as device index. + * + * If there is a special need like for G700(s), we can pass a + * udev prop RATBAG_HIDPP10_INDEX. */ - dev = hidpp10_device_new(&base, HIDPP_WIRED_DEVICE_IDX, type); + dev = hidpp10_device_new(&base, device_idx, type); if (!dev) { log_error(device->ratbag,