From e23f77f1e62afd8db712ab75b788dd92f06b9b2a Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 1 Mar 2014 13:06:25 -0500 Subject: [PATCH] evdev: Extend the device open callback with a close callback as well We need to return the device to logind with ReleaseDevice(). https://bugzilla.gnome.org/show_bug.cgi?id=726199 --- clutter/evdev/clutter-device-manager-evdev.c | 29 ++++++++++++-------- clutter/evdev/clutter-evdev.h | 7 +++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/clutter/evdev/clutter-device-manager-evdev.c b/clutter/evdev/clutter-device-manager-evdev.c index bdca5d477..c7a5437aa 100644 --- a/clutter/evdev/clutter-device-manager-evdev.c +++ b/clutter/evdev/clutter-device-manager-evdev.c @@ -116,8 +116,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (ClutterDeviceManagerEvdev, clutter_device_manager_evdev, CLUTTER_TYPE_DEVICE_MANAGER) -static ClutterOpenDeviceCallback open_callback; -static gpointer open_callback_data; +static ClutterOpenDeviceCallback device_open_callback; +static ClutterCloseDeviceCallback device_close_callback; +static gpointer device_callback_data; static const char *device_type_str[] = { "pointer", /* CLUTTER_POINTER_DEVICE */ @@ -1115,11 +1116,11 @@ open_restricted (const char *path, { gint fd; - if (open_callback) + if (device_open_callback) { GError *error = NULL; - fd = open_callback (path, flags, open_callback_data, &error); + fd = device_open_callback (path, flags, device_callback_data, &error); if (fd < 0) { @@ -1143,7 +1144,10 @@ static void close_restricted (int fd, void *user_data) { - close (fd); + if (device_close_callback) + device_close_callback (fd, device_callback_data); + else + close (fd); } static const struct libinput_interface libinput_interface = { @@ -1455,8 +1459,9 @@ clutter_evdev_reclaim_devices (void) } /** - * clutter_evdev_set_open_callback: (skip) - * @callback: the user replacement for open() + * clutter_evdev_set_device_callbacks: (skip) + * @open_callback: the user replacement for open() + * @close_callback: the user replacement for close() * @user_data: user data for @callback * * Through this function, the application can set a custom callback @@ -1472,11 +1477,13 @@ clutter_evdev_reclaim_devices (void) * Stability: unstable */ void -clutter_evdev_set_open_callback (ClutterOpenDeviceCallback callback, - gpointer user_data) +clutter_evdev_set_device_callbacks (ClutterOpenDeviceCallback open_callback, + ClutterCloseDeviceCallback close_callback, + gpointer user_data) { - open_callback = callback; - open_callback_data = user_data; + device_open_callback = open_callback; + device_close_callback = close_callback; + device_callback_data = user_data; } /** diff --git a/clutter/evdev/clutter-evdev.h b/clutter/evdev/clutter-evdev.h index 104e3b413..f97a3f5af 100644 --- a/clutter/evdev/clutter-evdev.h +++ b/clutter/evdev/clutter-evdev.h @@ -48,10 +48,13 @@ typedef int (*ClutterOpenDeviceCallback) (const char *path, int flags, gpointer user_data, GError **error); +typedef void (*ClutterCloseDeviceCallback) (int fd, + gpointer user_data); CLUTTER_AVAILABLE_IN_1_16 -void clutter_evdev_set_open_callback (ClutterOpenDeviceCallback callback, - gpointer user_data); +void clutter_evdev_set_device_callbacks (ClutterOpenDeviceCallback open_callback, + ClutterCloseDeviceCallback close_callback, + gpointer user_data); CLUTTER_AVAILABLE_IN_1_10 void clutter_evdev_release_devices (void);