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.
This commit is contained in:
Thomas Hindoe Paaboel Andersen
2016-10-27 02:43:51 +02:00
committed by Peter Hutterer
parent 27a141fd87
commit adefb2921b

View File

@@ -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;