[gnome-settings-daemon/gnome-3-10] common: provide a helper function to close an XDevice safely



commit 26159cd4bcc9e4352ff55c9df7abfe9c6114ddac
Author: Peter Hutterer <peter hutterer who-t net>
Date:   Thu Feb 20 17:21:21 2014 +1000

    common: provide a helper function to close an XDevice safely
    
    XCloseDevice may cause a BadDevice error if the device disappeared before we
    close it.

 plugins/common/gsd-input-helper.c   |    8 ++++++++
 plugins/common/gsd-input-helper.h   |    1 +
 plugins/mouse/gsd-mouse-manager.c   |   30 +++++++++++++++---------------
 plugins/wacom/gsd-wacom-device.c    |    4 ++--
 plugins/wacom/gsd-wacom-manager.c   |    8 ++++----
 plugins/xrandr/gsd-xrandr-manager.c |    2 +-
 6 files changed, 31 insertions(+), 22 deletions(-)
---
diff --git a/plugins/common/gsd-input-helper.c b/plugins/common/gsd-input-helper.c
index fc4f10c..f81809e 100644
--- a/plugins/common/gsd-input-helper.c
+++ b/plugins/common/gsd-input-helper.c
@@ -576,3 +576,11 @@ get_disabled_devices (GdkDeviceManager *manager)
 
         return ret;
 }
+
+void
+xdevice_close (XDevice *xdevice)
+{
+    gdk_error_trap_push ();
+    XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+    gdk_error_trap_pop_ignored();
+}
diff --git a/plugins/common/gsd-input-helper.h b/plugins/common/gsd-input-helper.h
index 0bf328a..9e8a04d 100644
--- a/plugins/common/gsd-input-helper.h
+++ b/plugins/common/gsd-input-helper.h
@@ -81,6 +81,7 @@ gboolean  run_custom_command      (GdkDevice              *device,
 GList *   get_disabled_devices     (GdkDeviceManager       *manager);
 char *    xdevice_get_device_node  (int                     deviceid);
 int       xdevice_get_last_tool_id (int                     deviceid);
+void      xdevice_close      (XDevice                *xdevice);
 
 G_END_DECLS
 
diff --git a/plugins/mouse/gsd-mouse-manager.c b/plugins/mouse/gsd-mouse-manager.c
index 6623c90..3815a2e 100644
--- a/plugins/mouse/gsd-mouse-manager.c
+++ b/plugins/mouse/gsd-mouse-manager.c
@@ -371,7 +371,7 @@ set_left_handed (GsdMouseManager *manager,
         gdk_error_trap_pop_ignored ();
 
 out:
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
         g_free (buttons);
 }
 
@@ -468,7 +468,7 @@ set_motion (GsdMouseManager *manager,
 
     out:
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 }
 
 static void
@@ -515,7 +515,7 @@ set_middle_button (GsdMouseManager *manager,
         if (rc == Success)
                 XFree (data);
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 }
 
 /* Ensure that syndaemon dies together with us, to avoid running several of
@@ -622,7 +622,7 @@ set_tap_to_click (GdkDevice *device,
                 return;
 
         if (!device_is_touchpad (xdevice)) {
-                XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+                xdevice_close (xdevice);
                 return;
         }
 
@@ -648,7 +648,7 @@ set_tap_to_click (GdkDevice *device,
         if (gdk_error_trap_pop ())
                 g_warning ("Error in setting tap to click on \"%s\"", gdk_device_get_name (device));
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 }
 
 static void
@@ -673,7 +673,7 @@ set_horiz_scroll (GdkDevice *device,
                 return;
 
         if (!device_is_touchpad (xdevice)) {
-                XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+                xdevice_close (xdevice);
                 return;
         }
 
@@ -712,7 +712,7 @@ set_horiz_scroll (GdkDevice *device,
         if (rc == Success)
                 XFree (data);
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 
 }
 
@@ -740,7 +740,7 @@ set_scroll_method (GsdMouseManager         *manager,
                 return;
 
         if (!device_is_touchpad (xdevice)) {
-                XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+                xdevice_close (xdevice);
                 return;
         }
 
@@ -793,7 +793,7 @@ set_scroll_method (GsdMouseManager         *manager,
         if (rc == Success)
                 XFree (data);
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 }
 
 static void
@@ -811,7 +811,7 @@ set_touchpad_disabled (GdkDevice *device)
                 return;
 
         if (!device_is_touchpad (xdevice)) {
-                XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+                xdevice_close (xdevice);
                 return;
         }
 
@@ -820,7 +820,7 @@ set_touchpad_disabled (GdkDevice *device)
         else
                 g_debug ("Disabled device \"%s\" (%d)", gdk_device_get_name (device), id);
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 }
 
 static void
@@ -836,7 +836,7 @@ set_touchpad_enabled (int id)
                 return;
 
         if (!device_is_touchpad (xdevice)) {
-                XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+                xdevice_close (xdevice);
                 return;
         }
 
@@ -845,7 +845,7 @@ set_touchpad_enabled (int id)
         else
                 g_debug ("Enabled device %d", id);
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 }
 
 static void
@@ -968,7 +968,7 @@ set_natural_scroll (GsdMouseManager *manager,
                 return;
 
         if (!device_is_touchpad (xdevice)) {
-                XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+                xdevice_close (xdevice);
                 return;
         }
 
@@ -1009,7 +1009,7 @@ set_natural_scroll (GsdMouseManager *manager,
         if (rc == Success)
                 XFree (data);
 
-        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+        xdevice_close (xdevice);
 }
 
 static void
diff --git a/plugins/wacom/gsd-wacom-device.c b/plugins/wacom/gsd-wacom-device.c
index 12204e1..58cbacf 100644
--- a/plugins/wacom/gsd-wacom-device.c
+++ b/plugins/wacom/gsd-wacom-device.c
@@ -1889,7 +1889,7 @@ gsd_wacom_device_get_area (GsdWacomDevice *device)
                                 XA_INTEGER, &realtype, &realformat, &nitems,
                                 &bytes_after, &data);
        if (gdk_error_trap_pop () || rc != Success || realtype == None || bytes_after != 0 || nitems != 4) {
-               XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+               xdevice_close (xdevice);
                return NULL;
        }
 
@@ -1898,7 +1898,7 @@ gsd_wacom_device_get_area (GsdWacomDevice *device)
                device_area[i] = ((long *)data)[i];
 
        XFree (data);
-       XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
+       xdevice_close (xdevice);
 
        return device_area;
 }
diff --git a/plugins/wacom/gsd-wacom-manager.c b/plugins/wacom/gsd-wacom-manager.c
index 1e3d202..5ef474d 100644
--- a/plugins/wacom/gsd-wacom-manager.c
+++ b/plugins/wacom/gsd-wacom-manager.c
@@ -261,7 +261,7 @@ wacom_set_property (GsdWacomDevice *device,
 
        xdev = open_device (device);
        device_set_property (xdev, gsd_wacom_device_get_tool_name (device), property);
-       XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdev);
+       xdevice_close (xdev);
 }
 
 static void
@@ -443,7 +443,7 @@ set_absolute (GsdWacomDevice  *device,
        if (gdk_error_trap_pop ())
                g_error ("Failed to set mode \"%s\" for \"%s\".",
                         is_absolute ? "Absolute" : "Relative", gsd_wacom_device_get_tool_name (device));
-       XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdev);
+       xdevice_close (xdev);
 }
 
 static void
@@ -591,7 +591,7 @@ set_device_buttonmap (GsdWacomDevice *device,
 
        g_free (map);
 
-       XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdev);
+       xdevice_close (xdev);
 }
 
 static void
@@ -797,7 +797,7 @@ reset_pad_buttons (GsdWacomDevice *device)
        reset_touch_buttons (xdev, def_touchstrip_buttons, "Wacom Strip Buttons");
        gdk_error_trap_pop_ignored ();
 
-       XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdev);
+       xdevice_close (xdev);
 
        /* Reset all the LEDs and OLEDs*/
        buttons = gsd_wacom_device_get_buttons (device);
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index 1af65ea..f90811a 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -1190,7 +1190,7 @@ rotate_touchscreens (GsdXrandrManager *mgr,
                                          evdev_rotations[rot_idx].matrix[8]);
                         }
 
-                        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
+                        xdevice_close (device);
                 }
         }
         XFreeDeviceList (device_info);


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