diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index e30784d7..b2920ea1 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -378,6 +378,8 @@ hidpp10drv_read_profile(struct ratbag_profile *profile, unsigned int index) xres = 0xffff; for (i = 0; i < profile->resolution.num_modes; i++) { + unsigned int min, max; + res = ratbag_resolution_init(profile, i, p.dpi_modes[i].xres, p.dpi_modes[i].yres, @@ -390,6 +392,10 @@ hidpp10drv_read_profile(struct ratbag_profile *profile, unsigned int index) res->is_active = true; if (i == p.default_dpi_mode) res->is_default = true; + + min = hidpp10_dpi_table_get_min_dpi(hidpp10); + max = hidpp10_dpi_table_get_max_dpi(hidpp10); + ratbag_resolution_set_range(res, min, max); } } diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 6322382c..9520653e 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -527,10 +527,17 @@ hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile) rc = hidpp20drv_read_resolution_dpi_2201(device); if (rc < 0) return rc; + for (i = 0; i < profile->resolution.num_modes; i++) { - int dpi = drv_data->sensors[i].dpi; + struct hidpp20_sensor *sensor; + + /* We only look at the first sensor. Multiple + * sensors is too niche to care about right now */ + sensor = &drv_data->sensors[0]; + /* FIXME: retrieve the refresh rate */ - res = ratbag_resolution_init(profile, i, dpi, dpi, 0); + res = ratbag_resolution_init(profile, i, sensor->dpi, sensor->dpi, 0); + ratbag_resolution_set_range(res, sensor->dpi_min, sensor->dpi_max); /* FIXME: we mark all resolutions as active because * they are from different sensors */ @@ -716,6 +723,12 @@ hidpp20drv_read_profile_8100(struct ratbag_profile *profile, unsigned int index) p = &drv_data->profiles->profiles[index]; for (i = 0; i < profile->resolution.num_modes; i++) { + struct hidpp20_sensor *sensor; + + /* We only look at the first sensor. Multiple + * sensors is too niche to care about right now */ + sensor = &drv_data->sensors[0]; + res = ratbag_resolution_init(profile, i, p->dpi[i], p->dpi[i], @@ -726,6 +739,8 @@ hidpp20drv_read_profile_8100(struct ratbag_profile *profile, unsigned int index) res->is_active = true; if (i == p->default_dpi) res->is_default = true; + + ratbag_resolution_set_range(res, sensor->dpi_min, sensor->dpi_max); } } diff --git a/src/hidpp10.c b/src/hidpp10.c index 9a85f420..a16272f4 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -31,6 +31,7 @@ #include "config.h" +#include #include #include #include @@ -85,6 +86,32 @@ const char *device_types[0xFF] = { [0x0A ... 0xFE] = NULL, }; +unsigned int +hidpp10_dpi_table_get_max_dpi(struct hidpp10_device *dev) +{ + struct hidpp10_dpi_mapping *dpi; + + assert(dev->dpi_count > 0); + + /* We assume a sorted list */ + dpi = &dev->dpi_table[dev->dpi_count - 1]; + + return dpi->dpi; +} + +unsigned int +hidpp10_dpi_table_get_min_dpi(struct hidpp10_device *dev) +{ + struct hidpp10_dpi_mapping *dpi; + + assert(dev->dpi_count > 0); + + /* We assume a sorted list, index 0 is always 0 */ + dpi = &dev->dpi_table[1]; + + return dpi->dpi; +} + int hidpp10_build_dpi_table_from_list(struct hidpp10_device *dev, const char *str_list) diff --git a/src/hidpp10.h b/src/hidpp10.h index e20a4b75..855c409b 100644 --- a/src/hidpp10.h +++ b/src/hidpp10.h @@ -101,6 +101,22 @@ int hidpp10_build_dpi_table_from_dpi_info(struct hidpp10_device *dev, const char *str_dpi); +/** + * Returns the lowest dpi stored in the dpi mapping table generated by + * hidpp10_build_dpi_table_from_list() or + * hidpp10_build_dpi_table_from_dpi_info() + */ +unsigned int +hidpp10_dpi_table_get_min_dpi(struct hidpp10_device *dev); + +/** + * Returns the highest dpi stored in the dpi mapping table generated by + * hidpp10_build_dpi_table_from_list() or + * hidpp10_build_dpi_table_from_dpi_info() + */ +unsigned int +hidpp10_dpi_table_get_max_dpi(struct hidpp10_device *dev); + /* -------------------------------------------------------------------------- */ /* 0x00: Enable HID++ Notifications */ /* -------------------------------------------------------------------------- */ diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 244ec8c4..976744cd 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -222,6 +222,8 @@ struct ratbag_resolution { struct ratbag_profile *profile; int refcount; void *userdata; + unsigned int dpi_max; /**< max resolution in dpi */ + unsigned int dpi_min; /**< min resolution in dpi */ unsigned int dpi_x; /**< x resolution in dpi */ unsigned int dpi_y; /**< y resolution in dpi */ unsigned int hz; /**< report rate in Hz */ @@ -419,10 +421,19 @@ ratbag_resolution_init(struct ratbag_profile *profile, int index, res->is_active = false; res->is_default = false; res->capabilities = 0; + res->dpi_min = 0; + res->dpi_max = 0; return res; } +static inline void +ratbag_resolution_set_range(struct ratbag_resolution *res, int min, int max) +{ + res->dpi_min = min; + res->dpi_max = max; +} + static inline void ratbag_resolution_set_cap(struct ratbag_resolution *res, enum ratbag_resolution_capability cap) diff --git a/src/libratbag.c b/src/libratbag.c index 76d65e65..43a64810 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -1075,6 +1075,18 @@ ratbag_resolution_get_dpi(struct ratbag_resolution *resolution) return resolution->dpi_x; } +LIBRATBAG_EXPORT int +ratbag_resolution_get_dpi_maximum(struct ratbag_resolution *resolution) +{ + return resolution->dpi_max; +} + +LIBRATBAG_EXPORT int +ratbag_resolution_get_dpi_minimum(struct ratbag_resolution *resolution) +{ + return resolution->dpi_min; +} + LIBRATBAG_EXPORT int ratbag_resolution_get_dpi_x(struct ratbag_resolution *resolution) { diff --git a/src/libratbag.h b/src/libratbag.h index a45ae136..d2b94974 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -956,6 +956,32 @@ ratbag_resolution_set_dpi_xy(struct ratbag_resolution *resolution, int ratbag_resolution_get_dpi(struct ratbag_resolution *resolution); +/** + * @ingroup resolution + * + * Get the maximum allowed resolution in DPI for the resolution mode. + * + * @param resolution A previously initialized ratbag resolution + * + * @return The maximum resolution in dpi + * @retval 0 The maximum resolution is unknown to libratbag + */ +int +ratbag_resolution_get_dpi_maximum(struct ratbag_resolution *resolution); + +/** + * @ingroup resolution + * + * Get the minimum allowed resolution in DPI for the resolution mode. + * + * @param resolution A previously initialized ratbag resolution + * + * @return The minimum resolution in dpi + * @retval 0 The minimum resolution is unknown to libratbag + */ +int +ratbag_resolution_get_dpi_minimum(struct ratbag_resolution *resolution); + /** * @ingroup resolution * diff --git a/src/libratbag.sym b/src/libratbag.sym index 15aab48f..bdf30f69 100644 --- a/src/libratbag.sym +++ b/src/libratbag.sym @@ -70,6 +70,8 @@ global: ratbag_profile_set_enabled; ratbag_profile_unref; ratbag_resolution_get_dpi; + ratbag_resolution_get_dpi_maximum; + ratbag_resolution_get_dpi_minimum; ratbag_resolution_get_dpi_x; ratbag_resolution_get_dpi_y; ratbag_resolution_get_report_rate; diff --git a/tools/ratbag-command.c b/tools/ratbag-command.c index c6ab8471..65a621c8 100644 --- a/tools/ratbag-command.c +++ b/tools/ratbag-command.c @@ -432,6 +432,8 @@ ratbag_cmd_info(const struct ratbag_cmd *cmd, for (int i = 0; i < num_profiles; i++) { int dpi, rate; + struct ratbag_resolution *res; + profile = ratbag_device_get_profile(device, i); if (!profile) continue; @@ -440,9 +442,14 @@ ratbag_cmd_info(const struct ratbag_cmd *cmd, ratbag_profile_is_enabled(profile) ? "enabled" : "disabled", ratbag_profile_is_active(profile) ? " (active)" : ""); printf(" Resolutions:\n"); - for (unsigned int j = 0; j < ratbag_profile_get_num_resolutions(profile); j++) { - struct ratbag_resolution *res; + res = ratbag_profile_get_resolution(profile, 0); + printf(" Range: [%d, %d]\n", + ratbag_resolution_get_dpi_minimum(res), + ratbag_resolution_get_dpi_maximum(res)); + ratbag_resolution_unref(res); + + for (unsigned int j = 0; j < ratbag_profile_get_num_resolutions(profile); j++) { res = ratbag_profile_get_resolution(profile, j); dpi = ratbag_resolution_get_dpi(res); rate = ratbag_resolution_get_report_rate(res);