From daa8b098a434809baaf92441b43d09c750953e15 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 20 Aug 2012 15:53:55 +0100 Subject: [PATCH] mouse: Update from gnome-settings-daemon --- panels/mouse/gsd-input-helper.c | 37 +++++++++++++++++++++++++++------ panels/mouse/gsd-input-helper.h | 2 ++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/panels/mouse/gsd-input-helper.c b/panels/mouse/gsd-input-helper.c index cf9e83d67..c15e135ab 100644 --- a/panels/mouse/gsd-input-helper.c +++ b/panels/mouse/gsd-input-helper.c @@ -83,6 +83,8 @@ device_set_property (XDevice *xdevice, xdevice, prop, realtype, realformat, PropModeReplace, data, nitems); + XFree (data); + if (gdk_error_trap_pop ()) { g_warning ("Error in setting \"%s\" for \"%s\"", property->name, device_name); return FALSE; @@ -129,7 +131,14 @@ supports_xinput2_devices (int *opcode) if (XIQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor) != Success) { gdk_error_trap_pop_ignored (); - return FALSE; + /* try for 2.2, maybe gtk has already announced 2.2 support */ + gdk_error_trap_push (); + major = 2; + minor = 2; + if (XIQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor) != Success) { + gdk_error_trap_pop_ignored (); + return FALSE; + } } gdk_error_trap_pop_ignored (); @@ -179,6 +188,12 @@ device_info_is_touchscreen (XDeviceInfo *device_info) return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TOUCHSCREEN, False)); } +gboolean +device_info_is_mouse (XDeviceInfo *device_info) +{ + return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_MOUSE, False)); +} + static gboolean device_type_is_present (InfoIdentifyFunc info_func, DeviceIdentifyFunc device_func) @@ -241,6 +256,13 @@ touchpad_is_present (void) device_is_touchpad); } +gboolean +mouse_is_present (void) +{ + return device_type_is_present (device_info_is_mouse, + NULL); +} + char * xdevice_get_device_node (int deviceid) { @@ -328,14 +350,16 @@ xdevice_get_last_tool_id (int deviceid) if (!prop) return -1; + data = NULL; + gdk_error_trap_push (); - if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), + if (XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceid, prop, 0, 1000, False, AnyPropertyType, &act_type, &act_format, - &nitems, &bytes_after, &data) == Success) { + &nitems, &bytes_after, &data) != Success) { gdk_error_trap_pop_ignored (); - return -1; + goto out; } if (gdk_error_trap_pop ()) @@ -366,10 +390,11 @@ xdevice_get_last_tool_id (int deviceid) /* That means that no tool was set down yet */ if (id == STYLUS_DEVICE_ID || id == ERASER_DEVICE_ID) - return 0x0; + id = 0x0; out: - XFree (data); + if (data != NULL) + XFree (data); return id; } diff --git a/panels/mouse/gsd-input-helper.h b/panels/mouse/gsd-input-helper.h index dfde51f2e..fb898b0d7 100644 --- a/panels/mouse/gsd-input-helper.h +++ b/panels/mouse/gsd-input-helper.h @@ -61,9 +61,11 @@ gboolean device_is_touchpad (XDevice *xdevice); gboolean device_info_is_touchpad (XDeviceInfo *device_info); gboolean device_info_is_touchscreen (XDeviceInfo *device_info); +gboolean device_info_is_mouse (XDeviceInfo *device_info); gboolean touchpad_is_present (void); gboolean touchscreen_is_present (void); +gboolean mouse_is_present (void); gboolean device_set_property (XDevice *xdevice, const char *device_name,