[gtk: 1/2] x11: Trap errors happening when getting output properties




commit f1551a87f62764082bf7cd1430c91d62a3f12f25
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon May 2 17:28:36 2022 +0200

    x11: Trap errors happening when getting output properties
    
    This is to avoid getting X11 errors (thus aborting/exiting with a
    failure) during rapid hotplugs, which may happen during e.g. CI testing.

 gdk/x11/gdkscreen-x11.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c
index bde0b7dd54..6013265151 100644
--- a/gdk/x11/gdkscreen-x11.c
+++ b/gdk/x11/gdkscreen-x11.c
@@ -518,19 +518,6 @@ init_randr15 (GdkX11Screen *x11_screen)
           XRRFreeCrtcInfo (crtc);
         }
 
-      monitor = find_monitor_by_output (x11_display, output);
-      if (monitor)
-        monitor->remove = FALSE;
-      else
-        {
-          monitor = g_object_new (GDK_TYPE_X11_MONITOR,
-                                  "display", display,
-                                  NULL);
-          monitor->output = output;
-          monitor->add = TRUE;
-          g_list_store_append (x11_display->monitors, monitor);
-        }
-
       /* Fetch minimal manufacturer information (PNP ID) from EDID */
       {
         #define EDID_LENGTH 128
@@ -543,6 +530,7 @@ init_randr15 (GdkX11Screen *x11_screen)
 
         edid_atom = XInternAtom (disp, RR_PROPERTY_RANDR_EDID, FALSE);
 
+        gdk_x11_display_error_trap_push (display);
         XRRGetOutputProperty (disp, output,
                               edid_atom,
                               0,
@@ -555,6 +543,11 @@ init_randr15 (GdkX11Screen *x11_screen)
                               &nbytes,
                               &bytes_left,
                               &prop);
+        if (gdk_x11_display_error_trap_pop (display))
+          {
+            XRRFreeOutputInfo (output_info);
+            continue;
+          }
 
         // Check partial EDID header (whole header: 00 ff ff ff ff ff ff 00)
         if (nbytes >= EDID_LENGTH && prop[0] == 0x00 && prop[1] == 0xff)
@@ -575,6 +568,19 @@ init_randr15 (GdkX11Screen *x11_screen)
         #undef EDID_LENGTH
       }
 
+      monitor = find_monitor_by_output (x11_display, output);
+      if (monitor)
+        monitor->remove = FALSE;
+      else
+        {
+          monitor = g_object_new (GDK_TYPE_X11_MONITOR,
+                                  "display", display,
+                                  NULL);
+          monitor->output = output;
+          monitor->add = TRUE;
+          g_list_store_append (x11_display->monitors, monitor);
+        }
+
       gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry);
       name = g_strndup (output_info->name, output_info->nameLen);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]