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