forked from drath/libratbag
hidpp10: only update current resolution once per commit
With the swtich to the commit style the function hidpp10drv_write_resolution_dpi is doing too much work. Before commit style the function would: * get the profile * get the current resolution * write the profile (resets it to default dpi) * set the current (updated) resolution With the commit style we call the function for every resolution in every dirty profile we now: * get the current resolution * set the current (updated) resolution Then later: * write the profile (resets to default dpi) This patch changes this to only doing one set of the current resolution when the active profile has been written. This reduces the traffic to the device and sets the current resolution after the profile write.
This commit is contained in:
committed by
Thomas H. P. Andersen
parent
43f501907e
commit
cd71ce67b1
@@ -409,40 +409,6 @@ hidpp10drv_write_profile(struct ratbag_profile *profile)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp10drv_write_resolution_dpi(struct hidpp10_profile *p,
|
||||
struct ratbag_resolution *resolution,
|
||||
int dpi_x, int dpi_y)
|
||||
{
|
||||
struct ratbag_profile *profile = resolution->profile;
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct hidpp10drv_data *drv_data = ratbag_get_drv_data(device);
|
||||
struct hidpp10_device *hidpp10 = drv_data->dev;
|
||||
unsigned int index;
|
||||
uint16_t cur_dpi_x, cur_dpi_y;
|
||||
int rc;
|
||||
|
||||
/* store the current resolution */
|
||||
rc = hidpp10_get_current_resolution(hidpp10, &cur_dpi_x, &cur_dpi_y);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
if (resolution->is_active) {
|
||||
/* we need to switch to the new resolution */
|
||||
cur_dpi_x = dpi_x;
|
||||
cur_dpi_y = dpi_y;
|
||||
}
|
||||
|
||||
/* retrieve which resolution is asked to be changed */
|
||||
index = resolution - profile->resolution.modes;
|
||||
|
||||
p->dpi_modes[index].xres = dpi_x;
|
||||
p->dpi_modes[index].yres = dpi_y;
|
||||
|
||||
/* restore the current setting */
|
||||
return hidpp10_set_current_resolution(hidpp10, cur_dpi_x, cur_dpi_y);
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device *dev)
|
||||
{
|
||||
@@ -507,6 +473,7 @@ hidpp10drv_commit(struct ratbag_device *device)
|
||||
struct ratbag_profile *profile;
|
||||
struct ratbag_button *button;
|
||||
struct ratbag_resolution *resolution;
|
||||
struct ratbag_resolution *active_resolution = NULL;
|
||||
struct hidpp10_profile p;
|
||||
int rc;
|
||||
unsigned int i;
|
||||
@@ -524,12 +491,11 @@ hidpp10drv_commit(struct ratbag_device *device)
|
||||
for (i = 0; i < profile->resolution.num_modes; i++) {
|
||||
resolution = &profile->resolution.modes[i];
|
||||
|
||||
rc = hidpp10drv_write_resolution_dpi(&p,
|
||||
resolution,
|
||||
resolution->dpi_x,
|
||||
resolution->dpi_y);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
p.dpi_modes[i].xres = resolution->dpi_x;
|
||||
p.dpi_modes[i].yres = resolution->dpi_y;
|
||||
|
||||
if (profile->is_active && resolution->is_active)
|
||||
active_resolution = resolution;
|
||||
}
|
||||
|
||||
list_for_each(button, &profile->buttons, link) {
|
||||
@@ -548,6 +514,17 @@ hidpp10drv_commit(struct ratbag_device *device)
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
}
|
||||
|
||||
/* Update the current resolution in case it changed */
|
||||
if (active_resolution) {
|
||||
rc = hidpp10_set_current_resolution(dev,
|
||||
active_resolution->dpi_x,
|
||||
active_resolution->dpi_y);
|
||||
if (rc)
|
||||
return RATBAG_ERROR_DEVICE;
|
||||
|
||||
active_resolution = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return RATBAG_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user