[PATCH weston 2/5] evdev: Add event process dispatching

Jonas Ådahl jadahl at gmail.com
Wed May 9 14:31:43 PDT 2012


By adding an 'evdev_dispatch' struct to the dispatch_list in
'evdev_input_device' the 'process' function in the associated interface
will be called with received input events. The process function can
either handle the event and return a non-zero integer or return zero and
the generic fallback handlers will process the event.

Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
 src/Makefile.am     |    1 +
 src/evdev-private.h |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/evdev.c         |   82 ++++++++++++--------------------------
 3 files changed, 134 insertions(+), 57 deletions(-)
 create mode 100644 src/evdev-private.h

diff --git a/src/Makefile.am b/src/Makefile.am
index ad607b7..2e815e9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,6 +79,7 @@ drm_backend_la_SOURCES =			\
 	tty.c					\
 	evdev.c					\
 	evdev.h					\
+	evdev-private.h				\
 	launcher-util.c				\
 	launcher-util.h				\
 	libbacklight.c				\
diff --git a/src/evdev-private.h b/src/evdev-private.h
new file mode 100644
index 0000000..da4fb7e
--- /dev/null
+++ b/src/evdev-private.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef EVDEV_PRIVATE_H
+#define EVDEV_PRIVATE_H
+
+#include <linux/input.h>
+#include <wayland-util.h>
+
+struct evdev_input {
+	struct weston_input_device base;
+	struct wl_list devices_list;
+	struct udev_monitor *udev_monitor;
+	struct wl_event_source *udev_monitor_source;
+	char *seat_id;
+};
+
+#define MAX_SLOTS 16
+
+struct evdev_input_device {
+	struct evdev_input *master;
+	struct wl_list link;
+	struct wl_event_source *source;
+	struct weston_output *output;
+	struct wl_list dispatch_list;
+	char *devnode;
+	int fd;
+	struct {
+		int min_x, max_x, min_y, max_y;
+		int old_x, old_y, reset_x, reset_y;
+		int32_t x, y;
+	} abs;
+
+	struct {
+		int slot;
+		int32_t x[MAX_SLOTS];
+		int32_t y[MAX_SLOTS];
+	} mt;
+	struct mtdev *mtdev;
+
+	struct {
+		int dx, dy;
+	} rel;
+
+	int type; /* event type flags */
+
+	int is_touchpad, is_mt;
+};
+
+/* event type flags */
+#define EVDEV_ABSOLUTE_MOTION		(1 << 0)
+#define EVDEV_ABSOLUTE_MT_DOWN		(1 << 1)
+#define EVDEV_ABSOLUTE_MT_MOTION	(1 << 2)
+#define EVDEV_ABSOLUTE_MT_UP		(1 << 3)
+#define EVDEV_RELATIVE_MOTION		(1 << 4)
+
+/* copied from udev/extras/input_id/input_id.c */
+/* we must use this kernel-compatible implementation */
+#define BITS_PER_LONG (sizeof(unsigned long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x)  ((x)%BITS_PER_LONG)
+#define BIT(x)  (1UL<<OFF(x))
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define TEST_BIT(array, bit)    ((array[LONG(bit)] >> OFF(bit)) & 1)
+/* end copied */
+
+struct evdev_dispatch;
+
+struct evdev_dispatch_interface {
+	/* Process an evdev input event. Return a non-zero integer if the
+	 * event was handled and zero either if the event was handled but
+	 * processing should continue or if the event was not handled. */
+	int (*process)(struct evdev_dispatch *dispatch,
+		       struct evdev_input_device *device,
+		       struct input_event *event,
+		       uint32_t time);
+	/* Destroy an event dispatch handler and free all its resources. */
+	void (*destroy)(struct evdev_dispatch *dispatch);
+};
+
+struct evdev_dispatch {
+	struct evdev_dispatch_interface *interface;
+	struct wl_list link;
+};
+
+struct evdev_dispatch *
+evdev_touchpad_create(struct evdev_input_device *device);
+
+#endif /* EVDEV_PRIVATE_H */
diff --git a/src/evdev.c b/src/evdev.c
index 4dbf575..4699586 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -30,53 +30,7 @@
 
 #include "compositor.h"
 #include "evdev.h"
-#include "launcher-util.h"
-
-struct evdev_input {
-	struct weston_input_device base;
-	struct wl_list devices_list;
-	struct udev_monitor *udev_monitor;
-	struct wl_event_source *udev_monitor_source;
-	char *seat_id;
-};
-
-#define MAX_SLOTS 16
-
-struct evdev_input_device {
-	struct evdev_input *master;
-	struct wl_list link;
-	struct wl_event_source *source;
-	struct weston_output *output;
-	char *devnode;
-	int fd;
-	struct {
-		int min_x, max_x, min_y, max_y;
-		int old_x, old_y, reset_x, reset_y;
-		int32_t x, y;
-	} abs;
-
-	struct {
-		int slot;
-		int32_t x[MAX_SLOTS];
-		int32_t y[MAX_SLOTS];
-	} mt;
-	struct mtdev *mtdev;
-
-	struct {
-		int dx, dy;
-	} rel;
-
-	int type; /* event type flags */
-
-	int is_touchpad, is_mt;
-};
-
-/* event type flags */
-#define EVDEV_ABSOLUTE_MOTION		(1 << 0)
-#define EVDEV_ABSOLUTE_MT_DOWN		(1 << 1)
-#define EVDEV_ABSOLUTE_MT_MOTION	(1 << 2)
-#define EVDEV_ABSOLUTE_MT_UP		(1 << 3)
-#define EVDEV_RELATIVE_MOTION		(1 << 4)
+#include "evdev-private.h"
 
 static inline void
 evdev_process_key(struct evdev_input_device *device,
@@ -337,6 +291,19 @@ evdev_flush_motion(struct evdev_input_device *device, uint32_t time)
 	}
 }
 
+static int
+evdev_dispatch_process_event(struct evdev_input_device *device,
+			     struct input_event *event,
+			     uint32_t time)
+{
+	struct evdev_dispatch *dispatch;
+	wl_list_for_each(dispatch, &device->dispatch_list, link)
+		if (dispatch->interface->process(dispatch, device, event, time))
+			return 1;
+
+	return 0;
+}
+
 static void
 evdev_process_events(struct evdev_input_device *device,
 		     struct input_event *ev, int count)
@@ -356,6 +323,10 @@ evdev_process_events(struct evdev_input_device *device,
 		 * events and send as a bunch */
 		if (!is_motion_event(e))
 			evdev_flush_motion(device, time);
+
+		if (evdev_dispatch_process_event(device, e, time))
+			continue;
+
 		switch (e->type) {
 		case EV_REL:
 			evdev_process_relative(device, e, time);
@@ -407,16 +378,6 @@ evdev_input_device_data(int fd, uint32_t mask, void *data)
 	return 1;
 }
 
-/* copied from udev/extras/input_id/input_id.c */
-/* we must use this kernel-compatible implementation */
-#define BITS_PER_LONG (sizeof(unsigned long) * 8)
-#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
-#define OFF(x)  ((x)%BITS_PER_LONG)
-#define BIT(x)  (1UL<<OFF(x))
-#define LONG(x) ((x)/BITS_PER_LONG)
-#define TEST_BIT(array, bit)    ((array[LONG(bit)] >> OFF(bit)) & 1)
-/* end copied */
-
 static int
 evdev_configure_device(struct evdev_input_device *device)
 {
@@ -491,6 +452,7 @@ evdev_input_device_create(struct evdev_input *master,
 	device->mt.slot = -1;
 	device->rel.dx = 0;
 	device->rel.dy = 0;
+	wl_list_init(&device->dispatch_list);
 
 	/* Use non-blocking mode so that we can loop on read on
 	 * evdev_input_device_data() until all events on the fd are
@@ -550,6 +512,12 @@ device_added(struct udev_device *udev_device, struct evdev_input *master)
 static void
 device_removed(struct evdev_input_device *device)
 {
+	struct evdev_dispatch *dispatch;
+	struct evdev_dispatch *next;
+
+	wl_list_for_each_safe(dispatch, next, &device->dispatch_list, link)
+		dispatch->interface->destroy(dispatch);
+
 	wl_event_source_remove(device->source);
 	wl_list_remove(&device->link);
 	if (device->mtdev)
-- 
1.7.9.5



More information about the wayland-devel mailing list