[gtk+] XI2: Push error traps around XIQueryDevice calls



commit 9b967ab8aff46b79494d75a3129fa8780545ecd1
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Nov 30 00:16:43 2011 -0500

    XI2: Push error traps around XIQueryDevice calls
    
    This may help against the crashes at resume time that some
    people have been hitting when input devices mysteriously
    disappear.

 gdk/x11/gdkdevice-xi2.c        |    7 +++++--
 gdk/x11/gdkdevicemanager-xi2.c |   30 ++++++++++++++++++++----------
 2 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
index b86d802..9eecb3c 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -192,10 +192,12 @@ gdk_x11_device_xi2_get_state (GdkDevice       *device,
 
       display = gdk_device_get_display (device);
 
+      gdk_x11_display_error_trap_push (display);
       info = XIQueryDevice (GDK_DISPLAY_XDISPLAY (display),
                             device_xi2->device_id, &ndevices);
+      gdk_x11_display_error_trap_pop_ignored (display);
 
-      for (i = 0, j = 0; i < info->num_classes; i++)
+      for (i = 0, j = 0; info && i < info->num_classes; i++)
         {
           XIAnyClassInfo *class_info = info->classes[i];
           GdkAxisUse use;
@@ -234,7 +236,8 @@ gdk_x11_device_xi2_get_state (GdkDevice       *device,
           j++;
         }
 
-      XIFreeDeviceInfo (info);
+      if (info)
+        XIFreeDeviceInfo (info);
     }
 
   if (mask)
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index c921ce0..afa9f54 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -586,9 +586,14 @@ handle_hierarchy_changed (GdkX11DeviceManagerXI2 *device_manager,
     {
       if (ev->info[i].flags & XIDeviceEnabled)
         {
+          gdk_x11_display_error_trap_push (display);
           info = XIQueryDevice (xdisplay, ev->info[i].deviceid, &ndevices);
-          add_device (device_manager, &info[0], TRUE);
-          XIFreeDeviceInfo (info);
+          gdk_x11_display_error_trap_pop_ignored (display);
+          if (info)
+            {
+              add_device (device_manager, &info[0], TRUE);
+              XIFreeDeviceInfo (info);
+            }
         }
       else if (ev->info[i].flags & XIDeviceDisabled)
         remove_device (device_manager, ev->info[i].deviceid);
@@ -614,15 +619,20 @@ handle_hierarchy_changed (GdkX11DeviceManagerXI2 *device_manager,
           /* Add new master if it's an attachment event */
           if (ev->info[i].flags & XISlaveAttached)
             {
+              gdk_x11_display_error_trap_push (display);
               info = XIQueryDevice (xdisplay, ev->info[i].deviceid, &ndevices);
-
-              master = g_hash_table_lookup (device_manager->id_table,
-                                            GINT_TO_POINTER (info->attachment));
-
-              _gdk_device_set_associated_device (slave, master);
-              _gdk_device_add_slave (master, slave);
-
-              g_signal_emit_by_name (device_manager, "device-changed", master);
+              gdk_x11_display_error_trap_pop_ignored (display);
+              if (info)
+                {
+                  master = g_hash_table_lookup (device_manager->id_table,
+                                                GINT_TO_POINTER (info->attachment));
+                  XIFreeDeviceInfo (info);
+
+                  _gdk_device_set_associated_device (slave, master);
+                  _gdk_device_add_slave (master, slave);
+
+                  g_signal_emit_by_name (device_manager, "device-changed", master);
+                }
             }
 
           g_signal_emit_by_name (device_manager, "device-changed", slave);



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