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

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