Blame SOURCES/0001-monitor-manager-xrandr-Be-more-robust-when-reading-X.patch

2c033f
From fe1d707a8ca1656063a1b93bf47a78ac20225d7b Mon Sep 17 00:00:00 2001
2c033f
From: Rui Matos <tiagomatos@gmail.com>
2c033f
Date: Thu, 15 Oct 2015 19:34:40 +0200
2c033f
Subject: [PATCH 1/4] monitor-manager-xrandr: Be more robust when reading
2c033f
 XRROutputInfos
2c033f
2c033f
We might get modes in XRROutputInfos that aren't in the
2c033f
XRRScreenResources we get earlier. This always seems to be transient,
2c033f
i.e. when it happens, the X server will usually send us a follow up
2c033f
RRScreenChangeNotify where we then get a "stable" view of the world
2c033f
again.
2c033f
2c033f
In any case, when these glitches happen, we end up with NULL pointers
2c033f
in the MetaOutput->modes array which makes us crash later on. This
2c033f
patch ensures that doesn't happen.
2c033f
2c033f
https://bugzilla.gnome.org/show_bug.cgi?id=756660
2c033f
---
2c033f
 src/backends/x11/meta-monitor-manager-xrandr.c | 42 ++++++++++++++++++--------
2c033f
 1 file changed, 29 insertions(+), 13 deletions(-)
2c033f
2c033f
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
2c033f
index 9c65cab..6653b33 100644
2c033f
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
2c033f
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
2c033f
@@ -406,6 +406,32 @@ output_get_suggested_y (MetaMonitorManagerXrandr *manager_xrandr,
2c033f
   return -1;
2c033f
 }
2c033f
 
2c033f
+static void
2c033f
+output_get_modes (MetaMonitorManager *manager,
2c033f
+                  MetaOutput         *meta_output,
2c033f
+                  XRROutputInfo      *output)
2c033f
+{
2c033f
+  guint j, k;
2c033f
+  guint n_actual_modes;
2c033f
+
2c033f
+  meta_output->modes = g_new0 (MetaMonitorMode *, output->nmode);
2c033f
+
2c033f
+  n_actual_modes = 0;
2c033f
+  for (j = 0; j < (guint)output->nmode; j++)
2c033f
+    {
2c033f
+      for (k = 0; k < manager->n_modes; k++)
2c033f
+        {
2c033f
+          if (output->modes[j] == (XID)manager->modes[k].mode_id)
2c033f
+            {
2c033f
+              meta_output->modes[n_actual_modes] = &manager->modes[k];
2c033f
+              n_actual_modes += 1;
2c033f
+              break;
2c033f
+            }
2c033f
+        }
2c033f
+    }
2c033f
+  meta_output->n_modes = n_actual_modes;
2c033f
+}
2c033f
+
2c033f
 static char *
2c033f
 get_xmode_name (XRRModeInfo *xmode)
2c033f
 {
2c033f
@@ -548,6 +574,8 @@ meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager)
2c033f
       MetaOutput *meta_output;
2c033f
 
2c033f
       output = XRRGetOutputInfo (manager_xrandr->xdisplay, resources, resources->outputs[i]);
2c033f
+      if (!output)
2c033f
+        continue;
2c033f
 
2c033f
       meta_output = &manager->outputs[n_actual_outputs];
2c033f
 
2c033f
@@ -596,19 +624,7 @@ meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager)
2c033f
 	  meta_output->suggested_x = output_get_suggested_x (manager_xrandr, meta_output);
2c033f
 	  meta_output->suggested_y = output_get_suggested_y (manager_xrandr, meta_output);
2c033f
 
2c033f
-	  meta_output->n_modes = output->nmode;
2c033f
-	  meta_output->modes = g_new0 (MetaMonitorMode *, meta_output->n_modes);
2c033f
-	  for (j = 0; j < meta_output->n_modes; j++)
2c033f
-	    {
2c033f
-	      for (k = 0; k < manager->n_modes; k++)
2c033f
-		{
2c033f
-		  if (output->modes[j] == (XID)manager->modes[k].mode_id)
2c033f
-		    {
2c033f
-		      meta_output->modes[j] = &manager->modes[k];
2c033f
-		      break;
2c033f
-		    }
2c033f
-		}
2c033f
-	    }
2c033f
+	  output_get_modes (manager, meta_output, output);
2c033f
 	  meta_output->preferred_mode = meta_output->modes[0];
2c033f
 
2c033f
 	  meta_output->n_possible_crtcs = output->ncrtc;
2c033f
-- 
2c033f
2.5.0
2c033f