Blame SOURCES/x11-monitor-configuration-patches.patch

1a7f9f
From 9c7c46384ec5e64fbfad84366c93ece52aabd26a Mon Sep 17 00:00:00 2001
1a7f9f
From: Rui Matos <tiagomatos@gmail.com>
1a7f9f
Date: Tue, 6 Oct 2015 21:16:18 +0200
1a7f9f
Subject: [PATCH 1/9] monitor-manager-xrandr: Work around spurious hotplugs on
1a7f9f
 Xvnc
1a7f9f
1a7f9f
Xvnc turns its outputs off/on on every mode set which makes us believe
1a7f9f
there was an hotplug when there actually wasn't. Work around this by
1a7f9f
requiring new randr configuration timestamps to be ahead of the last
1a7f9f
set timestamp by at least 100 ms for us to consider them an actual
1a7f9f
hotplug.
1a7f9f
---
1a7f9f
 .../x11/meta-monitor-manager-xrandr.c         | 21 ++++++++++++++++++-
1a7f9f
 1 file changed, 20 insertions(+), 1 deletion(-)
1a7f9f
1a7f9f
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
index 489a9b4241..1ddc2a7870 100644
1a7f9f
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
@@ -1100,6 +1100,20 @@ meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass)
1a7f9f
     g_quark_from_static_string ("-meta-monitor-xrandr-data");
1a7f9f
 }
1a7f9f
 
1a7f9f
+static gboolean
1a7f9f
+is_xvnc (MetaMonitorManager *manager)
1a7f9f
+{
1a7f9f
+  MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
1a7f9f
+  MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
1a7f9f
+  GList *l;
1a7f9f
+
1a7f9f
+  for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
1a7f9f
+    if (g_str_has_prefix (meta_output_get_name (l->data), "VNC-"))
1a7f9f
+      return TRUE;
1a7f9f
+
1a7f9f
+  return FALSE;
1a7f9f
+}
1a7f9f
+
1a7f9f
 gboolean
1a7f9f
 meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
1a7f9f
 					   XEvent                   *event)
1a7f9f
@@ -1110,6 +1124,7 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
1a7f9f
   XRRScreenResources *resources;
1a7f9f
   gboolean is_hotplug;
1a7f9f
   gboolean is_our_configuration;
1a7f9f
+  unsigned int timestamp;
1a7f9f
 
1a7f9f
   if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
1a7f9f
     return FALSE;
1a7f9f
@@ -1121,7 +1136,11 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
1a7f9f
   gpu_xrandr = META_GPU_XRANDR (gpu);
1a7f9f
   resources = meta_gpu_xrandr_get_resources (gpu_xrandr);
1a7f9f
 
1a7f9f
-  is_hotplug = resources->timestamp < resources->configTimestamp;
1a7f9f
+  timestamp = resources->timestamp;
1a7f9f
+  if (is_xvnc (manager))
1a7f9f
+    timestamp += 100;
1a7f9f
+
1a7f9f
+  is_hotplug = (timestamp < resources->configTimestamp);
1a7f9f
   is_our_configuration = (resources->timestamp ==
1a7f9f
                           manager_xrandr->last_xrandr_set_timestamp);
1a7f9f
   if (is_hotplug)
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From 17d9494cc08e833a6e896daa4f85a15b81df1554 Mon Sep 17 00:00:00 2001
1a7f9f
From: Rui Matos <tiagomatos@gmail.com>
1a7f9f
Date: Mon, 4 Jun 2018 16:35:04 -0400
1a7f9f
Subject: [PATCH 2/9] monitor-manager-xrandr: Force an update when resuming
1a7f9f
 from suspend
1a7f9f
1a7f9f
The stack below us isn't as reliable as we'd like and in some cases
1a7f9f
doesn't generate RRScreenChangeNotify events when e.g. resuming a
1a7f9f
laptop on a dock, meaning that we'd miss newly attached outputs.
1a7f9f
---
1a7f9f
 src/backends/meta-gpu.c                       |  7 ++
1a7f9f
 src/backends/meta-gpu.h                       |  4 +
1a7f9f
 src/backends/x11/meta-gpu-xrandr.c            | 26 ++++-
1a7f9f
 .../x11/meta-monitor-manager-xrandr.c         | 98 +++++++++++++++++--
1a7f9f
 4 files changed, 125 insertions(+), 10 deletions(-)
1a7f9f
1a7f9f
diff --git a/src/backends/meta-gpu.c b/src/backends/meta-gpu.c
1a7f9f
index ce4353bf01..6b3086e747 100644
1a7f9f
--- a/src/backends/meta-gpu.c
1a7f9f
+++ b/src/backends/meta-gpu.c
1a7f9f
@@ -66,6 +66,13 @@ meta_gpu_has_hotplug_mode_update (MetaGpu *gpu)
1a7f9f
   return FALSE;
1a7f9f
 }
1a7f9f
 
1a7f9f
+void
1a7f9f
+meta_gpu_poll_hardware (MetaGpu *gpu)
1a7f9f
+{
1a7f9f
+  if (META_GPU_GET_CLASS (gpu)->poll_hardware)
1a7f9f
+    META_GPU_GET_CLASS (gpu)->poll_hardware (gpu);
1a7f9f
+}
1a7f9f
+
1a7f9f
 gboolean
1a7f9f
 meta_gpu_read_current (MetaGpu  *gpu,
1a7f9f
                        GError  **error)
1a7f9f
diff --git a/src/backends/meta-gpu.h b/src/backends/meta-gpu.h
1a7f9f
index 9d12f95a72..37b76bd0fa 100644
1a7f9f
--- a/src/backends/meta-gpu.h
1a7f9f
+++ b/src/backends/meta-gpu.h
1a7f9f
@@ -36,8 +36,12 @@ struct _MetaGpuClass
1a7f9f
 
1a7f9f
   gboolean (* read_current) (MetaGpu  *gpu,
1a7f9f
                              GError  **error);
1a7f9f
+  void     (* poll_hardware) (MetaGpu *gpu);
1a7f9f
 };
1a7f9f
 
1a7f9f
+META_EXPORT_TEST
1a7f9f
+void meta_gpu_poll_hardware (MetaGpu *gpu);
1a7f9f
+
1a7f9f
 META_EXPORT_TEST
1a7f9f
 gboolean meta_gpu_read_current (MetaGpu  *gpu,
1a7f9f
                                 GError  **error);
1a7f9f
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
index bc3292d368..6a96e53979 100644
1a7f9f
--- a/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
@@ -46,6 +46,8 @@ struct _MetaGpuXrandr
1a7f9f
 
1a7f9f
   int max_screen_width;
1a7f9f
   int max_screen_height;
1a7f9f
+
1a7f9f
+  gboolean need_hardware_poll;
1a7f9f
 };
1a7f9f
 
1a7f9f
 G_DEFINE_TYPE (MetaGpuXrandr, meta_gpu_xrandr, META_TYPE_GPU)
1a7f9f
@@ -86,6 +88,14 @@ get_xmode_name (XRRModeInfo *xmode)
1a7f9f
   return g_strdup_printf ("%dx%d", width, height);
1a7f9f
 }
1a7f9f
 
1a7f9f
+static void
1a7f9f
+meta_gpu_xrandr_poll_hardware (MetaGpu *gpu)
1a7f9f
+{
1a7f9f
+  MetaGpuXrandr *gpu_xrandr = META_GPU_XRANDR (gpu);
1a7f9f
+
1a7f9f
+  gpu_xrandr->need_hardware_poll = TRUE;
1a7f9f
+}
1a7f9f
+
1a7f9f
 static gboolean
1a7f9f
 meta_gpu_xrandr_read_current (MetaGpu  *gpu,
1a7f9f
                               GError  **error)
1a7f9f
@@ -123,8 +133,18 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
1a7f9f
   monitor_manager->screen_width = WidthOfScreen (screen);
1a7f9f
   monitor_manager->screen_height = HeightOfScreen (screen);
1a7f9f
 
1a7f9f
-  resources = XRRGetScreenResourcesCurrent (xdisplay,
1a7f9f
-                                            DefaultRootWindow (xdisplay));
1a7f9f
+  if (gpu_xrandr->need_hardware_poll)
1a7f9f
+    {
1a7f9f
+      resources = XRRGetScreenResources (xdisplay,
1a7f9f
+                                         DefaultRootWindow (xdisplay));
1a7f9f
+      gpu_xrandr->need_hardware_poll = FALSE;
1a7f9f
+    }
1a7f9f
+  else
1a7f9f
+    {
1a7f9f
+      resources = XRRGetScreenResourcesCurrent (xdisplay,
1a7f9f
+                                                DefaultRootWindow (xdisplay));
1a7f9f
+    }
1a7f9f
+
1a7f9f
   if (!resources)
1a7f9f
     {
1a7f9f
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1a7f9f
@@ -263,6 +283,7 @@ meta_gpu_xrandr_finalize (GObject *object)
1a7f9f
 static void
1a7f9f
 meta_gpu_xrandr_init (MetaGpuXrandr *gpu_xrandr)
1a7f9f
 {
1a7f9f
+  gpu_xrandr->need_hardware_poll = TRUE;
1a7f9f
 }
1a7f9f
 
1a7f9f
 static void
1a7f9f
@@ -274,4 +295,5 @@ meta_gpu_xrandr_class_init (MetaGpuXrandrClass *klass)
1a7f9f
   object_class->finalize = meta_gpu_xrandr_finalize;
1a7f9f
 
1a7f9f
   gpu_class->read_current = meta_gpu_xrandr_read_current;
1a7f9f
+  gpu_class->poll_hardware = meta_gpu_xrandr_poll_hardware;
1a7f9f
 }
1a7f9f
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
index 1ddc2a7870..61e13f459d 100644
1a7f9f
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
@@ -72,6 +72,10 @@ struct _MetaMonitorManagerXrandr
1a7f9f
   Display *xdisplay;
1a7f9f
   int rr_event_base;
1a7f9f
   int rr_error_base;
1a7f9f
+
1a7f9f
+  guint logind_watch_id;
1a7f9f
+  guint logind_signal_sub_id;
1a7f9f
+
1a7f9f
   gboolean has_randr15;
1a7f9f
 
1a7f9f
   xcb_timestamp_t last_xrandr_set_timestamp;
1a7f9f
@@ -96,6 +100,8 @@ typedef struct _MetaMonitorXrandrData
1a7f9f
 
1a7f9f
 GQuark quark_meta_monitor_xrandr_data;
1a7f9f
 
1a7f9f
+static void meta_monitor_manager_xrandr_update (MetaMonitorManagerXrandr *manager_xrandr);
1a7f9f
+
1a7f9f
 Display *
1a7f9f
 meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xrandr)
1a7f9f
 {
1a7f9f
@@ -1009,6 +1015,64 @@ meta_monitor_manager_xrandr_set_output_ctm (MetaOutput          *output,
1a7f9f
   meta_output_xrandr_set_ctm (META_OUTPUT_XRANDR (output), ctm);
1a7f9f
 }
1a7f9f
 
1a7f9f
+static void
1a7f9f
+logind_signal_handler (GDBusConnection *connection,
1a7f9f
+                       const gchar     *sender_name,
1a7f9f
+                       const gchar     *object_path,
1a7f9f
+                       const gchar     *interface_name,
1a7f9f
+                       const gchar     *signal_name,
1a7f9f
+                       GVariant        *parameters,
1a7f9f
+                       gpointer         user_data)
1a7f9f
+{
1a7f9f
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
1a7f9f
+  gboolean suspending;
1a7f9f
+
1a7f9f
+  if (!g_str_equal (signal_name, "PrepareForSleep"))
1a7f9f
+    return;
1a7f9f
+
1a7f9f
+  g_variant_get (parameters, "(b)", &suspending);
1a7f9f
+  if (!suspending)
1a7f9f
+    {
1a7f9f
+      MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
1a7f9f
+
1a7f9f
+      meta_gpu_poll_hardware (gpu);
1a7f9f
+      meta_monitor_manager_xrandr_update (manager_xrandr);
1a7f9f
+    }
1a7f9f
+}
1a7f9f
+
1a7f9f
+static void
1a7f9f
+logind_appeared (GDBusConnection *connection,
1a7f9f
+                 const gchar     *name,
1a7f9f
+                 const gchar     *name_owner,
1a7f9f
+                 gpointer         user_data)
1a7f9f
+{
1a7f9f
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
1a7f9f
+
1a7f9f
+  manager_xrandr->logind_signal_sub_id = g_dbus_connection_signal_subscribe (connection,
1a7f9f
+                                                                             "org.freedesktop.login1",
1a7f9f
+                                                                             "org.freedesktop.login1.Manager",
1a7f9f
+                                                                             "PrepareForSleep",
1a7f9f
+                                                                             "/org/freedesktop/login1",
1a7f9f
+                                                                             NULL,
1a7f9f
+                                                                             G_DBUS_SIGNAL_FLAGS_NONE,
1a7f9f
+                                                                             logind_signal_handler,
1a7f9f
+                                                                             manager_xrandr,
1a7f9f
+                                                                             NULL);
1a7f9f
+}
1a7f9f
+
1a7f9f
+static void
1a7f9f
+logind_vanished (GDBusConnection *connection,
1a7f9f
+                 const gchar     *name,
1a7f9f
+                 gpointer         user_data)
1a7f9f
+{
1a7f9f
+  MetaMonitorManagerXrandr *manager_xrandr = user_data;
1a7f9f
+
1a7f9f
+  if (connection && manager_xrandr->logind_signal_sub_id > 0)
1a7f9f
+    g_dbus_connection_signal_unsubscribe (connection, manager_xrandr->logind_signal_sub_id);
1a7f9f
+
1a7f9f
+  manager_xrandr->logind_signal_sub_id = 0;
1a7f9f
+}
1a7f9f
+
1a7f9f
 static void
1a7f9f
 meta_monitor_manager_xrandr_constructed (GObject *object)
1a7f9f
 {
1a7f9f
@@ -1061,12 +1125,23 @@ meta_monitor_manager_xrandr_finalize (GObject *object)
1a7f9f
   g_hash_table_destroy (manager_xrandr->tiled_monitor_atoms);
1a7f9f
   g_free (manager_xrandr->supported_scales);
1a7f9f
 
1a7f9f
+  if (manager_xrandr->logind_watch_id > 0)
1a7f9f
+    g_bus_unwatch_name (manager_xrandr->logind_watch_id);
1a7f9f
+  manager_xrandr->logind_watch_id = 0;
1a7f9f
+
1a7f9f
   G_OBJECT_CLASS (meta_monitor_manager_xrandr_parent_class)->finalize (object);
1a7f9f
 }
1a7f9f
 
1a7f9f
 static void
1a7f9f
 meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
1a7f9f
 {
1a7f9f
+  manager_xrandr->logind_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
1a7f9f
+                                                      "org.freedesktop.login1",
1a7f9f
+                                                      G_BUS_NAME_WATCHER_FLAGS_NONE,
1a7f9f
+                                                      logind_appeared,
1a7f9f
+                                                      logind_vanished,
1a7f9f
+                                                      manager_xrandr,
1a7f9f
+                                                      NULL);
1a7f9f
 }
1a7f9f
 
1a7f9f
 static void
1a7f9f
@@ -1114,9 +1189,8 @@ is_xvnc (MetaMonitorManager *manager)
1a7f9f
   return FALSE;
1a7f9f
 }
1a7f9f
 
1a7f9f
-gboolean
1a7f9f
-meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
1a7f9f
-					   XEvent                   *event)
1a7f9f
+static void
1a7f9f
+meta_monitor_manager_xrandr_update (MetaMonitorManagerXrandr *manager_xrandr)
1a7f9f
 {
1a7f9f
   MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
1a7f9f
   MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr);
1a7f9f
@@ -1126,11 +1200,6 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
1a7f9f
   gboolean is_our_configuration;
1a7f9f
   unsigned int timestamp;
1a7f9f
 
1a7f9f
-  if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
1a7f9f
-    return FALSE;
1a7f9f
-
1a7f9f
-  XRRUpdateConfiguration (event);
1a7f9f
-
1a7f9f
   meta_monitor_manager_read_current_state (manager);
1a7f9f
 
1a7f9f
   gpu_xrandr = META_GPU_XRANDR (gpu);
1a7f9f
@@ -1165,6 +1234,19 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xra
1a7f9f
 
1a7f9f
       meta_monitor_manager_xrandr_rebuild_derived (manager, config);
1a7f9f
     }
1a7f9f
+}
1a7f9f
+
1a7f9f
+gboolean
1a7f9f
+meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager_xrandr,
1a7f9f
+					   XEvent                   *event)
1a7f9f
+{
1a7f9f
+
1a7f9f
+  if ((event->type - manager_xrandr->rr_event_base) != RRScreenChangeNotify)
1a7f9f
+    return FALSE;
1a7f9f
+
1a7f9f
+  XRRUpdateConfiguration (event);
1a7f9f
+
1a7f9f
+  meta_monitor_manager_xrandr_update (manager_xrandr);
1a7f9f
 
1a7f9f
   return TRUE;
1a7f9f
 }
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From 7a04949b978ebe96cd088d7bd255fd3f52c7c355 Mon Sep 17 00:00:00 2001
1a7f9f
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
1a7f9f
Date: Mon, 24 Feb 2020 16:09:59 +0100
1a7f9f
Subject: [PATCH 3/9] Revert "MetaMonitorManager: ignore hotplug_mode_update at
1a7f9f
 startup"
1a7f9f
1a7f9f
This reverts commit 183f4b0c13f3dc9565bf5f693f2e5d61ca0199c9.
1a7f9f
---
1a7f9f
 src/backends/meta-monitor-manager.c | 3 +--
1a7f9f
 1 file changed, 1 insertion(+), 2 deletions(-)
1a7f9f
1a7f9f
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
1a7f9f
index a75da9329e..c291ddb5d3 100644
1a7f9f
--- a/src/backends/meta-monitor-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-manager.c
1a7f9f
@@ -609,8 +609,7 @@ meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager)
1a7f9f
 static gboolean
1a7f9f
 should_use_stored_config (MetaMonitorManager *manager)
1a7f9f
 {
1a7f9f
-  return (manager->in_init ||
1a7f9f
-          !meta_monitor_manager_has_hotplug_mode_update (manager));
1a7f9f
+  return !meta_monitor_manager_has_hotplug_mode_update (manager);
1a7f9f
 }
1a7f9f
 
1a7f9f
 MetaMonitorsConfig *
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From babcf2a6d09136bcf1bf2dc958046aaa0334b85e Mon Sep 17 00:00:00 2001
1a7f9f
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
1a7f9f
Date: Thu, 28 Jan 2016 15:26:33 +0100
1a7f9f
Subject: [PATCH 4/9] monitor-manager: Consider external layout before default
1a7f9f
 linear config
1a7f9f
1a7f9f
In case of no existing configuration, we use a default layout of
1a7f9f
aligning attached displays horizontally. This sidesteps any layout
1a7f9f
configuration that is done externally, for instance via xorg.conf,
1a7f9f
which is not desirable. Instead, base the initial configuration on
1a7f9f
the existing layout if it passes some sanity checks before falling
1a7f9f
back to the default linear config.
1a7f9f
---
1a7f9f
 src/backends/meta-monitor-config-manager.c | 86 ++++++++++++++++++++++
1a7f9f
 src/backends/meta-monitor-config-manager.h |  2 +
1a7f9f
 src/backends/meta-monitor-manager.c        | 19 +++++
1a7f9f
 3 files changed, 107 insertions(+)
1a7f9f
1a7f9f
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
1a7f9f
index 0253e072ff..2f6cc3856f 100644
1a7f9f
--- a/src/backends/meta-monitor-config-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-config-manager.c
1a7f9f
@@ -739,6 +739,92 @@ create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_ma
1a7f9f
   return logical_monitor_config;
1a7f9f
 }
1a7f9f
 
1a7f9f
+static MetaLogicalMonitorConfig *
1a7f9f
+create_logical_monitor_config_from_output (MetaMonitorManager           *monitor_manager,
1a7f9f
+                                           MetaMonitor                  *monitor,
1a7f9f
+                                           MetaLogicalMonitorConfig     *primary_logical_monitor_config,
1a7f9f
+                                           MetaLogicalMonitorLayoutMode  layout_mode)
1a7f9f
+{
1a7f9f
+  MetaOutput *output;
1a7f9f
+  MetaCrtc *crtc;
1a7f9f
+  const MetaCrtcConfig *crtc_config;
1a7f9f
+
1a7f9f
+  output = meta_monitor_get_main_output (monitor);
1a7f9f
+  crtc = meta_output_get_assigned_crtc (output);
1a7f9f
+  crtc_config = meta_crtc_get_config (crtc);
1a7f9f
+  if (!crtc_config)
1a7f9f
+    return NULL;
1a7f9f
+
1a7f9f
+  return create_preferred_logical_monitor_config (monitor_manager,
1a7f9f
+                                                  monitor,
1a7f9f
+                                                  (int) crtc_config->layout.origin.x,
1a7f9f
+                                                  (int) crtc_config->layout.origin.y,
1a7f9f
+                                                  primary_logical_monitor_config,
1a7f9f
+                                                  layout_mode);
1a7f9f
+}
1a7f9f
+
1a7f9f
+MetaMonitorsConfig *
1a7f9f
+meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager)
1a7f9f
+{
1a7f9f
+  MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
1a7f9f
+  GList *logical_monitor_configs;
1a7f9f
+  MetaMonitor *primary_monitor;
1a7f9f
+  MetaLogicalMonitorLayoutMode layout_mode;
1a7f9f
+  MetaLogicalMonitorConfig *primary_logical_monitor_config;
1a7f9f
+  GList *monitors;
1a7f9f
+  GList *l;
1a7f9f
+
1a7f9f
+  if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
1a7f9f
+    return NULL;
1a7f9f
+
1a7f9f
+  primary_monitor = find_primary_monitor (monitor_manager);
1a7f9f
+  if (!primary_monitor || !meta_monitor_is_active (primary_monitor))
1a7f9f
+    return NULL;
1a7f9f
+
1a7f9f
+  layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
1a7f9f
+
1a7f9f
+  primary_logical_monitor_config =
1a7f9f
+    create_logical_monitor_config_from_output (monitor_manager,
1a7f9f
+                                               primary_monitor,
1a7f9f
+                                               NULL,
1a7f9f
+                                               layout_mode);
1a7f9f
+  if (!primary_logical_monitor_config)
1a7f9f
+    return NULL;
1a7f9f
+
1a7f9f
+  primary_logical_monitor_config->is_primary = TRUE;
1a7f9f
+  logical_monitor_configs = g_list_append (NULL,
1a7f9f
+                                           primary_logical_monitor_config);
1a7f9f
+
1a7f9f
+  monitors = meta_monitor_manager_get_monitors (monitor_manager);
1a7f9f
+  for (l = monitors; l; l = l->next)
1a7f9f
+    {
1a7f9f
+      MetaMonitor *monitor = l->data;
1a7f9f
+      MetaLogicalMonitorConfig *logical_monitor_config;
1a7f9f
+
1a7f9f
+      if (monitor == primary_monitor)
1a7f9f
+        continue;
1a7f9f
+
1a7f9f
+      if (!meta_monitor_is_active (monitor))
1a7f9f
+        continue;
1a7f9f
+
1a7f9f
+      logical_monitor_config =
1a7f9f
+        create_logical_monitor_config_from_output (monitor_manager,
1a7f9f
+                                                   monitor,
1a7f9f
+                                                   primary_logical_monitor_config,
1a7f9f
+                                                   layout_mode);
1a7f9f
+      if (!logical_monitor_config)
1a7f9f
+        continue;
1a7f9f
+
1a7f9f
+      logical_monitor_configs = g_list_append (logical_monitor_configs,
1a7f9f
+                                               logical_monitor_config);
1a7f9f
+    }
1a7f9f
+
1a7f9f
+  return meta_monitors_config_new (monitor_manager,
1a7f9f
+                                   logical_monitor_configs,
1a7f9f
+                                   layout_mode,
1a7f9f
+                                   META_MONITORS_CONFIG_FLAG_NONE);
1a7f9f
+}
1a7f9f
+
1a7f9f
 MetaMonitorsConfig *
1a7f9f
 meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager)
1a7f9f
 {
1a7f9f
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
1a7f9f
index 86756a7e33..961d604bd5 100644
1a7f9f
--- a/src/backends/meta-monitor-config-manager.h
1a7f9f
+++ b/src/backends/meta-monitor-config-manager.h
1a7f9f
@@ -94,6 +94,8 @@ gboolean meta_monitor_config_manager_assign (MetaMonitorManager *manager,
1a7f9f
 META_EXPORT_TEST
1a7f9f
 MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager);
1a7f9f
 
1a7f9f
+META_EXPORT_TEST
1a7f9f
+MetaMonitorsConfig * meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager);
1a7f9f
 META_EXPORT_TEST
1a7f9f
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
1a7f9f
 
1a7f9f
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
1a7f9f
index c291ddb5d3..96f0d6b84a 100644
1a7f9f
--- a/src/backends/meta-monitor-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-manager.c
1a7f9f
@@ -695,6 +695,25 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1a7f9f
       g_clear_object (&config);
1a7f9f
     }
1a7f9f
 
1a7f9f
+  config = meta_monitor_config_manager_create_current (manager->config_manager);
1a7f9f
+  if (config)
1a7f9f
+    {
1a7f9f
+      if (!meta_monitor_manager_apply_monitors_config (manager,
1a7f9f
+                                                       config,
1a7f9f
+                                                       method,
1a7f9f
+                                                       &error))
1a7f9f
+        {
1a7f9f
+          g_clear_object (&config);
1a7f9f
+          g_warning ("Failed to use current monitor configuration: %s",
1a7f9f
+                     error->message);
1a7f9f
+          g_clear_error (&error);
1a7f9f
+        }
1a7f9f
+      else
1a7f9f
+        {
1a7f9f
+          goto done;
1a7f9f
+        }
1a7f9f
+    }
1a7f9f
+
1a7f9f
   config = meta_monitor_config_manager_create_linear (manager->config_manager);
1a7f9f
   if (config)
1a7f9f
     {
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From ada8c9b1346fe261a8fa04f68149c79d95c969ac Mon Sep 17 00:00:00 2001
1a7f9f
From: rpm-build <rpm-build>
1a7f9f
Date: Tue, 11 Sep 2018 10:19:44 -0400
1a7f9f
Subject: [PATCH 5/9] monitor-manager: only reuse initial-config if monitor
1a7f9f
 topology matches startup
1a7f9f
1a7f9f
Right now we try to apply the current monitor config when a new
1a7f9f
monitor is attached.  The current config obviously doesn't include the
1a7f9f
new monitor, so the new monitor isn't lit up.
1a7f9f
1a7f9f
The only reason we apply the current config at all is to handle the
1a7f9f
startup case:  We want to reuse the config set in Xorg when first
1a7f9f
logging in.
1a7f9f
1a7f9f
This commit changes the code to look at the *initial config* instead
1a7f9f
of the current config, and only if the new monitor topology matches
1a7f9f
the start up topology.
1a7f9f
---
1a7f9f
 src/backends/meta-monitor-config-manager.c | 20 +++++++++++++++-----
1a7f9f
 src/backends/meta-monitor-config-manager.h |  2 +-
1a7f9f
 src/backends/meta-monitor-manager.c        | 16 +++++++++++++++-
1a7f9f
 3 files changed, 31 insertions(+), 7 deletions(-)
1a7f9f
1a7f9f
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
1a7f9f
index 2f6cc3856f..46249755bc 100644
1a7f9f
--- a/src/backends/meta-monitor-config-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-config-manager.c
1a7f9f
@@ -42,6 +42,7 @@ struct _MetaMonitorConfigManager
1a7f9f
   MetaMonitorConfigStore *config_store;
1a7f9f
 
1a7f9f
   MetaMonitorsConfig *current_config;
1a7f9f
+  MetaMonitorsConfig *initial_config;
1a7f9f
   GQueue config_history;
1a7f9f
 };
1a7f9f
 
1a7f9f
@@ -764,9 +765,10 @@ create_logical_monitor_config_from_output (MetaMonitorManager           *monitor
1a7f9f
 }
1a7f9f
 
1a7f9f
 MetaMonitorsConfig *
1a7f9f
-meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager)
1a7f9f
+meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager)
1a7f9f
 {
1a7f9f
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
1a7f9f
+  MetaMonitorsConfig *initial_config;
1a7f9f
   GList *logical_monitor_configs;
1a7f9f
   MetaMonitor *primary_monitor;
1a7f9f
   MetaLogicalMonitorLayoutMode layout_mode;
1a7f9f
@@ -774,6 +776,9 @@ meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_man
1a7f9f
   GList *monitors;
1a7f9f
   GList *l;
1a7f9f
 
1a7f9f
+  if (config_manager->initial_config != NULL)
1a7f9f
+    return g_object_ref (config_manager->initial_config);
1a7f9f
+
1a7f9f
   if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
1a7f9f
     return NULL;
1a7f9f
 
1a7f9f
@@ -819,10 +824,14 @@ meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_man
1a7f9f
                                                logical_monitor_config);
1a7f9f
     }
1a7f9f
 
1a7f9f
-  return meta_monitors_config_new (monitor_manager,
1a7f9f
-                                   logical_monitor_configs,
1a7f9f
-                                   layout_mode,
1a7f9f
-                                   META_MONITORS_CONFIG_FLAG_NONE);
1a7f9f
+  initial_config = meta_monitors_config_new (monitor_manager,
1a7f9f
+                                             logical_monitor_configs,
1a7f9f
+                                             layout_mode,
1a7f9f
+                                             META_MONITORS_CONFIG_FLAG_NONE);
1a7f9f
+
1a7f9f
+  config_manager->initial_config = g_object_ref (initial_config);
1a7f9f
+
1a7f9f
+  return initial_config;
1a7f9f
 }
1a7f9f
 
1a7f9f
 MetaMonitorsConfig *
1a7f9f
@@ -1453,6 +1462,7 @@ meta_monitor_config_manager_dispose (GObject *object)
1a7f9f
     META_MONITOR_CONFIG_MANAGER (object);
1a7f9f
 
1a7f9f
   g_clear_object (&config_manager->current_config);
1a7f9f
+  g_clear_object (&config_manager->initial_config);
1a7f9f
   meta_monitor_config_manager_clear_history (config_manager);
1a7f9f
 
1a7f9f
   G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
1a7f9f
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
1a7f9f
index 961d604bd5..dc273c961b 100644
1a7f9f
--- a/src/backends/meta-monitor-config-manager.h
1a7f9f
+++ b/src/backends/meta-monitor-config-manager.h
1a7f9f
@@ -95,7 +95,7 @@ META_EXPORT_TEST
1a7f9f
 MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigManager *config_manager);
1a7f9f
 
1a7f9f
 META_EXPORT_TEST
1a7f9f
-MetaMonitorsConfig * meta_monitor_config_manager_create_current (MetaMonitorConfigManager *config_manager);
1a7f9f
+MetaMonitorsConfig * meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager);
1a7f9f
 META_EXPORT_TEST
1a7f9f
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
1a7f9f
 
1a7f9f
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
1a7f9f
index 96f0d6b84a..baf5bf2f9f 100644
1a7f9f
--- a/src/backends/meta-monitor-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-manager.c
1a7f9f
@@ -615,9 +615,11 @@ should_use_stored_config (MetaMonitorManager *manager)
1a7f9f
 MetaMonitorsConfig *
1a7f9f
 meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1a7f9f
 {
1a7f9f
+  g_autoptr (MetaMonitorsConfig) initial_config = NULL;
1a7f9f
   MetaMonitorsConfig *config = NULL;
1a7f9f
   GError *error = NULL;
1a7f9f
   gboolean use_stored_config;
1a7f9f
+  MetaMonitorsConfigKey *current_state_key;
1a7f9f
   MetaMonitorsConfigMethod method;
1a7f9f
   MetaMonitorsConfigMethod fallback_method =
1a7f9f
     META_MONITORS_CONFIG_METHOD_TEMPORARY;
1a7f9f
@@ -628,6 +630,18 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1a7f9f
   else
1a7f9f
     method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
1a7f9f
 
1a7f9f
+  initial_config = meta_monitor_config_manager_create_initial (manager->config_manager);
1a7f9f
+
1a7f9f
+  if (initial_config)
1a7f9f
+    {
1a7f9f
+      current_state_key = meta_create_monitors_config_key_for_current_state (manager);
1a7f9f
+
1a7f9f
+      /* don't ever reuse initial configuration, if the monitor topology changed
1a7f9f
+       */
1a7f9f
+      if (current_state_key && !meta_monitors_config_key_equal (current_state_key, initial_config->key))
1a7f9f
+        g_clear_object (&initial_config);
1a7f9f
+    }
1a7f9f
+
1a7f9f
   if (use_stored_config)
1a7f9f
     {
1a7f9f
       config = meta_monitor_config_manager_get_stored (manager->config_manager);
1a7f9f
@@ -695,7 +709,7 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1a7f9f
       g_clear_object (&config);
1a7f9f
     }
1a7f9f
 
1a7f9f
-  config = meta_monitor_config_manager_create_current (manager->config_manager);
1a7f9f
+  config = g_steal_pointer (&initial_config);
1a7f9f
   if (config)
1a7f9f
     {
1a7f9f
       if (!meta_monitor_manager_apply_monitors_config (manager,
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From baa22f3ac77f549bd36c2a0ea45ba4caee434ddc Mon Sep 17 00:00:00 2001
1a7f9f
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
1a7f9f
Date: Mon, 18 Mar 2019 17:08:11 +0100
1a7f9f
Subject: [PATCH 6/9] monitor-config-manager: Use current mode when deriving
1a7f9f
 current config
1a7f9f
1a7f9f
Instead of overriding the existing mode with the preferred mode of the monitor,
1a7f9f
use the one already configured. Also use the MetaMonitor API for deriving the
1a7f9f
position of the monitor in the screen coordinate space.
1a7f9f
---
1a7f9f
 src/backends/meta-monitor-config-manager.c | 80 +++++++++++++---------
1a7f9f
 1 file changed, 46 insertions(+), 34 deletions(-)
1a7f9f
1a7f9f
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
1a7f9f
index 46249755bc..f355879c3e 100644
1a7f9f
--- a/src/backends/meta-monitor-config-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-config-manager.c
1a7f9f
@@ -678,21 +678,20 @@ get_monitor_transform (MetaMonitorManager *monitor_manager,
1a7f9f
 }
1a7f9f
 
1a7f9f
 static MetaLogicalMonitorConfig *
1a7f9f
-create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_manager,
1a7f9f
-                                         MetaMonitor                 *monitor,
1a7f9f
-                                         int                          x,
1a7f9f
-                                         int                          y,
1a7f9f
-                                         MetaLogicalMonitorConfig    *primary_logical_monitor_config,
1a7f9f
-                                         MetaLogicalMonitorLayoutMode layout_mode)
1a7f9f
+create_logical_monitor_config (MetaMonitorManager           *monitor_manager,
1a7f9f
+                               MetaMonitor                  *monitor,
1a7f9f
+                               MetaMonitorMode              *mode,
1a7f9f
+                               int                           x,
1a7f9f
+                               int                           y,
1a7f9f
+                               MetaLogicalMonitorConfig     *primary_logical_monitor_config,
1a7f9f
+                               MetaLogicalMonitorLayoutMode  layout_mode)
1a7f9f
 {
1a7f9f
-  MetaMonitorMode *mode;
1a7f9f
   int width, height;
1a7f9f
   float scale;
1a7f9f
   MetaMonitorTransform transform;
1a7f9f
   MetaMonitorConfig *monitor_config;
1a7f9f
   MetaLogicalMonitorConfig *logical_monitor_config;
1a7f9f
 
1a7f9f
-  mode = meta_monitor_get_preferred_mode (monitor);
1a7f9f
   meta_monitor_mode_get_resolution (mode, &width, &height);
1a7f9f
 
1a7f9f
   if ((meta_monitor_manager_get_capabilities (monitor_manager) &
1a7f9f
@@ -741,27 +740,40 @@ create_preferred_logical_monitor_config (MetaMonitorManager          *monitor_ma
1a7f9f
 }
1a7f9f
 
1a7f9f
 static MetaLogicalMonitorConfig *
1a7f9f
-create_logical_monitor_config_from_output (MetaMonitorManager           *monitor_manager,
1a7f9f
-                                           MetaMonitor                  *monitor,
1a7f9f
-                                           MetaLogicalMonitorConfig     *primary_logical_monitor_config,
1a7f9f
-                                           MetaLogicalMonitorLayoutMode  layout_mode)
1a7f9f
+create_preferred_logical_monitor_config (MetaMonitorManager           *monitor_manager,
1a7f9f
+                                         MetaMonitor                  *monitor,
1a7f9f
+                                         int                           x,
1a7f9f
+                                         int                           y,
1a7f9f
+                                         MetaLogicalMonitorConfig     *primary_logical_monitor_config,
1a7f9f
+                                         MetaLogicalMonitorLayoutMode  layout_mode)
1a7f9f
 {
1a7f9f
-  MetaOutput *output;
1a7f9f
-  MetaCrtc *crtc;
1a7f9f
-  const MetaCrtcConfig *crtc_config;
1a7f9f
+  return create_logical_monitor_config (monitor_manager,
1a7f9f
+                                        monitor,
1a7f9f
+                                        meta_monitor_get_preferred_mode (monitor),
1a7f9f
+                                        x, y,
1a7f9f
+                                        primary_logical_monitor_config,
1a7f9f
+                                        layout_mode);
1a7f9f
+}
1a7f9f
 
1a7f9f
-  output = meta_monitor_get_main_output (monitor);
1a7f9f
-  crtc = meta_output_get_assigned_crtc (output);
1a7f9f
-  crtc_config = meta_crtc_get_config (crtc);
1a7f9f
-  if (!crtc_config)
1a7f9f
-    return NULL;
1a7f9f
+static MetaLogicalMonitorConfig *
1a7f9f
+create_logical_monitor_config_from_monitor (MetaMonitorManager           *monitor_manager,
1a7f9f
+                                            MetaMonitor                  *monitor,
1a7f9f
+                                            MetaLogicalMonitorConfig     *primary_logical_monitor_config,
1a7f9f
+                                            MetaLogicalMonitorLayoutMode  layout_mode)
1a7f9f
+{
1a7f9f
+  MetaRectangle monitor_layout;
1a7f9f
+  MetaMonitorMode *mode;
1a7f9f
+
1a7f9f
+  meta_monitor_derive_layout (monitor, &monitor_layout);
1a7f9f
+  mode = meta_monitor_get_current_mode (monitor);
1a7f9f
 
1a7f9f
-  return create_preferred_logical_monitor_config (monitor_manager,
1a7f9f
-                                                  monitor,
1a7f9f
-                                                  (int) crtc_config->layout.origin.x,
1a7f9f
-                                                  (int) crtc_config->layout.origin.y,
1a7f9f
-                                                  primary_logical_monitor_config,
1a7f9f
-                                                  layout_mode);
1a7f9f
+  return create_logical_monitor_config (monitor_manager,
1a7f9f
+                                        monitor,
1a7f9f
+                                        mode,
1a7f9f
+                                        monitor_layout.x,
1a7f9f
+                                        monitor_layout.y,
1a7f9f
+                                        primary_logical_monitor_config,
1a7f9f
+                                        layout_mode);
1a7f9f
 }
1a7f9f
 
1a7f9f
 MetaMonitorsConfig *
1a7f9f
@@ -789,10 +801,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
1a7f9f
   layout_mode = meta_monitor_manager_get_default_layout_mode (monitor_manager);
1a7f9f
 
1a7f9f
   primary_logical_monitor_config =
1a7f9f
-    create_logical_monitor_config_from_output (monitor_manager,
1a7f9f
-                                               primary_monitor,
1a7f9f
-                                               NULL,
1a7f9f
-                                               layout_mode);
1a7f9f
+    create_logical_monitor_config_from_monitor (monitor_manager,
1a7f9f
+                                                primary_monitor,
1a7f9f
+                                                NULL,
1a7f9f
+                                                layout_mode);
1a7f9f
   if (!primary_logical_monitor_config)
1a7f9f
     return NULL;
1a7f9f
 
1a7f9f
@@ -813,10 +825,10 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
1a7f9f
         continue;
1a7f9f
 
1a7f9f
       logical_monitor_config =
1a7f9f
-        create_logical_monitor_config_from_output (monitor_manager,
1a7f9f
-                                                   monitor,
1a7f9f
-                                                   primary_logical_monitor_config,
1a7f9f
-                                                   layout_mode);
1a7f9f
+        create_logical_monitor_config_from_monitor (monitor_manager,
1a7f9f
+                                                    monitor,
1a7f9f
+                                                    primary_logical_monitor_config,
1a7f9f
+                                                    layout_mode);
1a7f9f
       if (!logical_monitor_config)
1a7f9f
         continue;
1a7f9f
 
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From 52622c80f747a03738823471be9d275c7a2fd8c0 Mon Sep 17 00:00:00 2001
1a7f9f
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
1a7f9f
Date: Mon, 18 Mar 2019 17:10:37 +0100
1a7f9f
Subject: [PATCH 7/9] monitor-manager: Don't try to derive current config on
1a7f9f
 non-X11
1a7f9f
1a7f9f
This commit also reworks the initial config state reading some. Appart from
1a7f9f
avoiding trying to inherit from backends where it doesn't make sense, it does
1a7f9f
the following changes:
1a7f9f
1a7f9f
 * Replace the name "initial" with "inherited", as the initial config in the
1a7f9f
   context of monitor management is the one used initialization. E.g. if there is
1a7f9f
   a applicable configuration in monitors.xml, the initial config is taken from
1a7f9f
   there.
1a7f9f
1a7f9f
 * Don't make "_create_()" functions have side effects. Previously
1a7f9f
   meta_monitor_config_manager_create_initial() also set state on the config
1a7f9f
   manager object. Instead, add a meta_monitor_config_manager_ensure_inherited()
1a7f9f
   and meta_monitor_manager_get_inherited_config() function to make things more
1a7f9f
   explicit.
1a7f9f
1a7f9f
 * Don't recreate "is-applicable" logic, just use the existing helper.
1a7f9f
---
1a7f9f
 src/backends/meta-monitor-config-manager.c    | 39 +++++++++++--------
1a7f9f
 src/backends/meta-monitor-config-manager.h    |  5 +++
1a7f9f
 src/backends/meta-monitor-manager-private.h   |  4 +-
1a7f9f
 src/backends/meta-monitor-manager.c           | 32 ++++++++-------
1a7f9f
 .../x11/meta-monitor-manager-xrandr.c         |  3 +-
1a7f9f
 5 files changed, 49 insertions(+), 34 deletions(-)
1a7f9f
1a7f9f
diff --git a/src/backends/meta-monitor-config-manager.c b/src/backends/meta-monitor-config-manager.c
1a7f9f
index f355879c3e..4b37657d34 100644
1a7f9f
--- a/src/backends/meta-monitor-config-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-config-manager.c
1a7f9f
@@ -42,7 +42,7 @@ struct _MetaMonitorConfigManager
1a7f9f
   MetaMonitorConfigStore *config_store;
1a7f9f
 
1a7f9f
   MetaMonitorsConfig *current_config;
1a7f9f
-  MetaMonitorsConfig *initial_config;
1a7f9f
+  MetaMonitorsConfig *inherited_config;
1a7f9f
   GQueue config_history;
1a7f9f
 };
1a7f9f
 
1a7f9f
@@ -776,11 +776,10 @@ create_logical_monitor_config_from_monitor (MetaMonitorManager           *monito
1a7f9f
                                         layout_mode);
1a7f9f
 }
1a7f9f
 
1a7f9f
-MetaMonitorsConfig *
1a7f9f
-meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager)
1a7f9f
+static MetaMonitorsConfig *
1a7f9f
+meta_monitor_config_manager_derive_current (MetaMonitorConfigManager *config_manager)
1a7f9f
 {
1a7f9f
   MetaMonitorManager *monitor_manager = config_manager->monitor_manager;
1a7f9f
-  MetaMonitorsConfig *initial_config;
1a7f9f
   GList *logical_monitor_configs;
1a7f9f
   MetaMonitor *primary_monitor;
1a7f9f
   MetaLogicalMonitorLayoutMode layout_mode;
1a7f9f
@@ -788,12 +787,6 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
1a7f9f
   GList *monitors;
1a7f9f
   GList *l;
1a7f9f
 
1a7f9f
-  if (config_manager->initial_config != NULL)
1a7f9f
-    return g_object_ref (config_manager->initial_config);
1a7f9f
-
1a7f9f
-  if (meta_monitor_config_store_get_config_count (config_manager->config_store) > 0)
1a7f9f
-    return NULL;
1a7f9f
-
1a7f9f
   primary_monitor = find_primary_monitor (monitor_manager);
1a7f9f
   if (!primary_monitor || !meta_monitor_is_active (primary_monitor))
1a7f9f
     return NULL;
1a7f9f
@@ -836,14 +829,26 @@ meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_man
1a7f9f
                                                logical_monitor_config);
1a7f9f
     }
1a7f9f
 
1a7f9f
-  initial_config = meta_monitors_config_new (monitor_manager,
1a7f9f
-                                             logical_monitor_configs,
1a7f9f
-                                             layout_mode,
1a7f9f
-                                             META_MONITORS_CONFIG_FLAG_NONE);
1a7f9f
+  return meta_monitors_config_new (monitor_manager,
1a7f9f
+                                   logical_monitor_configs,
1a7f9f
+                                   layout_mode,
1a7f9f
+                                   META_MONITORS_CONFIG_FLAG_NONE);
1a7f9f
+}
1a7f9f
+
1a7f9f
+void
1a7f9f
+meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager)
1a7f9f
+{
1a7f9f
+  if (config_manager->inherited_config)
1a7f9f
+    return;
1a7f9f
 
1a7f9f
-  config_manager->initial_config = g_object_ref (initial_config);
1a7f9f
+  config_manager->inherited_config =
1a7f9f
+    meta_monitor_config_manager_derive_current (config_manager);
1a7f9f
+}
1a7f9f
 
1a7f9f
-  return initial_config;
1a7f9f
+MetaMonitorsConfig *
1a7f9f
+meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager)
1a7f9f
+{
1a7f9f
+  return config_manager->inherited_config;
1a7f9f
 }
1a7f9f
 
1a7f9f
 MetaMonitorsConfig *
1a7f9f
@@ -1474,7 +1479,7 @@ meta_monitor_config_manager_dispose (GObject *object)
1a7f9f
     META_MONITOR_CONFIG_MANAGER (object);
1a7f9f
 
1a7f9f
   g_clear_object (&config_manager->current_config);
1a7f9f
-  g_clear_object (&config_manager->initial_config);
1a7f9f
+  g_clear_object (&config_manager->inherited_config);
1a7f9f
   meta_monitor_config_manager_clear_history (config_manager);
1a7f9f
 
1a7f9f
   G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
1a7f9f
diff --git a/src/backends/meta-monitor-config-manager.h b/src/backends/meta-monitor-config-manager.h
1a7f9f
index dc273c961b..641ed1bc1a 100644
1a7f9f
--- a/src/backends/meta-monitor-config-manager.h
1a7f9f
+++ b/src/backends/meta-monitor-config-manager.h
1a7f9f
@@ -96,6 +96,11 @@ MetaMonitorsConfig * meta_monitor_config_manager_get_stored (MetaMonitorConfigMa
1a7f9f
 
1a7f9f
 META_EXPORT_TEST
1a7f9f
 MetaMonitorsConfig * meta_monitor_config_manager_create_initial (MetaMonitorConfigManager *config_manager);
1a7f9f
+
1a7f9f
+void meta_monitor_config_manager_ensure_inherited_config (MetaMonitorConfigManager *config_manager);
1a7f9f
+
1a7f9f
+MetaMonitorsConfig * meta_monitor_config_manager_get_inherited_config (MetaMonitorConfigManager *config_manager);
1a7f9f
+
1a7f9f
 META_EXPORT_TEST
1a7f9f
 MetaMonitorsConfig * meta_monitor_config_manager_create_linear (MetaMonitorConfigManager *config_manager);
1a7f9f
 
1a7f9f
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
1a7f9f
index 60c1e90821..571b9000dc 100644
1a7f9f
--- a/src/backends/meta-monitor-manager-private.h
1a7f9f
+++ b/src/backends/meta-monitor-manager-private.h
1a7f9f
@@ -44,7 +44,8 @@ typedef enum _MetaMonitorManagerCapability
1a7f9f
 {
1a7f9f
   META_MONITOR_MANAGER_CAPABILITY_NONE = 0,
1a7f9f
   META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE = (1 << 0),
1a7f9f
-  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 1)
1a7f9f
+  META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED = (1 << 1),
1a7f9f
+  META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT = (1 << 2),
1a7f9f
 } MetaMonitorManagerCapability;
1a7f9f
 
1a7f9f
 /* Equivalent to the 'method' enum in org.gnome.Mutter.DisplayConfig */
1a7f9f
@@ -145,6 +146,7 @@ struct _MetaMonitorManager
1a7f9f
   guint panel_orientation_managed : 1;
1a7f9f
 
1a7f9f
   MetaMonitorConfigManager *config_manager;
1a7f9f
+  MetaMonitorsConfig *initial_config;
1a7f9f
 
1a7f9f
   GnomePnpIds *pnp_ids;
1a7f9f
 
1a7f9f
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
1a7f9f
index baf5bf2f9f..9e57db94cd 100644
1a7f9f
--- a/src/backends/meta-monitor-manager.c
1a7f9f
+++ b/src/backends/meta-monitor-manager.c
1a7f9f
@@ -612,14 +612,21 @@ should_use_stored_config (MetaMonitorManager *manager)
1a7f9f
   return !meta_monitor_manager_has_hotplug_mode_update (manager);
1a7f9f
 }
1a7f9f
 
1a7f9f
+static gboolean
1a7f9f
+can_derive_current_config (MetaMonitorManager *manager)
1a7f9f
+{
1a7f9f
+  MetaMonitorManagerCapability capabilities;
1a7f9f
+
1a7f9f
+  capabilities = meta_monitor_manager_get_capabilities (manager);
1a7f9f
+  return !!(capabilities & META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
1a7f9f
+}
1a7f9f
+
1a7f9f
 MetaMonitorsConfig *
1a7f9f
 meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1a7f9f
 {
1a7f9f
-  g_autoptr (MetaMonitorsConfig) initial_config = NULL;
1a7f9f
   MetaMonitorsConfig *config = NULL;
1a7f9f
   GError *error = NULL;
1a7f9f
   gboolean use_stored_config;
1a7f9f
-  MetaMonitorsConfigKey *current_state_key;
1a7f9f
   MetaMonitorsConfigMethod method;
1a7f9f
   MetaMonitorsConfigMethod fallback_method =
1a7f9f
     META_MONITORS_CONFIG_METHOD_TEMPORARY;
1a7f9f
@@ -630,17 +637,8 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1a7f9f
   else
1a7f9f
     method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
1a7f9f
 
1a7f9f
-  initial_config = meta_monitor_config_manager_create_initial (manager->config_manager);
1a7f9f
-
1a7f9f
-  if (initial_config)
1a7f9f
-    {
1a7f9f
-      current_state_key = meta_create_monitors_config_key_for_current_state (manager);
1a7f9f
-
1a7f9f
-      /* don't ever reuse initial configuration, if the monitor topology changed
1a7f9f
-       */
1a7f9f
-      if (current_state_key && !meta_monitors_config_key_equal (current_state_key, initial_config->key))
1a7f9f
-        g_clear_object (&initial_config);
1a7f9f
-    }
1a7f9f
+  if (can_derive_current_config (manager))
1a7f9f
+    meta_monitor_config_manager_ensure_inherited_config (manager->config_manager);
1a7f9f
 
1a7f9f
   if (use_stored_config)
1a7f9f
     {
1a7f9f
@@ -709,9 +707,13 @@ meta_monitor_manager_ensure_configured (MetaMonitorManager *manager)
1a7f9f
       g_clear_object (&config);
1a7f9f
     }
1a7f9f
 
1a7f9f
-  config = g_steal_pointer (&initial_config);
1a7f9f
-  if (config)
1a7f9f
+  config =
1a7f9f
+    meta_monitor_config_manager_get_inherited_config (manager->config_manager);
1a7f9f
+  if (config &&
1a7f9f
+      meta_monitor_manager_is_config_complete (manager, config))
1a7f9f
     {
1a7f9f
+      config = g_object_ref (config);
1a7f9f
+
1a7f9f
       if (!meta_monitor_manager_apply_monitors_config (manager,
1a7f9f
                                                        config,
1a7f9f
                                                        method,
1a7f9f
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
index 61e13f459d..90ccb74053 100644
1a7f9f
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
@@ -984,7 +984,8 @@ meta_monitor_manager_xrandr_calculate_supported_scales (MetaMonitorManager
1a7f9f
 static MetaMonitorManagerCapability
1a7f9f
 meta_monitor_manager_xrandr_get_capabilities (MetaMonitorManager *manager)
1a7f9f
 {
1a7f9f
-  return META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED;
1a7f9f
+  return (META_MONITOR_MANAGER_CAPABILITY_GLOBAL_SCALE_REQUIRED |
1a7f9f
+          META_MONITOR_MANAGER_CAPABILITY_CAN_DERIVE_CURRENT);
1a7f9f
 }
1a7f9f
 
1a7f9f
 static gboolean
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From e15c812ef8525d6dd6db730c1c6a1f8ad839bb09 Mon Sep 17 00:00:00 2001
1a7f9f
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
1a7f9f
Date: Wed, 27 Nov 2019 19:03:50 +0100
1a7f9f
Subject: [PATCH 8/9] monitor-manager-xrandr: Move dpms state and screen size
1a7f9f
 updating into helpers
1a7f9f
1a7f9f
To be used by no-Xrandr fallback path.
1a7f9f
---
1a7f9f
 src/backends/x11/meta-gpu-xrandr.c            | 39 +++++++++++++------
1a7f9f
 .../x11/meta-monitor-manager-xrandr.c         | 18 ++++++---
1a7f9f
 2 files changed, 40 insertions(+), 17 deletions(-)
1a7f9f
1a7f9f
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
index 6a96e53979..e8361c77bc 100644
1a7f9f
--- a/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
@@ -96,6 +96,32 @@ meta_gpu_xrandr_poll_hardware (MetaGpu *gpu)
1a7f9f
   gpu_xrandr->need_hardware_poll = TRUE;
1a7f9f
 }
1a7f9f
 
1a7f9f
+static void
1a7f9f
+update_screen_size (MetaGpuXrandr *gpu_xrandr)
1a7f9f
+{
1a7f9f
+  MetaGpu *gpu = META_GPU (gpu_xrandr);
1a7f9f
+  MetaBackend *backend = meta_gpu_get_backend (gpu);
1a7f9f
+  MetaMonitorManager *monitor_manager =
1a7f9f
+    meta_backend_get_monitor_manager (backend);
1a7f9f
+  MetaMonitorManagerXrandr *monitor_manager_xrandr =
1a7f9f
+    META_MONITOR_MANAGER_XRANDR (monitor_manager);
1a7f9f
+  Display *xdisplay =
1a7f9f
+    meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
1a7f9f
+  int min_width, min_height;
1a7f9f
+  Screen *screen;
1a7f9f
+
1a7f9f
+  XRRGetScreenSizeRange (xdisplay, DefaultRootWindow (xdisplay),
1a7f9f
+                         &min_width,
1a7f9f
+                         &min_height,
1a7f9f
+                         &gpu_xrandr->max_screen_width,
1a7f9f
+                         &gpu_xrandr->max_screen_height);
1a7f9f
+
1a7f9f
+  screen = ScreenOfDisplay (xdisplay, DefaultScreen (xdisplay));
1a7f9f
+  /* This is updated because we called XRRUpdateConfiguration. */
1a7f9f
+  monitor_manager->screen_width = WidthOfScreen (screen);
1a7f9f
+  monitor_manager->screen_height = HeightOfScreen (screen);
1a7f9f
+}
1a7f9f
+
1a7f9f
 static gboolean
1a7f9f
 meta_gpu_xrandr_read_current (MetaGpu  *gpu,
1a7f9f
                               GError  **error)
1a7f9f
@@ -112,8 +138,6 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
1a7f9f
   RROutput primary_output;
1a7f9f
   unsigned int i, j;
1a7f9f
   GList *l;
1a7f9f
-  int min_width, min_height;
1a7f9f
-  Screen *screen;
1a7f9f
   GList *outputs = NULL;
1a7f9f
   GList *modes = NULL;
1a7f9f
   GList *crtcs = NULL;
1a7f9f
@@ -122,16 +146,7 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
1a7f9f
     XRRFreeScreenResources (gpu_xrandr->resources);
1a7f9f
   gpu_xrandr->resources = NULL;
1a7f9f
 
1a7f9f
-  XRRGetScreenSizeRange (xdisplay, DefaultRootWindow (xdisplay),
1a7f9f
-                         &min_width,
1a7f9f
-                         &min_height,
1a7f9f
-                         &gpu_xrandr->max_screen_width,
1a7f9f
-                         &gpu_xrandr->max_screen_height);
1a7f9f
-
1a7f9f
-  screen = ScreenOfDisplay (xdisplay, DefaultScreen (xdisplay));
1a7f9f
-  /* This is updated because we called XRRUpdateConfiguration. */
1a7f9f
-  monitor_manager->screen_width = WidthOfScreen (screen);
1a7f9f
-  monitor_manager->screen_height = HeightOfScreen (screen);
1a7f9f
+  update_screen_size (gpu_xrandr);
1a7f9f
 
1a7f9f
   if (gpu_xrandr->need_hardware_poll)
1a7f9f
     {
1a7f9f
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
index 90ccb74053..1b35545a09 100644
1a7f9f
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
@@ -140,12 +140,9 @@ x11_dpms_state_to_power_save (CARD16 dpms_state)
1a7f9f
 }
1a7f9f
 
1a7f9f
 static void
1a7f9f
-meta_monitor_manager_xrandr_read_current_state (MetaMonitorManager *manager)
1a7f9f
+meta_monitor_manager_xrandr_update_dpms_state (MetaMonitorManagerXrandr *manager_xrandr)
1a7f9f
 {
1a7f9f
-  MetaMonitorManagerXrandr *manager_xrandr =
1a7f9f
-    META_MONITOR_MANAGER_XRANDR (manager);
1a7f9f
-  MetaMonitorManagerClass *parent_class =
1a7f9f
-    META_MONITOR_MANAGER_CLASS (meta_monitor_manager_xrandr_parent_class);
1a7f9f
+  MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
1a7f9f
   Display *xdisplay = meta_monitor_manager_xrandr_get_xdisplay (manager_xrandr);
1a7f9f
   BOOL dpms_capable, dpms_enabled;
1a7f9f
   CARD16 dpms_state;
1a7f9f
@@ -161,6 +158,17 @@ meta_monitor_manager_xrandr_read_current_state (MetaMonitorManager *manager)
1a7f9f
     power_save_mode = META_POWER_SAVE_UNSUPPORTED;
1a7f9f
 
1a7f9f
   meta_monitor_manager_power_save_mode_changed (manager, power_save_mode);
1a7f9f
+}
1a7f9f
+
1a7f9f
+static void
1a7f9f
+meta_monitor_manager_xrandr_read_current_state (MetaMonitorManager *manager)
1a7f9f
+{
1a7f9f
+  MetaMonitorManagerXrandr *manager_xrandr =
1a7f9f
+    META_MONITOR_MANAGER_XRANDR (manager);
1a7f9f
+  MetaMonitorManagerClass *parent_class =
1a7f9f
+    META_MONITOR_MANAGER_CLASS (meta_monitor_manager_xrandr_parent_class);
1a7f9f
+
1a7f9f
+  meta_monitor_manager_xrandr_update_dpms_state (manager_xrandr);
1a7f9f
 
1a7f9f
   parent_class->read_current_state (manager);
1a7f9f
 }
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f
1a7f9f
1a7f9f
From 49307c3171b086ba5cdebe633f97a217042c8903 Mon Sep 17 00:00:00 2001
1a7f9f
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
1a7f9f
Date: Wed, 3 Oct 2018 10:50:47 +0200
1a7f9f
Subject: [PATCH 9/9] monitor-manager/xrandr: Create dummy screen sized monitor
1a7f9f
 if no RANDR
1a7f9f
1a7f9f
When there is no RANDR support enabled in the X server, we wont get
1a7f9f
notified of any monitors, resulting in mutter believing we're being
1a7f9f
headless. To get at least something working, although with no way
1a7f9f
configuration ability, lets pretend the whole screen is just a single
1a7f9f
monitor with a single output, crtc and mode.
1a7f9f
---
1a7f9f
 src/backends/x11/meta-gpu-xrandr.c            | 86 +++++++++++++++++++
1a7f9f
 .../x11/meta-monitor-manager-xrandr.c         | 22 ++++-
1a7f9f
 .../x11/meta-monitor-manager-xrandr.h         |  4 +
1a7f9f
 3 files changed, 111 insertions(+), 1 deletion(-)
1a7f9f
1a7f9f
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
index e8361c77bc..3ecb80bb2c 100644
1a7f9f
--- a/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-gpu-xrandr.c
1a7f9f
@@ -122,6 +122,89 @@ update_screen_size (MetaGpuXrandr *gpu_xrandr)
1a7f9f
   monitor_manager->screen_height = HeightOfScreen (screen);
1a7f9f
 }
1a7f9f
 
1a7f9f
+static gboolean
1a7f9f
+read_current_fallback (MetaGpuXrandr            *gpu_xrandr,
1a7f9f
+                       MetaMonitorManagerXrandr *monitor_manager_xrandr)
1a7f9f
+{
1a7f9f
+  MetaGpu *gpu = META_GPU (gpu_xrandr);
1a7f9f
+  MetaMonitorManager *monitor_manager =
1a7f9f
+    META_MONITOR_MANAGER (monitor_manager_xrandr);
1a7f9f
+  g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL;
1a7f9f
+  g_autofree char *mode_name = NULL;
1a7f9f
+  MetaCrtcMode *mode;
1a7f9f
+  MetaCrtc *crtc;
1a7f9f
+  g_autoptr (MetaOutputInfo) output_info = NULL;
1a7f9f
+  MetaOutputAssignment output_assignment;
1a7f9f
+  MetaOutput *output;
1a7f9f
+
1a7f9f
+  meta_monitor_manager_xrandr_update_dpms_state (monitor_manager_xrandr);
1a7f9f
+  update_screen_size (gpu_xrandr);
1a7f9f
+
1a7f9f
+  crtc_mode_info = meta_crtc_mode_info_new ();
1a7f9f
+  crtc_mode_info->width = monitor_manager->screen_width;
1a7f9f
+  crtc_mode_info->height = monitor_manager->screen_height;
1a7f9f
+  crtc_mode_info->refresh_rate = 60.0;
1a7f9f
+
1a7f9f
+  mode_name = g_strdup_printf ("%dx%d",
1a7f9f
+                               crtc_mode_info->width,
1a7f9f
+                               crtc_mode_info->height);
1a7f9f
+  mode = g_object_new (META_TYPE_CRTC_MODE,
1a7f9f
+                       "id", 0,
1a7f9f
+                       "name", mode_name,
1a7f9f
+                       "info", crtc_mode_info,
1a7f9f
+                       NULL);
1a7f9f
+
1a7f9f
+  meta_gpu_take_modes (gpu, g_list_prepend (NULL, mode));
1a7f9f
+
1a7f9f
+  crtc = g_object_new (META_TYPE_CRTC_XRANDR,
1a7f9f
+                       "id", 0,
1a7f9f
+                       "gpu", gpu,
1a7f9f
+                       NULL);
1a7f9f
+  meta_crtc_set_config (crtc,
1a7f9f
+                        &(graphene_rect_t) {
1a7f9f
+                          .size = {
1a7f9f
+                            .width = crtc_mode_info->width, 
1a7f9f
+                            .height = crtc_mode_info->width, 
1a7f9f
+                          },
1a7f9f
+                        },
1a7f9f
+                        mode,
1a7f9f
+                        META_MONITOR_TRANSFORM_NORMAL);
1a7f9f
+
1a7f9f
+  meta_gpu_take_crtcs (gpu, g_list_prepend (NULL, crtc));
1a7f9f
+
1a7f9f
+  output_info = meta_output_info_new ();
1a7f9f
+  output_info->name = g_strdup ("X11 Screen");
1a7f9f
+  output_info->vendor = g_strdup ("unknown");
1a7f9f
+  output_info->product = g_strdup ("unknown");
1a7f9f
+  output_info->serial = g_strdup ("unknown");
1a7f9f
+  output_info->hotplug_mode_update = TRUE;
1a7f9f
+  output_info->suggested_x = -1;
1a7f9f
+  output_info->suggested_y = -1;
1a7f9f
+  output_info->connector_type = META_CONNECTOR_TYPE_Unknown;
1a7f9f
+  output_info->modes = g_new0 (MetaCrtcMode *, 1);
1a7f9f
+  output_info->modes[0] = mode;
1a7f9f
+  output_info->n_modes = 1;
1a7f9f
+  output_info->preferred_mode = mode;
1a7f9f
+  output_info->possible_crtcs = g_new0 (MetaCrtc *, 1);
1a7f9f
+  output_info->possible_crtcs[0] = crtc;
1a7f9f
+  output_info->n_possible_crtcs = 1;
1a7f9f
+
1a7f9f
+  output = g_object_new (META_TYPE_OUTPUT_XRANDR,
1a7f9f
+                         "id", (uint64_t) 0,
1a7f9f
+                         "gpu", gpu,
1a7f9f
+                         "info", output_info,
1a7f9f
+                         NULL);
1a7f9f
+
1a7f9f
+  output_assignment = (MetaOutputAssignment) {
1a7f9f
+    .output = output,
1a7f9f
+    .is_primary = TRUE,
1a7f9f
+  };
1a7f9f
+  meta_output_assign_crtc (output, crtc, &output_assignment);
1a7f9f
+  meta_gpu_take_outputs (gpu, g_list_prepend (NULL, output));
1a7f9f
+
1a7f9f
+  return TRUE;
1a7f9f
+}
1a7f9f
+
1a7f9f
 static gboolean
1a7f9f
 meta_gpu_xrandr_read_current (MetaGpu  *gpu,
1a7f9f
                               GError  **error)
1a7f9f
@@ -142,6 +225,9 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
1a7f9f
   GList *modes = NULL;
1a7f9f
   GList *crtcs = NULL;
1a7f9f
 
1a7f9f
+  if (!meta_monitor_manager_xrandr_has_randr (monitor_manager_xrandr))
1a7f9f
+    return read_current_fallback (gpu_xrandr, monitor_manager_xrandr);
1a7f9f
+
1a7f9f
   if (gpu_xrandr->resources)
1a7f9f
     XRRFreeScreenResources (gpu_xrandr->resources);
1a7f9f
   gpu_xrandr->resources = NULL;
1a7f9f
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
index 1b35545a09..98eb080b6b 100644
1a7f9f
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
1a7f9f
@@ -76,6 +76,7 @@ struct _MetaMonitorManagerXrandr
1a7f9f
   guint logind_watch_id;
1a7f9f
   guint logind_signal_sub_id;
1a7f9f
 
1a7f9f
+  gboolean has_randr;
1a7f9f
   gboolean has_randr15;
1a7f9f
 
1a7f9f
   xcb_timestamp_t last_xrandr_set_timestamp;
1a7f9f
@@ -108,6 +109,12 @@ meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xran
1a7f9f
   return manager_xrandr->xdisplay;
1a7f9f
 }
1a7f9f
 
1a7f9f
+gboolean
1a7f9f
+meta_monitor_manager_xrandr_has_randr (MetaMonitorManagerXrandr *manager_xrandr)
1a7f9f
+{
1a7f9f
+  return manager_xrandr->has_randr;
1a7f9f
+}
1a7f9f
+
1a7f9f
 gboolean
1a7f9f
 meta_monitor_manager_xrandr_has_randr15 (MetaMonitorManagerXrandr *manager_xrandr)
1a7f9f
 {
1a7f9f
@@ -139,7 +146,7 @@ x11_dpms_state_to_power_save (CARD16 dpms_state)
1a7f9f
     }
1a7f9f
 }
1a7f9f
 
1a7f9f
-static void
1a7f9f
+void
1a7f9f
 meta_monitor_manager_xrandr_update_dpms_state (MetaMonitorManagerXrandr *manager_xrandr)
1a7f9f
 {
1a7f9f
   MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
1a7f9f
@@ -615,9 +622,18 @@ meta_monitor_manager_xrandr_apply_monitors_config (MetaMonitorManager      *mana
1a7f9f
                                                    MetaMonitorsConfigMethod method,
1a7f9f
                                                    GError                 **error)
1a7f9f
 {
1a7f9f
+  MetaMonitorManagerXrandr *manager_xrandr =
1a7f9f
+  META_MONITOR_MANAGER_XRANDR (manager);
1a7f9f
   GPtrArray *crtc_assignments;
1a7f9f
   GPtrArray *output_assignments;
1a7f9f
 
1a7f9f
+  if (!manager_xrandr->has_randr)
1a7f9f
+    {
1a7f9f
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1a7f9f
+                   "Tried to change configuration without XRANDR support");
1a7f9f
+      return FALSE;
1a7f9f
+    }
1a7f9f
+
1a7f9f
   if (!config)
1a7f9f
     {
1a7f9f
       if (!manager->in_init)
1a7f9f
@@ -1097,11 +1113,15 @@ meta_monitor_manager_xrandr_constructed (GObject *object)
1a7f9f
 			  &manager_xrandr->rr_event_base,
1a7f9f
 			  &manager_xrandr->rr_error_base))
1a7f9f
     {
1a7f9f
+      g_warning ("No RANDR support, monitor configuration disabled");
1a7f9f
       return;
1a7f9f
     }
1a7f9f
   else
1a7f9f
     {
1a7f9f
       int major_version, minor_version;
1a7f9f
+
1a7f9f
+      manager_xrandr->has_randr = TRUE;
1a7f9f
+
1a7f9f
       /* We only use ScreenChangeNotify, but GDK uses the others,
1a7f9f
 	 and we don't want to step on its toes */
1a7f9f
       XRRSelectInput (manager_xrandr->xdisplay,
1a7f9f
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.h b/src/backends/x11/meta-monitor-manager-xrandr.h
1a7f9f
index d55b3d2b88..dc75134a56 100644
1a7f9f
--- a/src/backends/x11/meta-monitor-manager-xrandr.h
1a7f9f
+++ b/src/backends/x11/meta-monitor-manager-xrandr.h
1a7f9f
@@ -33,9 +33,13 @@ G_DECLARE_FINAL_TYPE (MetaMonitorManagerXrandr, meta_monitor_manager_xrandr,
1a7f9f
 
1a7f9f
 Display * meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xrandr);
1a7f9f
 
1a7f9f
+gboolean meta_monitor_manager_xrandr_has_randr (MetaMonitorManagerXrandr *manager_xrandr);
1a7f9f
+
1a7f9f
 gboolean meta_monitor_manager_xrandr_has_randr15 (MetaMonitorManagerXrandr *manager_xrandr);
1a7f9f
 
1a7f9f
 gboolean meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager,
1a7f9f
                                                     XEvent                   *event);
1a7f9f
 
1a7f9f
+void meta_monitor_manager_xrandr_update_dpms_state (MetaMonitorManagerXrandr *manager_xrandr);
1a7f9f
+
1a7f9f
 #endif /* META_MONITOR_MANAGER_XRANDR_H */
1a7f9f
-- 
1a7f9f
2.31.1
1a7f9f