From b1850b5c8abdeaf12b68ebc88b96ca047f7f1a98 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 19 Apr 2023 15:19:56 -0400 Subject: background: Clear out dconf if user picks defaults If a user chooses the default background in control-center, then they still end up with a change in dconf. This change means that on upgrades, they'll keep the old distro background configured. That's probably unexpected and may lead them to believe the upgrade didn't work. This commit checks if the user goes back to the distro defaults and clears out dconf in that case, so that when the disto defaults change they get the new defaults. --- panels/background/cc-background-panel.c | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c index 12f1e64d1..de6c843dc 100644 --- a/panels/background/cc-background-panel.c +++ b/panels/background/cc-background-panel.c @@ -268,6 +268,54 @@ create_save_dir (void) return TRUE; } +static void +reset_settings_if_defaults (CcBackgroundPanel *panel, + GSettings *settings, + gboolean check_dark) +{ + gsize i; + const char *keys[] = { + WP_URI_KEY, /* this key needs to be first */ + WP_URI_DARK_KEY, + WP_OPTIONS_KEY, + WP_SHADING_KEY, + WP_PCOLOR_KEY, + WP_SCOLOR_KEY, + NULL + }; + + for (i = 0; keys[i] != NULL; i++) + { + g_autoptr (GVariant) default_value = NULL; + g_autoptr (GVariant) user_value = NULL; + gboolean setting_is_default; + + if (!check_dark && g_str_equal (keys[i], WP_URI_DARK_KEY)) + continue; + + default_value = g_settings_get_default_value (settings, keys[i]); + user_value = g_settings_get_value (settings, keys[i]); + + setting_is_default = g_variant_equal (default_value, user_value); + + /* As a courtesy to distros that are a little lackadaisical about making sure + * schema defaults match the settings in the background item with the default + * picture, we only look at the URI to determine if we shouldn't clean out dconf. + * + * In otherwords, we still clean out the picture-uri key from dconf when a user + * selects the default background in control-center, even if after selecting it + * e.g., primary-color still mismatches with schema defaults. + */ + if (g_str_equal (keys[i], WP_URI_KEY) && !setting_is_default) + return; + + if (setting_is_default) + g_settings_reset (settings, keys[i]); + } + + g_settings_apply (settings); +} + static void set_background (CcBackgroundPanel *panel, GSettings *settings, @@ -320,6 +368,9 @@ set_background (CcBackgroundPanel *panel, /* Apply all changes */ g_settings_apply (settings); + /* Clean out dconf if the user went back to distro defaults */ + reset_settings_if_defaults (panel, settings, set_dark); + /* Save the source XML if there is one */ filename = get_save_path (); if (create_save_dir ()) -- cgit v1.2.1