Blame SOURCES/0001-monitor-config-Consider-external-layout-before-defau.patch

67f8b7
From d2cc8089a6fd31e302b23ac787d84ff5a3257b6c Mon Sep 17 00:00:00 2001
d1d875
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
d1d875
Date: Thu, 28 Jan 2016 15:26:33 +0100
d1d875
Subject: [PATCH] monitor-config: Consider external layout before default
d1d875
 linear config
d1d875
d1d875
In case of no existing configuration, we use a default layout of
d1d875
aligning attached displays horizontally. This sidesteps any layout
d1d875
configuration that is done externally, for instance via xorg.conf,
d1d875
which is not desirable. Instead, base the initial configuration on
d1d875
the existing layout if it passes some sanity checks before falling
d1d875
back to the default linear config.
d1d875
---
67f8b7
 src/backends/meta-monitor-config.c | 76 +++++++++++++++++++++++++++++---------
67f8b7
 1 file changed, 59 insertions(+), 17 deletions(-)
d1d875
d1d875
diff --git a/src/backends/meta-monitor-config.c b/src/backends/meta-monitor-config.c
67f8b7
index 21e3126f2..492b0ffe1 100644
d1d875
--- a/src/backends/meta-monitor-config.c
d1d875
+++ b/src/backends/meta-monitor-config.c
67f8b7
@@ -1130,6 +1130,23 @@ init_config_from_preferred_mode (MetaOutputConfig *config,
d1d875
   config->is_presentation = FALSE;
d1d875
 }
d1d875
 
d1d875
+static void
d1d875
+init_config_from_output (MetaOutputConfig *config,
d1d875
+                         MetaOutput       *output)
d1d875
+{
d1d875
+  config->enabled = (output->crtc != NULL);
d1d875
+
d1d875
+  if (!config->enabled)
d1d875
+    return;
d1d875
+
d1d875
+  config->rect = output->crtc->rect;
d1d875
+  config->refresh_rate = output->crtc->current_mode->refresh_rate;
d1d875
+  config->transform = output->crtc->transform;
d1d875
+  config->is_primary = output->is_primary;
d1d875
+  config->is_presentation = output->is_presentation;
67f8b7
+  config->is_underscanning = output->is_underscanning;
d1d875
+}
d1d875
+
d1d875
 /* This function handles configuring the outputs when the driver provides a
d1d875
  * suggested layout position for each output. This is done in recent versions
d1d875
  * of qxl and allows displays to be aligned on the guest in the same order as
67f8b7
@@ -1368,6 +1385,45 @@ extend_stored_config (MetaMonitorConfig *self,
d1d875
   return FALSE;
d1d875
 }
d1d875
 
d1d875
+static gboolean
d1d875
+make_initial_config_from_current (MetaMonitorConfig *self,
d1d875
+                                  MetaOutput        *outputs,
d1d875
+                                  unsigned           n_outputs,
d1d875
+                                  int                max_width,
d1d875
+                                  int                max_height,
d1d875
+                                  MetaConfiguration *config)
d1d875
+{
d1d875
+  GList *region = NULL;
d1d875
+  unsigned i;
d1d875
+
d1d875
+  g_return_val_if_fail (config != NULL, FALSE);
d1d875
+
d1d875
+  if (g_hash_table_size (self->configs) > 0)
d1d875
+    return FALSE;
d1d875
+
d1d875
+  g_assert (config->n_outputs == n_outputs);
d1d875
+
d1d875
+  for (i = 0; i < n_outputs; i++)
d1d875
+    {
d1d875
+      init_config_from_output (&config->outputs[i], &outputs[i]);
d1d875
+
d1d875
+      /* Reject the configuration if the suggested positions result in
d1d875
+       * overlapping displays */
d1d875
+      if (meta_rectangle_overlaps_with_region (region, &config->outputs[i].rect))
d1d875
+        {
d1d875
+          g_warning ("Overlapping outputs, rejecting suggested configuration");
d1d875
+          g_list_free (region);
d1d875
+          return FALSE;
d1d875
+        }
d1d875
+
d1d875
+      region = g_list_prepend (region, &config->outputs[i].rect);
d1d875
+    }
d1d875
+
d1d875
+  g_list_free (region);
d1d875
+
d1d875
+  return TRUE;
d1d875
+}
d1d875
+
d1d875
 static MetaConfiguration *
d1d875
 make_default_config (MetaMonitorConfig *self,
d1d875
                      MetaOutput        *outputs,
67f8b7
@@ -1399,6 +1455,9 @@ make_default_config (MetaMonitorConfig *self,
d1d875
       extend_stored_config (self, outputs, n_outputs, max_width, max_height, ret))
d1d875
       goto check_limits;
d1d875
 
d1d875
+  if (make_initial_config_from_current (self, outputs, n_outputs, max_width, max_height, ret))
d1d875
+      goto check_limits;
d1d875
+
d1d875
   make_linear_config (self, outputs, n_outputs, max_width, max_height, ret);
d1d875
 
d1d875
 check_limits:
67f8b7
@@ -1500,23 +1559,6 @@ meta_monitor_config_make_default (MetaMonitorConfig  *self,
d1d875
     }
d1d875
 }
d1d875
 
d1d875
-static void
d1d875
-init_config_from_output (MetaOutputConfig *config,
d1d875
-                         MetaOutput       *output)
d1d875
-{
d1d875
-  config->enabled = (output->crtc != NULL);
d1d875
-
d1d875
-  if (!config->enabled)
d1d875
-    return;
d1d875
-
d1d875
-  config->rect = output->crtc->rect;
d1d875
-  config->refresh_rate = output->crtc->current_mode->refresh_rate;
d1d875
-  config->transform = output->crtc->transform;
d1d875
-  config->is_primary = output->is_primary;
d1d875
-  config->is_presentation = output->is_presentation;
67f8b7
-  config->is_underscanning = output->is_underscanning;
d1d875
-}
d1d875
-
d1d875
 void
d1d875
 meta_monitor_config_update_current (MetaMonitorConfig  *self,
d1d875
                                     MetaMonitorManager *manager)
d1d875
-- 
67f8b7
2.12.0
d1d875