kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

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

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