[PATCH weston 06/17] evdev: move weston_launcher_open() call site

Pekka Paalanen ppaalanen at gmail.com
Thu Jul 5 03:33:03 PDT 2012


Move the weston_launcher_open() call from evdev.c into udev-evdev.c.
This makes evdev.c independent from launcher-util.

While doing this, change the evdev_input_device_create() signature:
- drop wl_display parameter as unused
- pass opened device file descriptor, since evdev.c cannot open the
  device

Add a bit of failure logging.

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 src/evdev.c      |   14 ++------------
 src/evdev.h      |    2 +-
 src/udev-evdev.c |   20 +++++++++++++++++++-
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index db4e58b..1fca3b3 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -24,12 +24,10 @@
 #include <string.h>
 #include <linux/input.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <mtdev.h>
 
 #include "compositor.h"
 #include "evdev.h"
-#include "launcher-util.h"
 #include "log.h"
 
 static void
@@ -474,7 +472,7 @@ evdev_configure_device(struct evdev_input_device *device)
 
 struct evdev_input_device *
 evdev_input_device_create(struct evdev_seat *master,
-			  struct wl_display *display, const char *path)
+			  const char *path, int device_fd)
 {
 	struct evdev_input_device *device;
 	struct weston_compositor *ec;
@@ -495,13 +493,7 @@ evdev_input_device_create(struct evdev_seat *master,
 	device->rel.dx = 0;
 	device->rel.dy = 0;
 	device->dispatch = NULL;
-
-	/* Use non-blocking mode so that we can loop on read on
-	 * evdev_input_device_data() until all events on the fd are
-	 * read.  mtdev_get() also expects this. */
-	device->fd = weston_launcher_open(ec, path, O_RDWR | O_NONBLOCK);
-	if (device->fd < 0)
-		goto err0;
+	device->fd = device_fd;
 
 	if (evdev_configure_device(device) == -1)
 		goto err1;
@@ -532,8 +524,6 @@ evdev_input_device_create(struct evdev_seat *master,
 err2:
 	device->dispatch->interface->destroy(device->dispatch);
 err1:
-	close(device->fd);
-err0:
 	free(device->devnode);
 	free(device);
 	return NULL;
diff --git a/src/evdev.h b/src/evdev.h
index f75e115..522c19d 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -120,7 +120,7 @@ evdev_seat_release(struct evdev_seat *seat);
 
 struct evdev_input_device *
 evdev_input_device_create(struct evdev_seat *master,
-			  struct wl_display *display, const char *path);
+			  const char *path, int device_fd);
 
 void
 evdev_notify_keyboard_focus(struct evdev_seat *seat);
diff --git a/src/udev-evdev.c b/src/udev-evdev.c
index 4660409..a19db92 100644
--- a/src/udev-evdev.c
+++ b/src/udev-evdev.c
@@ -23,12 +23,14 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <mtdev.h>
 
 #include "compositor.h"
 #include "evdev.h"
 #include "udev-evdev.h"
 #include "log.h"
+#include "launcher-util.h"
 
 struct uevdev_seat {
 	struct evdev_seat evdev;
@@ -43,8 +45,10 @@ static void
 device_added(struct udev_device *udev_device, struct uevdev_seat *master)
 {
 	struct weston_compositor *c;
+	struct evdev_input_device *device;
 	const char *devnode;
 	const char *device_seat;
+	int fd;
 
 	device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
 	if (!device_seat)
@@ -55,7 +59,21 @@ device_added(struct udev_device *udev_device, struct uevdev_seat *master)
 
 	c = master->evdev.base.compositor;
 	devnode = udev_device_get_devnode(udev_device);
-	evdev_input_device_create(&master->evdev, c->wl_display, devnode);
+
+	/* Use non-blocking mode so that we can loop on read on
+	 * evdev_input_device_data() until all events on the fd are
+	 * read.  mtdev_get() also expects this. */
+	fd = weston_launcher_open(c, devnode, O_RDWR | O_NONBLOCK);
+	if (fd < 0) {
+		weston_log("opening input device '%s' failed.\n", devnode);
+		return;
+	}
+
+	device = evdev_input_device_create(&master->evdev, devnode, fd);
+	if (!device) {
+		close(fd);
+		weston_log("not using input device '%s'.\n", devnode);
+	}
 }
 
 static void
-- 
1.7.8.6



More information about the wayland-devel mailing list