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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2017-10-13 13:48:56 +10:00
committed by Benjamin Tissoires
parent 251efd3b40
commit 40658c6d0e
4 changed files with 34 additions and 4 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)