diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index b732583f..dd06a24b 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -148,6 +148,8 @@ hidpp10drv_read_profile(struct ratbag_profile *profile, unsigned int index) * active profile */ if (profile->resolution.modes[i].dpi == xres) profile->resolution.modes[i].is_active = true; + if (i == p.default_dpi_mode) + profile->resolution.modes[i].is_default = true; } } diff --git a/src/libratbag-private.h b/src/libratbag-private.h index ea44ce37..68e6d7da 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -187,6 +187,7 @@ struct ratbag_resolution{ unsigned int dpi; /**< resolution on dpi */ unsigned int hz; /**< report rate in Hz */ bool is_active; + bool is_default; }; struct ratbag_profile { diff --git a/src/libratbag.c b/src/libratbag.c index 7e4de53e..ead5fe4d 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -787,6 +787,20 @@ ratbag_resolution_set_active(struct ratbag_resolution *resolution) } +LIBRATBAG_EXPORT int +ratbag_resolution_is_default(const struct ratbag_resolution *resolution) +{ + return resolution->is_default; +} + +LIBRATBAG_EXPORT int +ratbag_resolution_set_default(struct ratbag_resolution *resolution) +{ + resolution->is_default = true; + /* FIXME: call into the driver */ + return 0; +} + LIBRATBAG_EXPORT struct ratbag_button* ratbag_profile_get_button_by_index(struct ratbag_profile *profile, unsigned int index) diff --git a/src/libratbag.h b/src/libratbag.h index 2a615ddd..e4104ab5 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -593,9 +593,8 @@ ratbag_resolution_get_report_rate(struct ratbag_resolution *resolution); * Activate the given resolution mode. If the mode is not configured, this * function returns an error and the result is undefined. * - * If the profile is the currently active profile, the change takes effect - * immediately. Otherwise, the resolution mode will be the active mode when - * the device switches to the profile next. + * The mode must be one of the current profile, otherwise an error is + * returned. * * @param resolution A previously initialized ratbag resolution * @@ -610,8 +609,7 @@ ratbag_resolution_set_active(struct ratbag_resolution *resolution); * Check if the resolution mode is the currently active one. * * If the profile is the currently active profile, the mode is the one - * currently active. Otherwise, the resolution mode is the one used when - * the device switches to the profile next. + * currently active. For profiles not currently active, this always returns 0. * * @param resolution A previously initialized ratbag resolution * @@ -621,6 +619,41 @@ ratbag_resolution_set_active(struct ratbag_resolution *resolution); int ratbag_resolution_is_active(const struct ratbag_resolution *resolution); +/** + * @ingroup resolution + * + * Set the default resolution mode for the associated profile. When the + * device switches to the profile next, this mode will be the active + * resolution. If the mode is not configured, this function returns an error + * and the result is undefined. + * + * This only switches the default resolution, not the currently active + * resolution. Use ratbag_resolution_set_active() instead. + * + * @param resolution A previously initialized ratbag resolution + * + * @return zero on success, non-zero otherwise + */ +int +ratbag_resolution_set_default(struct ratbag_resolution *resolution); + +/** + * @ingroup resolution + * + * Check if the resolution mode is the default one in this profile. + * + * The default resolution is the one the device selects when switching to + * the corresponding profile. It may not be the currently active resolution, + * use ratbag_resolution_is_active() instead. + * + * @param resolution A previously initialized ratbag resolution + * + * @return Non-zero if the resolution mode is the default one, zero + * otherwise. + */ +int +ratbag_resolution_is_default(const struct ratbag_resolution *resolution); + /** * @ingroup profile * diff --git a/src/libratbag.sym b/src/libratbag.sym index 272b0d2d..4af0f96b 100644 --- a/src/libratbag.sym +++ b/src/libratbag.sym @@ -43,8 +43,10 @@ global: ratbag_resolution_get_report_rate; ratbag_resolution_get_user_data; ratbag_resolution_is_active; + ratbag_resolution_is_default; ratbag_resolution_ref; ratbag_resolution_set_active; + ratbag_resolution_set_default; ratbag_resolution_set_dpi; ratbag_resolution_set_report_rate; ratbag_resolution_set_user_data; diff --git a/tools/ratbag-command.c b/tools/ratbag-command.c index e766a2db..525a3c97 100644 --- a/tools/ratbag-command.c +++ b/tools/ratbag-command.c @@ -330,8 +330,9 @@ ratbag_cmd_info(struct ratbag *ratbag, uint32_t flags, int argc, char **argv) res = ratbag_profile_get_resolution(profile, j); dpi = ratbag_resolution_get_dpi(res); rate = ratbag_resolution_get_report_rate(res); - printf(" %d: %ddpi @ %dHz%s\n", i, dpi, rate, - ratbag_resolution_is_active(res) ? " (active)" : ""); + printf(" %d: %ddpi @ %dHz%s%s\n", i, dpi, rate, + ratbag_resolution_is_active(res) ? " (active)" : "", + ratbag_resolution_is_default(res) ? " (default)" : ""); ratbag_resolution_unref(res); }