[PATCH libinput 3/8] Add libinput_device_suspend() and libinput_device_resume()
Peter Hutterer
peter.hutterer at who-t.net
Tue Aug 19 20:18:51 PDT 2014
Does what it says on the box, preventing events from the device without actually
dropping the device from the context.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
See my notes in the coverletter. For the T440 case I specifically did not
mention that _suspend() closes the file descriptors.
src/evdev.c | 23 +++++++++++++++++++++++
src/evdev.h | 3 +++
src/libinput.c | 16 ++++++++++++++++
src/libinput.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 87 insertions(+)
diff --git a/src/evdev.c b/src/evdev.c
index d4a4a07..78d9985 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1082,6 +1082,29 @@ evdev_device_suspend(struct evdev_device *device)
return 0;
}
+int
+evdev_device_resume(struct evdev_device *device)
+{
+ struct libinput *libinput = device->base.seat->libinput;
+ int fd;
+
+ if (device->fd != -1)
+ return 0;
+
+ fd = open_restricted(libinput, device->devnode, O_RDWR | O_NONBLOCK);
+
+ if (fd < 0)
+ return fd;
+
+ device->fd = fd;
+ device->source =
+ libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
+ if (!device->source)
+ return -ENOMEM;
+
+ return 0;
+}
+
void
evdev_device_remove(struct evdev_device *device)
{
diff --git a/src/evdev.h b/src/evdev.h
index 05125b7..b4749b6 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -182,6 +182,9 @@ evdev_device_transform_y(struct evdev_device *device,
int
evdev_device_suspend(struct evdev_device *device);
+int
+evdev_device_resume(struct evdev_device *device);
+
void
evdev_keyboard_notify_key(struct evdev_device *device,
uint32_t time,
diff --git a/src/libinput.c b/src/libinput.c
index 90b6a13..d18d9b8 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1142,6 +1142,22 @@ libinput_suspend(struct libinput *libinput)
libinput->interface_backend->suspend(libinput);
}
+LIBINPUT_EXPORT int
+libinput_device_suspend(struct libinput_device *device)
+{
+ struct evdev_device *dev = (struct evdev_device*)device;
+
+ return evdev_device_suspend(dev);
+}
+
+LIBINPUT_EXPORT int
+libinput_device_resume(struct libinput_device *device)
+{
+ struct evdev_device *dev = (struct evdev_device*)device;
+
+ return evdev_device_resume(dev);
+}
+
LIBINPUT_EXPORT void
libinput_device_set_user_data(struct libinput_device *device, void *user_data)
{
diff --git a/src/libinput.h b/src/libinput.h
index 9296a35..338a08f 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1226,6 +1226,51 @@ libinput_device_unref(struct libinput_device *device);
/**
* @ingroup device
*
+ * Suspend the device but do not remove the device from the context.
+ * Suspending a device stops the device from generating events until it is
+ * either resumed with libinput_device_resume() or removed from the context.
+ * Suspending a device does not generate a @ref
+ * LIBINPUT_EVENT_DEVICE_REMOVED event.
+ *
+ * Events already received and processed from this device are unaffected and
+ * will be passed to the caller on the next call to libinput_get_event().
+ * When the device is suspended, it may generate events to reset it into a
+ * neutral state (e.g. releasing currently pressed buttons).
+ *
+ * If the device is already suspended, this function does nothing.
+ *
+ * @param device A previously obtained device
+ * @return 0 on success or a negative errno on failure
+ *
+ * @see libinput_device_resume
+ */
+int
+libinput_device_suspend(struct libinput_device *device);
+
+/**
+ * @ingroup device
+ *
+ * Resume a previously suspended device. Events from this device will be
+ * processed in the next call of libinput_dispatch().
+ * Resuming a device does not generate a @ref LIBINPUT_EVENT_DEVICE_ADDED
+ * event.
+ *
+ * When the device is resumed, it may generate events to match the logical
+ * state with the current physical state of the device.
+ *
+ * If the device is not currently suspended, this function does nothing.
+ *
+ * @param device A previously suspended device
+ * @return 0 on success or a negative errno on failure
+ *
+ * @see libinput_device_suspend
+ */
+int
+libinput_device_resume(struct libinput_device *device);
+
+/**
+ * @ingroup device
+ *
* Set caller-specific data associated with this input device. libinput does
* not manage, look at, or modify this data. The caller must ensure the
* data is valid.
--
1.9.3
More information about the wayland-devel
mailing list