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