From f476f03762829f667de1059995b6d02e6504a3c3 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 1 Sep 2015 09:47:19 -0400 Subject: [PATCH] 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 --- src/driver-etekcity.c | 3 +-- src/driver-hidpp10.c | 19 ++++++++++--------- src/driver-hidpp20.c | 5 +++-- src/libratbag-private.h | 4 +++- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index a5cd54d5..05d66735 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -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); diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 0845c384..37045e11 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -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; } } diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 5db7dd0b..d651f088 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -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; diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 708195c5..3bb92ce7 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -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