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

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