[PATCH libinput 1/2] Hook up libevdev as backend

Peter Hutterer peter.hutterer at who-t.net
Sun Feb 23 15:28:49 PST 2014


On Sat, Feb 22, 2014 at 03:51:57PM +0100, Jonas Ådahl wrote:
> On Tue, Feb 18, 2014 at 04:09:09PM +1000, Peter Hutterer wrote:
> > libevdev wraps the various peculiarities of the evdev kernel API into a
> > type-safe API. It also buffers the device so checking for specific features at
> > a later time is easier than re-issuing the ioctls. Plus, it gives us almost
> > free support for SYN_DROPPED events (in the following patch).
> > 
> > This patch switches all the bit checks over to libevdev and leaves the event
> > processing as-is. Makes it easier to review.
> > 
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> 
> Looks good to me as well, with one comment inline.
> 
> Reviewed-by: Jonas Ådahl <jadahl at gmail.com>

..

> > @@ -624,6 +607,10 @@ evdev_device_create(struct libinput_seat *seat,
> >  
> >  	libinput_device_init(&device->base, seat);
> >  
> > +	rc = libevdev_new_from_fd(fd, &device->evdev);
> > +	if (rc != 0)
> > +		return NULL;
> > +
> >  	device->seat_caps = 0;
> >  	device->is_mt = 0;
> >  	device->mtdev = NULL;
> > @@ -635,10 +622,7 @@ evdev_device_create(struct libinput_seat *seat,
> >  	device->dispatch = NULL;
> >  	device->fd = fd;
> >  	device->pending_event = EVDEV_NONE;
> > -
> > -	ioctl(device->fd, EVIOCGNAME(sizeof(devname)), devname);
> > -	devname[sizeof(devname) - 1] = '\0';
> > -	device->devname = strdup(devname);
> > +	device->devname = libevdev_get_name(device->evdev);
> 
> This makes the assumption that the const char * returned by
> libevdev_get_name() is valid until we destroy the device. Is this
> guaranteed anywhere by libevdev?

It's guaranteed by the kernel. There is no facility to set the name through
the API and there is no facility to notify the caller if the name would
change. so libevdev (which has a copy, obviuosly) wouldn't know that it
changed. libevdev_change_fd() doesn't re-sync the name, so yes, this name
is constant.

Cheers,
   Peter

> 
> >  
> >  	libinput_seat_ref(seat);
> >  
> > @@ -742,8 +726,7 @@ evdev_device_destroy(struct evdev_device *device)
> >  		dispatch->interface->destroy(dispatch);
> >  
> >  	libinput_seat_unref(device->base.seat);
> > -
> > -	free(device->devname);
> > +	libevdev_free(device->evdev);
> >  	free(device->devnode);
> >  	free(device->sysname);
> >  	free(device);
> > diff --git a/src/evdev.h b/src/evdev.h
> > index 3c9f93a..a9e27bf 100644
> > --- a/src/evdev.h
> > +++ b/src/evdev.h
> > @@ -27,6 +27,7 @@
> >  #include "config.h"
> >  
> >  #include <linux/input.h>
> > +#include <libevdev/libevdev.h>
> >  
> >  #include "libinput-private.h"
> >  
> > @@ -55,10 +56,11 @@ struct evdev_device {
> >  	struct libinput_source *source;
> >  
> >  	struct evdev_dispatch *dispatch;
> > +	struct libevdev *evdev;
> >  	char *output_name;
> >  	char *devnode;
> >  	char *sysname;
> > -	char *devname;
> > +	const char *devname;
> >  	int fd;
> >  	struct {
> >  		int min_x, max_x, min_y, max_y;
> > @@ -86,16 +88,6 @@ struct evdev_device {
> >  	int is_mt;
> >  };
> >  
> > -/* 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 */
> > -
> >  #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
> >  
> >  struct evdev_dispatch;
> > -- 
> > 1.8.4.2
> > 
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list