From 64cfad665dec0ce8905f6d536113aa95fc4dcaf9 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 21 Aug 2015 11:59:32 -0400 Subject: [PATCH] Implement reading the resolution of the sensor Should work with adjustable DPI and fixed DPI for Logitech devices. Signed-off-by: Benjamin Tissoires --- src/driver-hidpp20.c | 74 ++++++++++++++++++++++++++++++----------- src/libratbag-private.h | 1 + src/libratbag.c | 3 +- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index d5143642..2e201f26 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -79,7 +79,7 @@ hidpp20drv_has_capability(const struct ratbag_device *device, enum ratbag_capabi static int hidpp20drv_current_profile(struct ratbag_device *device) { - return -1; + return 0; } static int @@ -88,9 +88,62 @@ hidpp20drv_set_current_profile(struct ratbag_device *device, unsigned int index) return -1; } +static int +hidpp20drv_read_resolution_dpi(struct ratbag_device *device) +{ + struct ratbag *ratbag = device->ratbag; + struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device); + int rc, dpi; + + if (drv_data->capabilities & HIDPP_CAP_RESOLUTION_2200) { + uint16_t resolution; + uint8_t flags; + + rc = hidpp20_mousepointer_get_mousepointer_info(device, &resolution, &flags); + if (rc) { + log_error(ratbag, + "Error while requesting resolution: %s (%d)\n", + strerror(-rc), rc); + return 0; + } + + return resolution; + } + + if (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201) { + struct hidpp20_sensor *sensors; + + dpi = 0; + rc = hidpp20_adjustable_dpi_get_sensors(device, &sensors); + if (rc < 0) { + log_error(ratbag, + "Error while requesting resolution: %s (%d)\n", + strerror(-rc), rc); + } else if (rc == 0) { + log_error(ratbag, "Error, no compatible sensors found.\n"); + } else { + log_info(ratbag, + "device is at %d dpi (variable between %d and %d).\n", + sensors[0].dpi, + sensors[0].dpi_min, + sensors[0].dpi_max); + dpi = sensors[0].dpi; + } + free(sensors); + return dpi; + } + + return 0; +} + static void hidpp20drv_read_profile(struct ratbag_profile *profile, unsigned int index) { + int dpi; + + dpi = hidpp20drv_read_resolution_dpi(profile->device); + if (dpi > 0) + profile->current_dpi = dpi; } static int @@ -112,30 +165,11 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) /* these features are mandatory and already handled */ break; case HIDPP_PAGE_MOUSE_POINTER_BASIC: { - uint16_t resolution; - uint8_t flags; - drv_data->capabilities |= HIDPP_CAP_RESOLUTION_2200; - rc = hidpp20_mousepointer_get_mousepointer_info(device, &resolution, &flags); - if (rc) - return rc; - log_info(ratbag, "device resolution is %d dpi\n", resolution); break; } case HIDPP_PAGE_ADJUSTABLE_DPI: { - struct hidpp20_sensor *sensors; - log_info(ratbag, "device has adjustable dpi\n"); - rc = hidpp20_adjustable_dpi_get_sensors(device, &sensors); - if (rc < 0) - return rc; - if (rc > 0) - log_info(ratbag, - "device is at %d dpi (variable between %d and %d).\n", - sensors[0].dpi, - sensors[0].dpi_min, - sensors[0].dpi_max); - free(sensors); drv_data->capabilities |= HIDPP_CAP_SWITCHABLE_RESOLUTION_2201; break; } diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 6b020cdd..503b1526 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -175,6 +175,7 @@ struct ratbag_profile { struct list buttons; void *drv_data; void *user_data; + int current_dpi; }; struct ratbag_button { diff --git a/src/libratbag.c b/src/libratbag.c index 66bfaf79..85cacf0c 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -603,7 +603,8 @@ ratbag_device_set_active_profile(struct ratbag_device *device, LIBRATBAG_EXPORT int ratbag_profile_get_resolution_dpi(const struct ratbag_profile *profile) { - return 0; + assert(profile); + return profile->current_dpi; } LIBRATBAG_EXPORT int