[PATCH libinput 7/9] Introduce seat wide button and key count API

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 10 00:13:17 PDT 2014


On Thu, Apr 10, 2014 at 08:53:45AM +0200, Jonas Ådahl wrote:
> On Thu, Apr 10, 2014 at 04:48:52PM +1000, Peter Hutterer wrote:
> > On Thu, Apr 10, 2014 at 08:35:00AM +0200, Jonas Ådahl wrote:
> > > On Thu, Apr 10, 2014 at 04:07:34PM +1000, Peter Hutterer wrote:
> > > > On Wed, Apr 09, 2014 at 09:02:14PM +0200, Jonas Ådahl wrote:
> > > > > Compositors will need to keep provide virtual devices of supported
> > > > > generic device types (pointer, keyboard, touch etc). Events from each
> > > > > device capable of a certain device type abstraction should be combined
> > > > > as if it was only one device.
> > > > > 
> > > > > For key and button events this means counting presses of every key or
> > > > > button. With this patch, libinput provides two new API for doing just
> > > > > this; libinput_event_pointer_get_seat_button_count() and
> > > > > libinput_event_keyboard_get_seat_key_count().
> > > > > 
> > > > > With these functions, a compositor can sort out what key or button events
> > > > > that should be ignored for a virtual device. This could for example
> > > > > look like:
> > > > > 
> > > > > event = libinput_get_event(libinput);
> > > > > switch (libinput_event_get_type(event)) {
> > > > > ...
> > > > > case LIBINPUT_EVENT_POINTER_BUTTON:
> > > > > 	device = libinput_event_get_device(event);
> > > > > 	seat = libinput_event_get_seat(device);
> > > > > 	pevent = libinput_event_get_pointer_event(event);
> > > > > 
> > > > > 	if (libinput_event_pointer_get_button_state(pevent) &&
> > > > > 	    libinput_event_pointer_get_seat_button_count(pevent) == 1)
> > > > > 		notify_pointer_button_press(seat);
> > > > > 	else if (libinput_event_pointer_get_button_state(pevent) &&
> > > > > 		 libinput_event_pointer_get_seat_button_count(pevent) == 0)
> > > > > 		notify_pointer_button_release(seat);
> > > > > 	break;
> > > > > ...
> > > > > }
> > > > > 
> > > > > Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
> > > > > ---
> > > > >  src/evdev.c            |  3 +++
> > > > >  src/libinput-private.h |  5 ++++
> > > > >  src/libinput.c         | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > > > >  src/libinput.h         | 32 ++++++++++++++++++++++
> > > > >  tools/event-debug.c    |  5 ++--
> > > > >  5 files changed, 115 insertions(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/src/evdev.c b/src/evdev.c
> > > > > index b6aaf57..4020496 100644
> > > > > --- a/src/evdev.c
> > > > > +++ b/src/evdev.c
> > > > > @@ -252,6 +252,9 @@ evdev_process_key(struct evdev_device *device, struct input_event *e, int time)
> > > > >  	if (e->value == 2)
> > > > >  		return;
> > > > >  
> > > > > +	if (e->code > KEY_MAX)
> > > > > +		return;
> > > > > +
> > > > >  	if (e->code == BTN_TOUCH) {
> > > > >  		if (!device->is_mt)
> > > > >  			evdev_process_touch_button(device, time, e->value);
> > > > > diff --git a/src/libinput-private.h b/src/libinput-private.h
> > > > > index 21627b0..39d6445 100644
> > > > > --- a/src/libinput-private.h
> > > > > +++ b/src/libinput-private.h
> > > > > @@ -23,6 +23,8 @@
> > > > >  #ifndef LIBINPUT_PRIVATE_H
> > > > >  #define LIBINPUT_PRIVATE_H
> > > > >  
> > > > > +#include <linux/input.h>
> > > > > +
> > > > >  #include "libinput.h"
> > > > >  #include "libinput-util.h"
> > > > >  
> > > > > @@ -63,6 +65,9 @@ struct libinput_seat {
> > > > >  	char *logical_name;
> > > > >  
> > > > >  	uint32_t slot_map;
> > > > > +
> > > > > +	uint32_t button_count[KEY_CNT];
> > > > > +	uint32_t key_count[KEY_CNT];
> > > > 
> > > > the ranges are mutually exclusive, we don't really need two arrays here.
> > > 
> > > This is in the seat, and libinput separates pointers from keyboards, so
> > > shouldn't they be counted separately because of that? Will a pointer
> > > never press a "key" and a keyboard never a "button"? If they would then
> > > the keyboards button count should not effect the pointers button count
> > > and vice versa.
> > 
> > are you suggesting we add keyboard_button or pointer_key events? because
> > that's a bridge we should burn when we have cross it, not before :)
> 
> No, what I mean is will a pointer_button code never be KEY_* and a
> keyboard_key code never be BTN_*?

I'm gonna say "no it won't" as long as we keep using linux/input.h codes.
and even if we decide that a BTN_foo should count as KEY_* then we have to
filter this elsewhere anyway, each index is still unique then.

Cheers,
   Peter



More information about the wayland-devel mailing list