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

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