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

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