From 40658c6d0ed25e16518164d54335d7a8d1291894 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 13 Oct 2017 13:48:56 +1000 Subject: [PATCH] hidpp10: pass the dpi list to libratbag as-is If our device only has a discrete number of DPIs, pass it on as-is to libratbag rather than pretending it's a range and then failing to set the DPIs. For the actual ranged devices we use libratbag's now-exponential range mapping rather than passing all possible ones on. This relies on us having the same steps that libratbag uses, should be safe enough. Signed-off-by: Peter Hutterer --- src/driver-hidpp10.c | 19 +++++++++++++++---- src/hidpp10.c | 2 ++ src/hidpp10.h | 2 ++ src/libratbag-private.h | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 4f1da8f0..4fbb1cd1 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -417,7 +417,7 @@ hidpp10drv_read_profile(struct ratbag_profile *profile) ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION); ratbag_profile_for_each_resolution(profile, res) { - unsigned int min, max; + unsigned int dpis[hidpp10->dpi_count]; ratbag_resolution_set_resolution(res, p.dpi_modes[res->index].xres, @@ -435,9 +435,20 @@ hidpp10drv_read_profile(struct ratbag_profile *profile) res->is_active = true; } - min = hidpp10_dpi_table_get_min_dpi(hidpp10); - max = hidpp10_dpi_table_get_max_dpi(hidpp10); - ratbag_resolution_set_dpi_list_from_range(res, min, max); + if (hidpp10->dpi_table_is_range) { + unsigned int min, max; + + min = hidpp10_dpi_table_get_min_dpi(hidpp10); + max = hidpp10_dpi_table_get_max_dpi(hidpp10); + /* FIXME: this relies on libratbag using the + * same steps that we support */ + ratbag_resolution_set_dpi_list_from_range(res, min, max); + } else { + for (int i = 0; i < hidpp10->dpi_count - 1; i++) + dpis[i] = hidpp10->dpi_table[i].dpi; + + ratbag_resolution_set_dpi_list(res, dpis, hidpp10->dpi_count); + } } ratbag_profile_for_each_button(profile, button) diff --git a/src/hidpp10.c b/src/hidpp10.c index b94945db..cd334213 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -123,6 +123,7 @@ hidpp10_build_dpi_table_from_list(struct hidpp10_device *dev, dev->dpi_count = list->nentries; dev->dpi_table = zalloc(list->nentries * sizeof(*dev->dpi_table)); + dev->dpi_table_is_range = false; for (i = 0; i < list->nentries; i++) { dev->dpi_table[i].raw_value = i + 0x80; @@ -150,6 +151,7 @@ hidpp10_build_dpi_table_from_dpi_info(struct hidpp10_device *dev, dev->dpi_count = raw_max + 1; dev->dpi_table = zalloc((raw_max + 1) * sizeof(*dev->dpi_table)); + dev->dpi_table_is_range = true; for (i = 1; i <= raw_max; i++) { dev->dpi_table[i].raw_value = i; diff --git a/src/hidpp10.h b/src/hidpp10.h index 2a497ce8..40018188 100644 --- a/src/hidpp10.h +++ b/src/hidpp10.h @@ -60,6 +60,8 @@ struct hidpp10_dpi_mapping { struct hidpp10_device { struct hidpp_device base; unsigned index; + + bool dpi_table_is_range; uint8_t dpi_count; struct hidpp10_dpi_mapping *dpi_table; enum hidpp10_profile_type profile_type; diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 617831cd..60bcd55c 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -511,6 +511,21 @@ ratbag_resolution_set_dpi_list_from_range(struct ratbag_resolution *res, res->profile->device->name); } +static inline void +ratbag_resolution_set_dpi_list(struct ratbag_resolution *res, + unsigned int *dpis, + size_t ndpis) +{ + assert(ndpis <= ARRAY_LENGTH(res->dpis)); + _Static_assert(sizeof(*dpis) == sizeof(*res->dpis), "Mismatching size"); + + for (size_t i = 0; i < ndpis; i++) { + res->dpis[i] = dpis[i]; + if (i > 0) + assert(dpis[i] > dpis[i - 1]); + } +} + static inline void ratbag_resolution_set_cap(struct ratbag_resolution *res, enum ratbag_resolution_capability cap)