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

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