mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
make ratbag_resolution_init() return the struct resolution pointer
It is a common pattern to have: ratbag_resolution_init(...) profile->resolution.modes[i].xxx = yyy; ratbag_resolution_set_cap(&profile->resolution.modes[i], zzz) So instead of dealing with the internal fields of profile/resolution/modes, just return the resolution that has been initialized. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -489,7 +489,6 @@ etekcity_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
profile->resolution.num_modes = ETEKCITY_NUM_DPI;
|
||||
|
||||
for (i = 0; i < ETEKCITY_NUM_DPI; i++) {
|
||||
resolution = &profile->resolution.modes[i];
|
||||
dpi_x = setting_report->xres[i] * 50;
|
||||
dpi_y = setting_report->yres[i] * 50;
|
||||
hz = report_rate;
|
||||
@@ -499,7 +498,7 @@ etekcity_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
resolution->dpi_y = 0;
|
||||
resolution->hz = 0;
|
||||
}
|
||||
ratbag_resolution_init(profile, i, dpi_x, dpi_y, hz);
|
||||
resolution = ratbag_resolution_init(profile, i, dpi_x, dpi_y, hz);
|
||||
ratbag_resolution_set_cap(resolution,
|
||||
RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION);
|
||||
resolution->is_active = (i == setting_report->current_dpi);
|
||||
|
||||
@@ -118,6 +118,7 @@ hidpp10drv_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
struct hidpp10drv_data *drv_data;
|
||||
struct hidpp10_device *hidpp10;
|
||||
struct hidpp10_profile p;
|
||||
struct ratbag_resolution *res;
|
||||
int rc;
|
||||
unsigned int i;
|
||||
uint16_t xres, yres;
|
||||
@@ -139,18 +140,18 @@ hidpp10drv_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
|
||||
profile->resolution.num_modes = p.num_dpi_modes;
|
||||
for (i = 0; i < p.num_dpi_modes; i++) {
|
||||
ratbag_resolution_init(profile, i,
|
||||
p.dpi_modes[i].xres,
|
||||
p.dpi_modes[i].yres,
|
||||
p.refresh_rate);
|
||||
ratbag_resolution_set_cap(&profile->resolution.modes[i],
|
||||
res = ratbag_resolution_init(profile, i,
|
||||
p.dpi_modes[i].xres,
|
||||
p.dpi_modes[i].yres,
|
||||
p.refresh_rate);
|
||||
ratbag_resolution_set_cap(res,
|
||||
RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION);
|
||||
if (profile->is_active &&
|
||||
profile->resolution.modes[i].dpi_x == xres &&
|
||||
profile->resolution.modes[i].dpi_y == yres)
|
||||
profile->resolution.modes[i].is_active = true;
|
||||
res->dpi_x == xres &&
|
||||
res->dpi_y == yres)
|
||||
res->is_active = true;
|
||||
if (i == p.default_dpi_mode)
|
||||
profile->resolution.modes[i].is_default = true;
|
||||
res->is_default = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,6 +165,7 @@ 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);
|
||||
struct ratbag_resolution *res;
|
||||
int rc;
|
||||
unsigned int i;
|
||||
|
||||
@@ -210,11 +211,11 @@ hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile)
|
||||
for (i = 0; i < profile->resolution.num_modes; i++) {
|
||||
int dpi = drv_data->sensors[i].dpi;
|
||||
/* FIXME: retrieve the refresh rate */
|
||||
ratbag_resolution_init(profile, i, dpi, dpi, 0);
|
||||
res = ratbag_resolution_init(profile, i, dpi, dpi, 0);
|
||||
|
||||
/* FIXME: we mark all resolutions as active because
|
||||
* they are from different sensors */
|
||||
profile->resolution.modes[i].is_active = true;
|
||||
res->is_active = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -312,7 +312,7 @@ ratbag_button_action_match(const struct ratbag_button_action *action,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
static inline struct ratbag_resolution *
|
||||
ratbag_resolution_init(struct ratbag_profile *profile, int index,
|
||||
int dpi_x, int dpi_y, int hz)
|
||||
{
|
||||
@@ -325,6 +325,8 @@ ratbag_resolution_init(struct ratbag_profile *profile, int index,
|
||||
res->is_active = false;
|
||||
res->is_default = false;
|
||||
res->capabilities = 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
||||
Reference in New Issue
Block a user