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

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