evdev: move device opening out from evdev_input_device_create

This makes the generic evdev code (i.e. the functions not relying on
udev) independent of launcher-util too. The aim is to allow re-using the
generic evdev code in the Android backend, where neither udev nor
launcher-util are available.

evdev_input_device_create() signature is changed:
- add the opened device file descriptor
- remove wl_display as unused

Also add a bit of failure logging.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
Pekka Paalanen 2012-08-03 14:38:58 +03:00 committed by Kristian Høgsberg
parent a123e5c46a
commit 5a6383ba57

View File

@ -464,7 +464,7 @@ evdev_configure_device(struct evdev_input_device *device)
static struct evdev_input_device * static struct evdev_input_device *
evdev_input_device_create(struct evdev_seat *master, 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 evdev_input_device *device;
struct weston_compositor *ec; struct weston_compositor *ec;
@ -485,13 +485,7 @@ evdev_input_device_create(struct evdev_seat *master,
device->rel.dx = 0; device->rel.dx = 0;
device->rel.dy = 0; device->rel.dy = 0;
device->dispatch = NULL; device->dispatch = NULL;
device->fd = device_fd;
/* 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;
if (evdev_configure_device(device) == -1) if (evdev_configure_device(device) == -1)
goto err1; goto err1;
@ -522,8 +516,6 @@ evdev_input_device_create(struct evdev_seat *master,
err2: err2:
device->dispatch->interface->destroy(device->dispatch); device->dispatch->interface->destroy(device->dispatch);
err1: err1:
close(device->fd);
err0:
free(device->devnode); free(device->devnode);
free(device); free(device);
return NULL; return NULL;
@ -553,8 +545,10 @@ static void
device_added(struct udev_device *udev_device, struct evdev_seat *master) device_added(struct udev_device *udev_device, struct evdev_seat *master)
{ {
struct weston_compositor *c; struct weston_compositor *c;
struct evdev_input_device *device;
const char *devnode; const char *devnode;
const char *device_seat; const char *device_seat;
int fd;
device_seat = udev_device_get_property_value(udev_device, "ID_SEAT"); device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
if (!device_seat) if (!device_seat)
@ -565,7 +559,21 @@ device_added(struct udev_device *udev_device, struct evdev_seat *master)
c = master->base.compositor; c = master->base.compositor;
devnode = udev_device_get_devnode(udev_device); devnode = udev_device_get_devnode(udev_device);
evdev_input_device_create(master, 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, devnode, fd);
if (!device) {
close(fd);
weston_log("not using input device '%s'.\n", devnode);
}
} }
static void static void