Blame SOURCES/0001-monitor-config-store-Read-system-wide-config-files.patch

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