From 6d55dae48da2b3f1e40725c35455a013234d3158 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 26 Aug 2015 09:10:21 +1000 Subject: [PATCH] driver-hidpp10: fill the number of buttons from the first profile We don't know the HID++ 1.0 request to check for the number of buttons or profiles, this is the next-best thing. Signed-off-by: Peter Hutterer --- src/driver-hidpp10.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index b4cea6e5..1af5663e 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -185,6 +185,26 @@ out: return 0; } +static int +hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device *dev) +{ + int rc; + struct hidpp10_profile profile; + + /* We don't know the HID++1.0 requests to query for buttons, etc. + * and the get_current_profile request is garbage. So get profile 1 + * and fill the device information in from that. + */ + rc = hidpp10_get_profile(dev, 0, &profile); + if (rc) + return rc; + + device->num_buttons = profile.num_buttons; + device->num_profiles = HIDPP10_NUM_PROFILES; + + return 0; +} + static int hidpp10drv_probe(struct ratbag_device *device, const struct ratbag_id id) { @@ -230,8 +250,11 @@ hidpp10drv_probe(struct ratbag_device *device, const struct ratbag_id id) drv_data->dev = dev; ratbag_set_drv_data(device, drv_data); - device->num_profiles = 1; - device->num_buttons = 8; + if (hidpp10drv_fill_from_profile(device, dev)) { + /* Fall back to something that every mouse has */ + device->num_profiles = 1; + device->num_buttons = 3; + } return 0; err: