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

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