From a715679f1f2913d8cfc4bf75b5d35c7484dde082 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 28 Apr 2016 15:23:48 +1000 Subject: [PATCH] Add a fallback for Logitech's HID++ devices If a device is not specifically assigned a driver, try hidpp20 and then hidpp10 hoping that one of them will work. Signed-off-by: Peter Hutterer --- src/libratbag.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/libratbag.c b/src/libratbag.c index 2b0b719b..55067d7a 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -34,6 +34,7 @@ #include #include +#include "usb-ids.h" #include "libratbag-private.h" #include "libratbag-util.h" @@ -331,6 +332,22 @@ error: return false; } +static inline bool +ratbag_driver_fallback_logitech(struct ratbag_device *device, + const struct input_id *dev_id) +{ + int rc; + + if (dev_id->vendor != USB_VENDOR_ID_LOGITECH) + return false; + + rc = ratbag_test_driver(device, dev_id, "hidpp20", NULL); + if (!rc) + rc = ratbag_test_driver(device, dev_id, "hidpp10", NULL); + + return rc; +} + bool ratbag_assign_driver(struct ratbag_device *device, const struct input_id *dev_id, @@ -341,13 +358,15 @@ ratbag_assign_driver(struct ratbag_device *device, if (!test_device) { driver_name = udev_prop_value(device->udev_device, "RATBAG_DRIVER"); - if (!driver_name) - return false; } else { driver_name = "test_driver"; } - rc = ratbag_test_driver(device, dev_id, driver_name, test_device); + if (driver_name) { + rc = ratbag_test_driver(device, dev_id, driver_name, test_device); + } else { + rc = ratbag_driver_fallback_logitech(device, dev_id); + } return rc; }