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
This commit is contained in:
Jasper St. Pierre 2014-03-01 13:06:25 -05:00
parent aa5a4e9e3c
commit e23f77f1e6
2 changed files with 23 additions and 13 deletions

View File

@ -116,8 +116,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (ClutterDeviceManagerEvdev,
clutter_device_manager_evdev, clutter_device_manager_evdev,
CLUTTER_TYPE_DEVICE_MANAGER) CLUTTER_TYPE_DEVICE_MANAGER)
static ClutterOpenDeviceCallback open_callback; static ClutterOpenDeviceCallback device_open_callback;
static gpointer open_callback_data; static ClutterCloseDeviceCallback device_close_callback;
static gpointer device_callback_data;
static const char *device_type_str[] = { static const char *device_type_str[] = {
"pointer", /* CLUTTER_POINTER_DEVICE */ "pointer", /* CLUTTER_POINTER_DEVICE */
@ -1115,11 +1116,11 @@ open_restricted (const char *path,
{ {
gint fd; gint fd;
if (open_callback) if (device_open_callback)
{ {
GError *error = NULL; 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) if (fd < 0)
{ {
@ -1143,7 +1144,10 @@ static void
close_restricted (int fd, close_restricted (int fd,
void *user_data) 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 = { static const struct libinput_interface libinput_interface = {
@ -1455,8 +1459,9 @@ clutter_evdev_reclaim_devices (void)
} }
/** /**
* clutter_evdev_set_open_callback: (skip) * clutter_evdev_set_device_callbacks: (skip)
* @callback: the user replacement for open() * @open_callback: the user replacement for open()
* @close_callback: the user replacement for close()
* @user_data: user data for @callback * @user_data: user data for @callback
* *
* Through this function, the application can set a custom callback * Through this function, the application can set a custom callback
@ -1472,11 +1477,13 @@ clutter_evdev_reclaim_devices (void)
* Stability: unstable * Stability: unstable
*/ */
void void
clutter_evdev_set_open_callback (ClutterOpenDeviceCallback callback, clutter_evdev_set_device_callbacks (ClutterOpenDeviceCallback open_callback,
gpointer user_data) ClutterCloseDeviceCallback close_callback,
gpointer user_data)
{ {
open_callback = callback; device_open_callback = open_callback;
open_callback_data = user_data; device_close_callback = close_callback;
device_callback_data = user_data;
} }
/** /**

View File

@ -48,10 +48,13 @@ typedef int (*ClutterOpenDeviceCallback) (const char *path,
int flags, int flags,
gpointer user_data, gpointer user_data,
GError **error); GError **error);
typedef void (*ClutterCloseDeviceCallback) (int fd,
gpointer user_data);
CLUTTER_AVAILABLE_IN_1_16 CLUTTER_AVAILABLE_IN_1_16
void clutter_evdev_set_open_callback (ClutterOpenDeviceCallback callback, void clutter_evdev_set_device_callbacks (ClutterOpenDeviceCallback open_callback,
gpointer user_data); ClutterCloseDeviceCallback close_callback,
gpointer user_data);
CLUTTER_AVAILABLE_IN_1_10 CLUTTER_AVAILABLE_IN_1_10
void clutter_evdev_release_devices (void); void clutter_evdev_release_devices (void);