Blame SOURCES/0002-monitor-manager-xrandr-Create-dummy-screen-sized-mon.patch

bfb30e
From 85484d8f5d75764ab74308da7b21411c3fe4a2da Mon Sep 17 00:00:00 2001
bfb30e
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
bfb30e
Date: Wed, 3 Oct 2018 10:50:47 +0200
bfb30e
Subject: [PATCH 2/2] monitor-manager/xrandr: Create dummy screen sized monitor
bfb30e
 if no RANDR
bfb30e
bfb30e
When there is no RANDR support enabled in the X server, we wont get
bfb30e
notified of any monitors, resulting in mutter believing we're being
bfb30e
headless. To get at least something working, although with no way
bfb30e
configuration ability, lets pretend the whole screen is just a single
bfb30e
monitor with a single output, crtc and mode.
bfb30e
---
bfb30e
 src/backends/x11/meta-gpu-xrandr.c            | 60 +++++++++++++++++++
bfb30e
 .../x11/meta-monitor-manager-xrandr.c         | 22 ++++++-
bfb30e
 .../x11/meta-monitor-manager-xrandr.h         |  4 ++
bfb30e
 3 files changed, 85 insertions(+), 1 deletion(-)
bfb30e
bfb30e
diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
bfb30e
index 1884278ca..22e7e70e0 100644
bfb30e
--- a/src/backends/x11/meta-gpu-xrandr.c
bfb30e
+++ b/src/backends/x11/meta-gpu-xrandr.c
bfb30e
@@ -115,6 +115,63 @@ update_screen_size (MetaGpuXrandr *gpu_xrandr)
bfb30e
   monitor_manager->screen_height = HeightOfScreen (screen);
bfb30e
 }
bfb30e
 
bfb30e
+static gboolean
bfb30e
+read_current_fallback (MetaGpuXrandr            *gpu_xrandr,
bfb30e
+                       MetaMonitorManagerXrandr *monitor_manager_xrandr)
bfb30e
+{
bfb30e
+  MetaGpu *gpu = META_GPU (gpu_xrandr);
bfb30e
+  MetaMonitorManager *monitor_manager =
bfb30e
+    META_MONITOR_MANAGER (monitor_manager_xrandr);
bfb30e
+  MetaCrtcMode *mode;
bfb30e
+  MetaCrtc *crtc;
bfb30e
+  MetaOutput *output;
bfb30e
+
bfb30e
+  meta_monitor_manager_xrandr_update_dpms_state (monitor_manager_xrandr);
bfb30e
+  update_screen_size (gpu_xrandr);
bfb30e
+
bfb30e
+  mode = g_object_new (META_TYPE_CRTC_MODE, NULL);
bfb30e
+  mode->mode_id = 0;
bfb30e
+  mode->width = monitor_manager->screen_width;
bfb30e
+  mode->height = monitor_manager->screen_height;
bfb30e
+  mode->refresh_rate = 60.0;
bfb30e
+  mode->name = g_strdup_printf ("%dx%d", mode->width, mode->height);
bfb30e
+
bfb30e
+  meta_gpu_take_modes (gpu, g_list_prepend (NULL, mode));
bfb30e
+
bfb30e
+  crtc = g_object_new (META_TYPE_CRTC, NULL);
bfb30e
+  crtc->gpu = gpu;
bfb30e
+  crtc->crtc_id = 0;
bfb30e
+  crtc->rect = (MetaRectangle) { .width = mode->width, .height = mode->height };
bfb30e
+  crtc->current_mode = mode;
bfb30e
+
bfb30e
+  meta_gpu_take_crtcs (gpu, g_list_prepend (NULL, crtc));
bfb30e
+
bfb30e
+  output = g_object_new (META_TYPE_OUTPUT, NULL);
bfb30e
+  output->gpu = gpu;
bfb30e
+  output->winsys_id = 0;
bfb30e
+  output->name = g_strdup ("X11 Screen");
bfb30e
+  output->vendor = g_strdup ("unknown");
bfb30e
+  output->product = g_strdup ("unknown");
bfb30e
+  output->serial = g_strdup ("unknown");
bfb30e
+  output->hotplug_mode_update = TRUE;
bfb30e
+  output->suggested_x = -1;
bfb30e
+  output->suggested_y = -1;
bfb30e
+  output->connector_type = META_CONNECTOR_TYPE_Unknown;
bfb30e
+  output->modes = g_new0 (MetaCrtcMode *, 1);
bfb30e
+  output->modes[0] = mode;
bfb30e
+  output->n_modes = 1;
bfb30e
+  output->preferred_mode = mode;
bfb30e
+  output->possible_crtcs = g_new0 (MetaCrtc *, 1);
bfb30e
+  output->possible_crtcs[0] = crtc;
bfb30e
+  output->n_possible_crtcs = 1;
bfb30e
+  meta_output_assign_crtc (output, crtc);
bfb30e
+  output->is_primary = TRUE;
bfb30e
+
bfb30e
+  meta_gpu_take_outputs (gpu, g_list_prepend (NULL, output));
bfb30e
+
bfb30e
+  return TRUE;
bfb30e
+}
bfb30e
+
bfb30e
 static gboolean
bfb30e
 meta_gpu_xrandr_read_current (MetaGpu  *gpu,
bfb30e
                               GError  **error)
bfb30e
@@ -133,6 +190,9 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
bfb30e
   GList *modes = NULL;
bfb30e
   GList *crtcs = NULL;
bfb30e
 
bfb30e
+  if (!meta_monitor_manager_xrandr_has_randr (monitor_manager_xrandr))
bfb30e
+    return read_current_fallback (gpu_xrandr, monitor_manager_xrandr);
bfb30e
+
bfb30e
   if (gpu_xrandr->resources)
bfb30e
     XRRFreeScreenResources (gpu_xrandr->resources);
bfb30e
   gpu_xrandr->resources = NULL;
bfb30e
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
bfb30e
index 7a0b43ac4..d6306faeb 100644
bfb30e
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
bfb30e
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
bfb30e
@@ -75,6 +75,7 @@ struct _MetaMonitorManagerXrandr
bfb30e
   guint logind_watch_id;
bfb30e
   guint logind_signal_sub_id;
bfb30e
 
bfb30e
+  gboolean has_randr;
bfb30e
   gboolean has_randr15;
bfb30e
 
bfb30e
   /*
bfb30e
@@ -114,6 +115,12 @@ meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xran
bfb30e
   return manager_xrandr->xdisplay;
bfb30e
 }
bfb30e
 
bfb30e
+gboolean
bfb30e
+meta_monitor_manager_xrandr_has_randr (MetaMonitorManagerXrandr *manager_xrandr)
bfb30e
+{
bfb30e
+  return manager_xrandr->has_randr;
bfb30e
+}
bfb30e
+
bfb30e
 gboolean
bfb30e
 meta_monitor_manager_xrandr_has_randr15 (MetaMonitorManagerXrandr *manager_xrandr)
bfb30e
 {
bfb30e
@@ -145,7 +152,7 @@ x11_dpms_state_to_power_save (CARD16 dpms_state)
bfb30e
     }
bfb30e
 }
bfb30e
 
bfb30e
-static void
bfb30e
+void
bfb30e
 meta_monitor_manager_xrandr_update_dpms_state (MetaMonitorManagerXrandr *manager_xrandr)
bfb30e
 {
bfb30e
   MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_xrandr);
bfb30e
@@ -637,9 +644,18 @@ meta_monitor_manager_xrandr_apply_monitors_config (MetaMonitorManager      *mana
bfb30e
                                                    MetaMonitorsConfigMethod method,
bfb30e
                                                    GError                 **error)
bfb30e
 {
bfb30e
+  MetaMonitorManagerXrandr *manager_xrandr =
bfb30e
+    META_MONITOR_MANAGER_XRANDR (manager);
bfb30e
   GPtrArray *crtc_infos;
bfb30e
   GPtrArray *output_infos;
bfb30e
 
bfb30e
+  if (!manager_xrandr->has_randr)
bfb30e
+    {
bfb30e
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
bfb30e
+                   "Tried to change configuration without XRANDR support");
bfb30e
+      return FALSE;
bfb30e
+    }
bfb30e
+
bfb30e
   if (!config)
bfb30e
     {
bfb30e
       meta_monitor_manager_xrandr_rebuild_derived (manager, NULL);
bfb30e
@@ -1105,11 +1121,15 @@ meta_monitor_manager_xrandr_constructed (GObject *object)
bfb30e
 			  &manager_xrandr->rr_event_base,
bfb30e
 			  &manager_xrandr->rr_error_base))
bfb30e
     {
bfb30e
+      g_warning ("No RANDR support, monitor configuration disabled");
bfb30e
       return;
bfb30e
     }
bfb30e
   else
bfb30e
     {
bfb30e
       int major_version, minor_version;
bfb30e
+
bfb30e
+      manager_xrandr->has_randr = TRUE;
bfb30e
+
bfb30e
       /* We only use ScreenChangeNotify, but GDK uses the others,
bfb30e
 	 and we don't want to step on its toes */
bfb30e
       XRRSelectInput (manager_xrandr->xdisplay,
bfb30e
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.h b/src/backends/x11/meta-monitor-manager-xrandr.h
bfb30e
index d55b3d2b8..dc75134a5 100644
bfb30e
--- a/src/backends/x11/meta-monitor-manager-xrandr.h
bfb30e
+++ b/src/backends/x11/meta-monitor-manager-xrandr.h
bfb30e
@@ -33,9 +33,13 @@ G_DECLARE_FINAL_TYPE (MetaMonitorManagerXrandr, meta_monitor_manager_xrandr,
bfb30e
 
bfb30e
 Display * meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xrandr);
bfb30e
 
bfb30e
+gboolean meta_monitor_manager_xrandr_has_randr (MetaMonitorManagerXrandr *manager_xrandr);
bfb30e
+
bfb30e
 gboolean meta_monitor_manager_xrandr_has_randr15 (MetaMonitorManagerXrandr *manager_xrandr);
bfb30e
 
bfb30e
 gboolean meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager,
bfb30e
                                                     XEvent                   *event);
bfb30e
 
bfb30e
+void meta_monitor_manager_xrandr_update_dpms_state (MetaMonitorManagerXrandr *manager_xrandr);
bfb30e
+
bfb30e
 #endif /* META_MONITOR_MANAGER_XRANDR_H */
bfb30e
-- 
bfb30e
2.23.0
bfb30e