mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-08 07:33:53 +01:00
hidpp20: restore the dpi functionality
We need to store the profile in each ratbag_resolution or we will not be able to get back to the driver. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -159,29 +159,31 @@ hidpp20drv_set_current_profile(struct ratbag_device *device, unsigned int index)
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp20drv_read_resolution_dpi(struct ratbag_device *device)
|
||||
hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile)
|
||||
{
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct ratbag *ratbag = device->ratbag;
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
int rc, dpi;
|
||||
int rc;
|
||||
unsigned int i;
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_RESOLUTION_2200) {
|
||||
uint16_t resolution;
|
||||
uint8_t flags;
|
||||
|
||||
profile->resolution.num_modes = 1;
|
||||
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 rc;
|
||||
}
|
||||
|
||||
return resolution;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201) {
|
||||
dpi = 0;
|
||||
free(drv_data->sensors);
|
||||
drv_data->sensors = NULL;
|
||||
drv_data->num_sensors = 0;
|
||||
@@ -190,18 +192,30 @@ hidpp20drv_read_resolution_dpi(struct ratbag_device *device)
|
||||
log_error(ratbag,
|
||||
"Error while requesting resolution: %s (%d)\n",
|
||||
strerror(-rc), rc);
|
||||
return 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",
|
||||
drv_data->sensors[0].dpi,
|
||||
drv_data->sensors[0].dpi_min,
|
||||
drv_data->sensors[0].dpi_max);
|
||||
dpi = drv_data->sensors[0].dpi;
|
||||
drv_data->num_sensors = rc;
|
||||
return -ENODEV;
|
||||
}
|
||||
return dpi;
|
||||
log_info(ratbag,
|
||||
"device is at %d dpi (variable between %d and %d).\n",
|
||||
drv_data->sensors[0].dpi,
|
||||
drv_data->sensors[0].dpi_min,
|
||||
drv_data->sensors[0].dpi_max);
|
||||
drv_data->num_sensors = rc;
|
||||
if (drv_data->num_sensors > MAX_RESOLUTIONS)
|
||||
drv_data->num_sensors = MAX_RESOLUTIONS;
|
||||
profile->resolution.num_modes = drv_data->num_sensors;
|
||||
for (i = 0; i < profile->resolution.num_modes; i++) {
|
||||
profile->resolution.modes[i].dpi = drv_data->sensors[i].dpi;
|
||||
/* FIXME: retrieve the refresh rate */
|
||||
profile->resolution.modes[i].hz = 0;
|
||||
/* FIXME: we mark all resolutions as active because
|
||||
* they are from different sensors */
|
||||
profile->resolution.modes[i].is_active = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -295,16 +309,8 @@ static void
|
||||
hidpp20drv_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
{
|
||||
struct ratbag_device *device = profile->device;
|
||||
int dpi;
|
||||
|
||||
|
||||
/* FIXME */
|
||||
#if 0
|
||||
dpi = hidpp20drv_read_resolution_dpi(device);
|
||||
if (dpi > 0)
|
||||
profile->current_dpi = dpi;
|
||||
#endif
|
||||
|
||||
hidpp20drv_read_resolution_dpi(profile);
|
||||
hidpp20drv_read_special_key_mouse(device);
|
||||
}
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@ struct ratbag_driver {
|
||||
|
||||
#define MAX_RESOLUTIONS 10
|
||||
struct ratbag_resolution{
|
||||
struct ratbag_profile *profile;
|
||||
int refcount;
|
||||
void *userdata;
|
||||
unsigned int dpi; /**< resolution on dpi */
|
||||
|
||||
@@ -554,6 +554,7 @@ ratbag_create_profile(struct ratbag_device *device,
|
||||
unsigned int num_buttons)
|
||||
{
|
||||
struct ratbag_profile *profile;
|
||||
unsigned i;
|
||||
|
||||
profile = zalloc(sizeof(*profile));
|
||||
if (!profile)
|
||||
@@ -566,6 +567,9 @@ ratbag_create_profile(struct ratbag_device *device,
|
||||
list_insert(&device->profiles, &profile->link);
|
||||
list_init(&profile->buttons);
|
||||
|
||||
for (i = 0; i < MAX_RESOLUTIONS; i++)
|
||||
profile->resolution.modes[i].profile = profile;
|
||||
|
||||
assert(device->driver->read_profile);
|
||||
device->driver->read_profile(profile, index);
|
||||
|
||||
@@ -743,9 +747,11 @@ LIBRATBAG_EXPORT int
|
||||
ratbag_resolution_set_dpi(struct ratbag_resolution *resolution,
|
||||
unsigned int dpi)
|
||||
{
|
||||
struct ratbag_profile *profile = resolution->profile;
|
||||
resolution->dpi = dpi;
|
||||
/* FIXME: call into the driver */
|
||||
return 0;
|
||||
|
||||
assert(profile->device->driver->write_resolution_dpi);
|
||||
return profile->device->driver->write_resolution_dpi(profile, dpi);
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
|
||||
Reference in New Issue
Block a user