forked from drath/libratbag
Provide a min/max dpi for the resolutions
For a GUI application like Piper, it's required that we know the range to present to the user. This patch includes the code for HID++ 1.0 and 2.0, other drivers need to follow. https://github.com/libratbag/libratbag/issues/180 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Benjamin Tissoires
parent
ecdba84977
commit
e311f89357
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <linux/types.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
@@ -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)
|
||||
|
||||
@@ -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 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user