From adefb2921b19405f0cb9482b25b3a829b540209d Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Thu, 27 Oct 2016 02:43:51 +0200 Subject: [PATCH] unset previous default resolution Make sure that there can only be one resolution marked as default. The previous code allowed to set multiple resolutions as default. To clean up any bad state we allways loop all other resolutions and unset the default if neccesary. --- src/libratbag.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libratbag.c b/src/libratbag.c index 981347f7..6aa74076 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -1011,9 +1011,23 @@ ratbag_resolution_is_default(const struct ratbag_resolution *resolution) LIBRATBAG_EXPORT enum ratbag_error_code ratbag_resolution_set_default(struct ratbag_resolution *resolution) { + struct ratbag_profile *profile = resolution->profile; + unsigned int i; + + /* Unset the default on the other resolutions */ + for (i = 0; i < profile->resolution.num_modes; i++) { + struct ratbag_resolution *other = &profile->resolution.modes[i]; + + if (other == resolution || !other->is_default) + continue; + + other->is_default = false; + profile->dirty = true; + } + if (!resolution->is_default) { - resolution->profile->dirty = true; resolution->is_default = true; + profile->dirty = true; } return RATBAG_SUCCESS;