[mutter] monitor-config-store: Read system wide config files
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] monitor-config-store: Read system wide config files
- Date: Tue, 26 Feb 2019 21:11:13 +0000 (UTC)
commit 9e75ce2ad73dca884d9de6f117088cce0b2fad94
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Fri Oct 5 18:52:03 2018 +0200
monitor-config-store: Read system wide config files
Before introducing the new config store, the old monitor configuration
system read system wide monitor configuration files. Add back that
feature.
https://gitlab.gnome.org/GNOME/mutter/merge_requests/253
src/backends/meta-monitor-config-manager.h | 1 +
src/backends/meta-monitor-config-store.c | 72 ++++++++++++++++++++++++++----
2 files changed, 65 insertions(+), 8 deletions(-)
---
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
index 771176eba..3875e04e9 100644
--- a/src/backends/meta-monitor-config-manager.h
+++ b/src/backends/meta-monitor-config-manager.h
@@ -55,6 +55,7 @@ typedef enum _MetaMonitorsConfigFlag
{
META_MONITORS_CONFIG_FLAG_NONE = 0,
META_MONITORS_CONFIG_FLAG_MIGRATED = (1 << 0),
+ META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG = (1 << 1),
} MetaMonitorsConfigFlag;
struct _MetaMonitorsConfig
diff --git a/src/backends/meta-monitor-config-store.c b/src/backends/meta-monitor-config-store.c
index ed0ce34f0..770bef734 100644
--- a/src/backends/meta-monitor-config-store.c
+++ b/src/backends/meta-monitor-config-store.c
@@ -179,6 +179,8 @@ typedef struct
MetaMonitorConfig *current_monitor_config;
MetaLogicalMonitorConfig *current_logical_monitor_config;
GList *current_disabled_monitor_specs;
+
+ MetaMonitorsConfigFlag extra_config_flags;
} ConfigParser;
G_DEFINE_TYPE (MetaMonitorConfigStore, meta_monitor_config_store,
@@ -766,6 +768,8 @@ handle_end_element (GMarkupParseContext *context,
if (parser->current_was_migrated)
config_flags |= META_MONITORS_CONFIG_FLAG_MIGRATED;
+ config_flags |= parser->extra_config_flags;
+
config =
meta_monitors_config_new_full (parser->current_logical_monitor_configs,
parser->current_disabled_monitor_specs,
@@ -1078,9 +1082,10 @@ static const GMarkupParser config_parser = {
};
static gboolean
-read_config_file (MetaMonitorConfigStore *config_store,
- GFile *file,
- GError **error)
+read_config_file (MetaMonitorConfigStore *config_store,
+ GFile *file,
+ MetaMonitorsConfigFlag extra_config_flags,
+ GError **error)
{
char *buffer;
gsize size;
@@ -1092,7 +1097,8 @@ read_config_file (MetaMonitorConfigStore *config_store,
parser = (ConfigParser) {
.state = STATE_INITIAL,
- .config_store = config_store
+ .config_store = config_store,
+ .extra_config_flags = extra_config_flags,
};
parse_context = g_markup_parse_context_new (&config_parser,
@@ -1274,6 +1280,9 @@ generate_config_xml (MetaMonitorConfigStore *config_store)
{
GList *l;
+ if (config->flags & META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG)
+ continue;
+
g_string_append (buffer, " <configuration>\n");
if (config->flags & META_MONITORS_CONFIG_FLAG_MIGRATED)
@@ -1425,6 +1434,12 @@ maybe_save_configs (MetaMonitorConfigStore *config_store)
meta_monitor_config_store_save (config_store);
}
+static gboolean
+is_system_config (MetaMonitorsConfig *config)
+{
+ return !!(config->flags & META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG);
+}
+
void
meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
MetaMonitorsConfig *config)
@@ -1432,7 +1447,8 @@ meta_monitor_config_store_add (MetaMonitorConfigStore *config_store,
g_hash_table_replace (config_store->configs,
config->key, g_object_ref (config));
- maybe_save_configs (config_store);
+ if (!is_system_config (config))
+ maybe_save_configs (config_store);
}
void
@@ -1441,7 +1457,8 @@ meta_monitor_config_store_remove (MetaMonitorConfigStore *config_store,
{
g_hash_table_remove (config_store->configs, config->key);
- maybe_save_configs (config_store);
+ if (!is_system_config (config))
+ maybe_save_configs (config_store);
}
gboolean
@@ -1458,7 +1475,10 @@ meta_monitor_config_store_set_custom (MetaMonitorConfigStore *config_store,
if (write_path)
config_store->custom_write_file = g_file_new_for_path (write_path);
- return read_config_file (config_store, config_store->custom_read_file, error);
+ return read_config_file (config_store,
+ config_store->custom_read_file,
+ META_MONITORS_CONFIG_FLAG_NONE,
+ error);
}
int
@@ -1485,9 +1505,42 @@ static void
meta_monitor_config_store_constructed (GObject *object)
{
MetaMonitorConfigStore *config_store = META_MONITOR_CONFIG_STORE (object);
+ const char * const *system_dirs;
char *user_file_path;
GError *error = NULL;
+ for (system_dirs = g_get_system_config_dirs ();
+ system_dirs && *system_dirs;
+ system_dirs++)
+ {
+ g_autofree char *system_file_path = NULL;
+
+ system_file_path = g_build_filename (*system_dirs, "monitors.xml", NULL);
+ if (g_file_test (system_file_path, G_FILE_TEST_EXISTS))
+ {
+ g_autoptr (GFile) system_file = NULL;
+
+ system_file = g_file_new_for_path (system_file_path);
+ if (!read_config_file (config_store,
+ system_file,
+ META_MONITORS_CONFIG_FLAG_SYSTEM_CONFIG,
+ &error))
+ {
+ if (g_error_matches (error,
+ META_MONITOR_CONFIG_STORE_ERROR,
+ META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION))
+ g_warning ("System monitor configuration file (%s) is "
+ "incompatible; ask your administrator to migrate "
+ "the system monitor configuation.",
+ system_file_path);
+ else
+ g_warning ("Failed to read monitors config file '%s': %s",
+ system_file_path, error->message);
+ g_clear_error (&error);
+ }
+ }
+ }
+
user_file_path = g_build_filename (g_get_user_config_dir (),
"monitors.xml",
NULL);
@@ -1495,7 +1548,10 @@ meta_monitor_config_store_constructed (GObject *object)
if (g_file_test (user_file_path, G_FILE_TEST_EXISTS))
{
- if (!read_config_file (config_store, config_store->user_file, &error))
+ if (!read_config_file (config_store,
+ config_store->user_file,
+ META_MONITORS_CONFIG_FLAG_NONE,
+ &error))
{
if (error->domain == META_MONITOR_CONFIG_STORE_ERROR &&
error->code == META_MONITOR_CONFIG_STORE_ERROR_NEEDS_MIGRATION)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]