Blob Blame History Raw
From 7ce6f10f6966ec6e66549a6878ae333d0fe1e84c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
Date: Wed, 3 Oct 2018 10:50:07 +0200
Subject: [PATCH 1/2] gpu/xrandr: Move dpms state and screen size updating into
 helpers

To be used by no-Xrandr fallback path.
---
 src/backends/x11/meta-gpu-xrandr.c | 70 ++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 24 deletions(-)

diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c
index add80c0d2d..a4e187a49a 100644
--- a/src/backends/x11/meta-gpu-xrandr.c
+++ b/src/backends/x11/meta-gpu-xrandr.c
@@ -91,31 +91,15 @@ meta_gpu_xrandr_poll_hardware (MetaGpu *gpu)
   gpu_xrandr->need_hardware_poll = TRUE;
 }
 
-static gboolean
-meta_gpu_xrandr_read_current (MetaGpu  *gpu,
-                              GError  **error)
+static void
+update_dpms_state (MetaMonitorManagerXrandr *monitor_manager_xrandr)
 {
-  MetaGpuXrandr *gpu_xrandr = META_GPU_XRANDR (gpu);
-  MetaMonitorManager *monitor_manager = meta_gpu_get_monitor_manager (gpu);
-  MetaMonitorManagerXrandr *monitor_manager_xrandr =
-    META_MONITOR_MANAGER_XRANDR (monitor_manager);
+  MetaMonitorManager *monitor_manager =
+    META_MONITOR_MANAGER (monitor_manager_xrandr);
   Display *xdisplay =
     meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
-  XRRScreenResources *resources;
-  RROutput primary_output;
-  unsigned int i, j;
-  GList *l;
-  int min_width, min_height;
-  Screen *screen;
   BOOL dpms_capable, dpms_enabled;
   CARD16 dpms_state;
-  GList *outputs = NULL;
-  GList *modes = NULL;
-  GList *crtcs = NULL;
-
-  if (gpu_xrandr->resources)
-    XRRFreeScreenResources (gpu_xrandr->resources);
-  gpu_xrandr->resources = NULL;
 
   dpms_capable = DPMSCapable (xdisplay);
 
@@ -146,6 +130,47 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
     {
       monitor_manager->power_save_mode = META_POWER_SAVE_UNSUPPORTED;
     }
+}
+
+static void
+update_screen_size (MetaMonitorManagerXrandr *monitor_manager_xrandr)
+{
+  MetaMonitorManager *monitor_manager =
+    META_MONITOR_MANAGER (monitor_manager_xrandr);
+  Display *xdisplay =
+    meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
+  Screen *screen;
+
+  screen = ScreenOfDisplay (xdisplay, DefaultScreen (xdisplay));
+
+  monitor_manager->screen_width = WidthOfScreen (screen);
+  monitor_manager->screen_height = HeightOfScreen (screen);
+}
+
+static gboolean
+meta_gpu_xrandr_read_current (MetaGpu  *gpu,
+                              GError  **error)
+{
+  MetaGpuXrandr *gpu_xrandr = META_GPU_XRANDR (gpu);
+  MetaMonitorManager *monitor_manager = meta_gpu_get_monitor_manager (gpu);
+  MetaMonitorManagerXrandr *monitor_manager_xrandr =
+    META_MONITOR_MANAGER_XRANDR (monitor_manager);
+  Display *xdisplay =
+    meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
+  XRRScreenResources *resources;
+  RROutput primary_output;
+  unsigned int i, j;
+  GList *l;
+  int min_width, min_height;
+  GList *outputs = NULL;
+  GList *modes = NULL;
+  GList *crtcs = NULL;
+
+  if (gpu_xrandr->resources)
+    XRRFreeScreenResources (gpu_xrandr->resources);
+  gpu_xrandr->resources = NULL;
+
+  update_dpms_state (monitor_manager_xrandr);
 
   XRRGetScreenSizeRange (xdisplay, DefaultRootWindow (xdisplay),
                          &min_width,
@@ -153,10 +178,7 @@ meta_gpu_xrandr_read_current (MetaGpu  *gpu,
                          &gpu_xrandr->max_screen_width,
                          &gpu_xrandr->max_screen_height);
 
-  screen = ScreenOfDisplay (xdisplay, DefaultScreen (xdisplay));
-  /* This is updated because we called XRRUpdateConfiguration. */
-  monitor_manager->screen_width = WidthOfScreen (screen);
-  monitor_manager->screen_height = HeightOfScreen (screen);
+  update_screen_size (monitor_manager_xrandr);
 
   if (gpu_xrandr->need_hardware_poll)
     {
-- 
2.17.1