diff --git a/hwdb/70-libratbag-mouse.hwdb b/hwdb/70-libratbag-mouse.hwdb index 6111c58f..841db688 100644 --- a/hwdb/70-libratbag-mouse.hwdb +++ b/hwdb/70-libratbag-mouse.hwdb @@ -96,12 +96,14 @@ mouse:usb:v046dpc249:name:*: mouse:usb:v046dpc068:name:*: RATBAG_DRIVER=hidpp10 RATBAG_HIDPP10_DPI=0:5700@23.53 + RATBAG_HIDPP10_PROFILE=G500 # G500s mouse:usb:v046dpc24e:name:*: RATBAG_DRIVER=hidpp10 RATBAG_SVG=logitech-g500s.svg RATBAG_HIDPP10_DPI=0:8200@50 + RATBAG_HIDPP10_PROFILE=G500 # G502 over USB mouse:usb:v046dpc07d:name:*: diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index e555fbae..cf70a806 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -218,6 +218,7 @@ hidpp10drv_probe(struct ratbag_device *device) struct hidpp10drv_data *drv_data = NULL; struct hidpp10_device *dev = NULL; struct hidpp_device base; + enum hidpp10_profile_type type = HIDPP10_PROFILE_UNKNOWN; const char *prop; rc = ratbag_find_hidraw(device, hidpp10drv_test_hidraw); @@ -236,12 +237,17 @@ hidpp10drv_probe(struct ratbag_device *device) hidpp_device_init(&base, device->hidraw.fd); hidpp_device_set_log_handler(&base, hidpp10_log, HIDPP_LOG_PRIORITY_RAW, device); + prop = ratbag_device_get_udev_property(device, "RATBAG_HIDPP10_PROFILE"); + if (prop) { + if (strcasecmp("G500", prop) == 0) + type = HIDPP10_PROFILE_G500; + } /* 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. */ - dev = hidpp10_device_new(&base, HIDPP_WIRED_DEVICE_IDX); + dev = hidpp10_device_new(&base, HIDPP_WIRED_DEVICE_IDX, type); if (!dev) { log_error(device->ratbag, diff --git a/src/hidpp10.c b/src/hidpp10.c index 940653cf..fa1582b2 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -633,6 +633,11 @@ hidpp10_get_profile_directory(struct hidpp10_device *dev, struct hidpp10_directory *directory = (struct hidpp10_directory *)bytes; size_t count; + if (dev->profile_type == HIDPP10_PROFILE_UNKNOWN) { + hidpp_log_debug(&dev->base, "no profile type given\n"); + return 0; + } + if (dev->profile_directory) { count = 0; while (dev->profile_directory[count].page) { @@ -751,6 +756,9 @@ hidpp10_get_profile(struct hidpp10_device *dev, int8_t number, struct hidpp10_pr if (count < 0) return count; + if (count == 0 || dev->profile_type == HIDPP10_PROFILE_UNKNOWN) + return -ENOTSUP; + if (number >= count) { hidpp_log_error(&dev->base, "Profile number %d not in the directory.\n", number); return -EINVAL; @@ -1497,7 +1505,8 @@ hidpp10_get_device_info(struct hidpp10_device *dev) } struct hidpp10_device* -hidpp10_device_new(const struct hidpp_device *base, int idx) +hidpp10_device_new(const struct hidpp_device *base, int idx, + enum hidpp10_profile_type type) { struct hidpp10_device *dev; @@ -1505,6 +1514,7 @@ hidpp10_device_new(const struct hidpp_device *base, int idx) dev->index = idx; dev->base = *base; + dev->profile_type = type; if (hidpp10_get_device_info(dev) != 0) { hidpp10_device_destroy(dev); diff --git a/src/hidpp10.h b/src/hidpp10.h index 9c3ab76c..d3136da6 100644 --- a/src/hidpp10.h +++ b/src/hidpp10.h @@ -40,6 +40,11 @@ #define HIDPP10_MAX_PAGE_NUMBER 31 +enum hidpp10_profile_type { + HIDPP10_PROFILE_UNKNOWN = -1, + HIDPP10_PROFILE_G500, +}; + struct hidpp10_directory; struct hidpp10_dpi_mapping { @@ -53,10 +58,12 @@ struct hidpp10_device { uint8_t dpi_count; struct hidpp10_dpi_mapping *dpi_table; /* must be null terminated */ struct hidpp10_directory *profile_directory; /* must be null terminated */ + enum hidpp10_profile_type profile_type; }; struct hidpp10_device* -hidpp10_device_new(const struct hidpp_device *base, int idx); +hidpp10_device_new(const struct hidpp_device *base, int idx, + enum hidpp10_profile_type type); void hidpp10_device_destroy(struct hidpp10_device *dev); diff --git a/tools/hidpp10-dump-page.c b/tools/hidpp10-dump-page.c index a9f8ce02..3124da84 100644 --- a/tools/hidpp10-dump-page.c +++ b/tools/hidpp10-dump-page.c @@ -98,7 +98,7 @@ main(int argc, char **argv) error(1, errno, "Failed to open path %s", path); hidpp_device_init(&base, fd); - dev = hidpp10_device_new(&base, HIDPP_WIRED_DEVICE_IDX); + dev = hidpp10_device_new(&base, HIDPP_WIRED_DEVICE_IDX, HIDPP10_PROFILE_UNKNOWN); if (argc == 2) rc = dump_all_pages(dev);