Blame SOURCES/0001-monitor-manager-Consider-external-layout-before-defa.patch

f73620
From 648f1ce9350fcab0ebaecccb115b5021c632e7b5 Mon Sep 17 00:00:00 2001
f73620
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
f73620
Date: Thu, 28 Jan 2016 15:26:33 +0100
f73620
Subject: [PATCH] monitor-manager: Consider external layout before default
f73620
 linear config
f73620
f73620
In case of no existing configuration, we use a default layout of
f73620
aligning attached displays horizontally. This sidesteps any layout
f73620
configuration that is done externally, for instance via xorg.conf,
f73620
which is not desirable. Instead, base the initial configuration on
f73620
the existing layout if it passes some sanity checks before falling
f73620
back to the default linear config.
f73620
---
f73620
 src/backends/meta-monitor-config-manager.c | 75 ++++++++++++++++++++++
f73620
 src/backends/meta-monitor-config-manager.h |  1 +
f73620
 src/backends/meta-monitor-manager.c        | 19 ++++++++
f73620
 3 files changed, 97 insertions(+)
f73620
f73620
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
f73620
index 197892bf2..ae988f64a 100644
f73620
--- a/src/backends/meta-monitor-config-manager.c
f73620
+++ b/src/backends/meta-monitor-config-manager.c
f73620
@@ -559,6 +559,83 @@ create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_ma
f73620
   return logical_monitor_config;
f73620
 }
f73620
 
f73620
+static MetaLogicalMonitorConfig *
f73620
+create_logical_monitor_config_from_output (MetaMonitorManager           *monitor_manager,
f73620
+                                           MetaMonitor                  *monitor,
f73620
+                                           MetaLogicalMonitorConfig     *primary_logical_monitor_config,
f73620
+                                           MetaLogicalMonitorLayoutMode  layout_mode)
f73620
+{
f73620
+    MetaOutput *output;
f73620
+    MetaCrtc *crtc;
f73620
+
f73620
+    output = meta_monitor_get_main_output (monitor);
f73620
+    crtc = meta_output_get_assigned_crtc (output);
f73620
+    return create_preferred_logical_monitor_config (monitor_manager,
f73620
+                                                    monitor,
f73620
+                                                    crtc->rect.x,
f73620
+                                                    crtc->rect.y,
f73620
+                                                    primary_logical_monitor_config,
f73620
+                                                    layout_mode);
f73620
+}
f73620
+
f73620
+MetaMonitorsConfig *
f73620
+meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager)
f73620
+{
f73620
+  MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
f73620
+  GList *logical_monitor_configs;
f73620
+  MetaMonitor *primary_monitor;
f73620
+  MetaLogicalMonitorLayoutMode layout_mode;
f73620
+  MetaLogicalMonitorConfig *primary_logical_monitor_config;
f73620
+  GList *monitors;
f73620
+  GList *l;
f73620
+
f73620
+  if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
f73620
+    return NULL;
f73620
+
f73620
+  primary_monitor = find_primary_monitor (monitor_manager);
f73620
+  if (!primary_monitor || !meta_monitor_is_active (primary_monitor))
f73620
+    return NULL;
f73620
+
f73620
+  layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
f73620
+
f73620
+  primary_logical_monitor_config =
f73620
+    create_logical_monitor_config_from_output (monitor_manager,
f73620
+                                               primary_monitor,
f73620
+                                               NULL,
f73620
+                                               layout_mode);
f73620
+
f73620
+  primary_logical_monitor_config->is_primary = TRUE;
f73620
+  logical_monitor_configs = g_list_append (NULL,
f73620
+                                           primary_logical_monitor_config);
f73620
+
f73620
+  monitors = meta_monitor_manager_get_monitors (monitor_manager);
f73620
+  for (l = monitors; l; l = l->next)
f73620
+    {
f73620
+      MetaMonitor *monitor = l->data;
f73620
+      MetaLogicalMonitorConfig *logical_monitor_config;
f73620
+
f73620
+      if (monitor == primary_monitor)
f73620
+        continue;
f73620
+
f73620
+      if (!meta_monitor_is_active (monitor))
f73620
+        continue;
f73620
+
f73620
+      logical_monitor_config =
f73620
+        create_logical_monitor_config_from_output (monitor_manager,
f73620
+                                                   monitor,
f73620
+                                                   primary_logical_monitor_config,
f73620
+                                                   layout_mode);
f73620
+
f73620
+      logical_monitor_configs = g_list_append (logical_monitor_configs,
f73620
+                                               logical_monitor_config);
f73620
+    }
f73620
+
f73620
+  return meta_monitors_config_new (monitor_manager,
f73620
+                                   logical_monitor_configs,
f73620
+                                   layout_mode,
f73620
+                                   META_MONITORS_CONFIG_FLAG_NONE);
f73620
+}
f73620
+
f73620
 MetaMonitorsConfig *
f73620
 meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager)
f73620
 {
f73620
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
f73620
index 269d8e1b7..c36df38e6 100644
f73620
--- a/src/backends/meta-monitor-config-manager.h
f73620
+++ b/src/backends/meta-monitor-config-manager.h
f73620
@@ -87,6 +87,7 @@ gboolean meta_monitor_config_manager_assign (MetaMonitorManager *manager,
f73620
 
f73620
 MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager);
f73620
 
f73620
+MetaMonitorsConfig * meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager);
f73620
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
f73620
 
f73620
 MetaMonitorsConfig * meta_monitor_config_manager_create_fallback (MetaMonitorConfigManager *config_manager);
f73620
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
f73620
index 0b5e54c48..263e93941 100644
f73620
--- a/src/backends/meta-monitor-manager.c
f73620
+++ b/src/backends/meta-monitor-manager.c
f73620
@@ -576,6 +576,25 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
f73620
       g_clear_object (&config);
f73620
     }
f73620
 
f73620
+  config = meta_monitor_config_manager_create_current (manager->config_manager);
f73620
+  if (config)
f73620
+    {
f73620
+      if (!meta_monitor_manager_apply_monitors_config (manager,
f73620
+                                                       config,
f73620
+                                                       method,
f73620
+                                                       &error))
f73620
+        {
f73620
+          g_clear_object (&config);
f73620
+          g_warning ("Failed to use current monitor configuration: %s",
f73620
+                     error->message);
f73620
+          g_clear_error (&error);
f73620
+        }
f73620
+      else
f73620
+        {
f73620
+          goto done;
f73620
+        }
f73620
+    }
f73620
+
f73620
   config = meta_monitor_config_manager_create_linear (manager->config_manager);
f73620
   if (config)
f73620
     {
f73620
-- 
f73620
2.17.1
f73620