diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index dbbe378c..d369288e 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -500,14 +500,16 @@ etekcity_read_profile(struct ratbag_profile *profile, unsigned int index) dpi_list = setting_report->xres; for (i = 0; i < ETEKCITY_NUM_DPI; i++) { + int dpi, hz; resolution = &profile->resolution.modes[i]; - resolution->dpi = dpi_list[i] * 50; - resolution->hz = report_rate; + dpi = dpi_list[i] * 50; + hz = report_rate; if (!(setting_report->dpi_mask & (1 << i))) { /* the profile is disabled, overwrite it */ resolution->dpi = 0; resolution->hz = 0; } + ratbag_resolution_init(profile, i, dpi,hz); resolution->is_active = (i == setting_report->current_dpi); } diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 858a9107..269f6fad 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -139,9 +139,8 @@ 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++) { /* FIXME: we should expose x/y res separately */ - profile->resolution.modes[i].dpi = p.dpi_modes[i].xres; - profile->resolution.modes[i].hz = p.refresh_rate; - profile->resolution.modes[i].is_active = false; + ratbag_resolution_init(profile, i, p.dpi_modes[i].xres, + p.refresh_rate); if (profile->is_active && profile->resolution.modes[i].dpi == xres) profile->resolution.modes[i].is_active = true; if (i == p.default_dpi_mode) diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index 357cccb4..3c27c167 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -207,9 +207,9 @@ hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile) 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; + ratbag_resolution_init(profile, i, drv_data->sensors[i].dpi, 0); + /* FIXME: we mark all resolutions as active because * they are from different sensors */ profile->resolution.modes[i].is_active = true; diff --git a/src/libratbag-private.h b/src/libratbag-private.h index f14a02f9..b0e98266 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -307,6 +307,18 @@ ratbag_button_action_match(const struct ratbag_button_action *action, return 0; } +static inline void +ratbag_resolution_init(struct ratbag_profile *profile, int index, int dpi, int hz) +{ + struct ratbag_resolution *res = &profile->resolution.modes[index]; + + res->profile = profile; + res->dpi = dpi; + res->hz = hz; + res->is_active = false; + res->is_default = false; +} + /** * Override the auto-picked hidraw device. */ diff --git a/src/libratbag.c b/src/libratbag.c index d5acb7a6..470ed094 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -568,7 +568,7 @@ ratbag_create_profile(struct ratbag_device *device, list_init(&profile->buttons); for (i = 0; i < MAX_RESOLUTIONS; i++) - profile->resolution.modes[i].profile = profile; + ratbag_resolution_init(profile, i, 0, 0); assert(device->driver->read_profile); device->driver->read_profile(profile, index);