1
0
Fork 0

monitor-config-store: Save configs after layout mode detection/conversion

We don't want to do the work of the layout mode detection and conversion
every time we read the monitors.xml file.

Instead, when the detection logic is used, set a flag to automatically
update the config files after the parsing is finished.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3596>
This commit is contained in:
Jonas Dreßler 2024-02-16 22:46:44 +01:00 committed by Marge Bot
parent 2c8b383a7e
commit 05cc8a56e1

View file

@ -197,6 +197,7 @@ typedef struct
int unknown_level; int unknown_level;
MetaMonitorsConfigFlag extra_config_flags; MetaMonitorsConfigFlag extra_config_flags;
gboolean should_update_file;
} ConfigParser; } ConfigParser;
G_DEFINE_TYPE (MetaMonitorConfigStore, meta_monitor_config_store, G_DEFINE_TYPE (MetaMonitorConfigStore, meta_monitor_config_store,
@ -1496,6 +1497,8 @@ handle_end_element (GMarkupParseContext *context,
logical_layout_mode_config->key, logical_layout_mode_config->key,
logical_layout_mode_config); logical_layout_mode_config);
} }
parser->should_update_file = TRUE;
} }
else else
{ {
@ -2031,6 +2034,7 @@ read_config_file (MetaMonitorConfigStore *config_store,
GFile *file, GFile *file,
MetaMonitorsConfigFlag extra_config_flags, MetaMonitorsConfigFlag extra_config_flags,
GHashTable **out_configs, GHashTable **out_configs,
gboolean *should_update_file,
GError **error) GError **error)
{ {
char *buffer; char *buffer;
@ -2052,6 +2056,7 @@ read_config_file (MetaMonitorConfigStore *config_store,
.extra_config_flags = extra_config_flags, .extra_config_flags = extra_config_flags,
.unknown_state_root = -1, .unknown_state_root = -1,
.pending_store = -1, .pending_store = -1,
.should_update_file = FALSE
}; };
parse_context = g_markup_parse_context_new (&config_parser, parse_context = g_markup_parse_context_new (&config_parser,
@ -2075,6 +2080,7 @@ read_config_file (MetaMonitorConfigStore *config_store,
} }
*out_configs = g_steal_pointer (&parser.pending_configs); *out_configs = g_steal_pointer (&parser.pending_configs);
*should_update_file = parser.should_update_file;
g_markup_parse_context_free (parse_context); g_markup_parse_context_free (parse_context);
g_free (buffer); g_free (buffer);
@ -2486,6 +2492,7 @@ meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
GError **error) GError **error)
{ {
GHashTable *new_configs = NULL; GHashTable *new_configs = NULL;
gboolean should_save_configs = FALSE;
g_clear_object (&config_store->custom_read_file); g_clear_object (&config_store->custom_read_file);
g_clear_object (&config_store->custom_write_file); g_clear_object (&config_store->custom_write_file);
@ -2503,11 +2510,16 @@ meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
config_store->custom_read_file, config_store->custom_read_file,
config_flags, config_flags,
&new_configs, &new_configs,
&should_save_configs,
error)) error))
return FALSE; return FALSE;
g_clear_pointer (&config_store->configs, g_hash_table_unref); g_clear_pointer (&config_store->configs, g_hash_table_unref);
config_store->configs = g_steal_pointer (&new_configs); config_store->configs = g_steal_pointer (&new_configs);
if (should_save_configs)
maybe_save_configs (config_store);
return TRUE; return TRUE;
} }
@ -2662,6 +2674,7 @@ meta_monitor_config_store_reset (MetaMonitorConfigStore *config_store)
const char * const *system_dirs; const char * const *system_dirs;
char *user_file_path; char *user_file_path;
GError *error = NULL; GError *error = NULL;
gboolean should_save_configs = FALSE;
g_clear_object (&config_store->user_file); g_clear_object (&config_store->user_file);
g_clear_object (&config_store->custom_read_file); g_clear_object (&config_store->custom_read_file);
@ -2684,12 +2697,22 @@ meta_monitor_config_store_reset (MetaMonitorConfigStore *config_store)
system_file, system_file,
META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG, META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG,
&system_configs, &system_configs,
&should_save_configs,
&error)) &error))
{ {
g_warning ("Failed to read monitors config file '%s': %s", g_warning ("Failed to read monitors config file '%s': %s",
system_file_path, error->message); system_file_path, error->message);
g_clear_error (&error); g_clear_error (&error);
} }
if (should_save_configs)
{
g_warning ("System monitor configuration file (%s) needs "
"updating; ask your administrator to migrate "
"the system monitor configuration.",
system_file_path);
should_save_configs = FALSE;
}
} }
} }
@ -2704,6 +2727,7 @@ meta_monitor_config_store_reset (MetaMonitorConfigStore *config_store)
config_store->user_file, config_store->user_file,
META_MONITORS_CONFIG_FLAG_NONE, META_MONITORS_CONFIG_FLAG_NONE,
&user_configs, &user_configs,
&should_save_configs,
&error)) &error))
{ {
g_warning ("Failed to read monitors config file '%s': %s", g_warning ("Failed to read monitors config file '%s': %s",
@ -2740,6 +2764,8 @@ meta_monitor_config_store_reset (MetaMonitorConfigStore *config_store)
replace_configs (config_store, user_configs); replace_configs (config_store, user_configs);
} }
if (should_save_configs)
maybe_save_configs (config_store);
g_free (user_file_path); g_free (user_file_path);
} }