[PATCH libinput 14/15] tablet: add support for libinput_tool_has_button
Lyude
thatslyude at gmail.com
Sun Feb 22 16:48:03 PST 2015
On Wed, 2015-02-18 at 15:45 +1000, Peter Hutterer wrote:
> The mouse like devices have LMR, SIDE and EXTRA.
> PENCIL (which is the Wacom Inking) and the eraser have no buttons.
> AIRBRUSH has only one button, all other pens have two.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> src/evdev-tablet.c | 41 +++++++++++++++++++++++++++++++++++++++++
> src/libinput-private.h | 1 +
> src/libinput.c | 11 +++++++++++
> src/libinput.h | 15 +++++++++++++++
> src/libinput.sym | 1 +
> 5 files changed, 69 insertions(+)
>
> diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
> index dcf1716..6ae9c6e 100644
> --- a/src/evdev-tablet.c
> +++ b/src/evdev-tablet.c
> @@ -401,6 +401,16 @@ copy_axis_cap(const struct tablet_dispatch *tablet,
> set_bit(tool->axis_caps, axis);
> }
>
> +static inline void
> +copy_button_cap(const struct tablet_dispatch *tablet,
> + struct libinput_tool *tool,
> + uint32_t button)
> +{
> + struct libevdev *evdev = tablet->device->evdev;
> + if (libevdev_has_event_code(evdev, EV_KEY, button))
> + set_bit(tool->buttons, button);
> +}
> +
> static void
> tool_set_bits(const struct tablet_dispatch *tablet,
> struct libinput_tool *tool,
> @@ -447,6 +457,37 @@ tool_set_bits(const struct tablet_dispatch *tablet,
> default:
> break;
> }
> +
> + /* Button capabilities on the various tools:
> + * - all pens have BTN_TOUCH
> + * - the eraser and the pencil (Wacom Inking) have no buttons
> + * - the airbrush only has a single button
> + * - all other pens have 2 buttons
> + * - the mouse has the first 5 mouse buttons
> + */
> + switch (type) {
> + case LIBINPUT_TOOL_PEN:
> + case LIBINPUT_TOOL_BRUSH:
> + copy_button_cap(tablet, tool, BTN_STYLUS2);
> + /* fallthrough */
> + case LIBINPUT_TOOL_AIRBRUSH:
> + copy_button_cap(tablet, tool, BTN_STYLUS);
> + /* fallthrough */
> + case LIBINPUT_TOOL_PENCIL:
> + case LIBINPUT_TOOL_ERASER:
> + copy_button_cap(tablet, tool, BTN_TOUCH);
> + break;
> + case LIBINPUT_TOOL_MOUSE:
> + case LIBINPUT_TOOL_LENS:
> + copy_button_cap(tablet, tool, BTN_LEFT);
> + copy_button_cap(tablet, tool, BTN_MIDDLE);
> + copy_button_cap(tablet, tool, BTN_RIGHT);
> + copy_button_cap(tablet, tool, BTN_SIDE);
> + copy_button_cap(tablet, tool, BTN_EXTRA);
> + break;
> + default:
> + break;
> + }
> }
>
> static struct libinput_tool *
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index 0b01029..4fd8fa6 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -190,6 +190,7 @@ struct libinput_tool {
> uint32_t serial;
> enum libinput_tool_type type;
> unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
> + unsigned char buttons[NCHARS(KEY_MAX) + 1];
> int refcount;
> void *user_data;
> };
> diff --git a/src/libinput.c b/src/libinput.c
> index 7c90f37..3a8c07f 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -677,6 +677,17 @@ libinput_tool_has_axis(struct libinput_tool *tool,
> return bit_is_set(tool->axis_caps, axis);
> }
>
> +LIBINPUT_EXPORT int
> +libinput_tool_has_button(struct libinput_tool *tool,
> + uint32_t code)
> +{
> + if (NCHARS(code) > sizeof(tool->buttons))
> + return 0;
> +
> + return bit_is_set(tool->buttons, code);
> +}
> +
> +
Everything looks great, although you've got an extra bit of whitespace
right here :).
> LIBINPUT_EXPORT void
> libinput_tool_set_user_data(struct libinput_tool *tool,
> void *user_data)
> diff --git a/src/libinput.h b/src/libinput.h
> index 461925a..36c0931 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -1222,6 +1222,21 @@ libinput_tool_has_axis(struct libinput_tool *tool,
> /**
> * @ingroup event_tablet
> *
> + * Check if a tablet tool has a button with the
> + * passed-in code (see linux/input.h).
> + *
> + * @param tool A tablet tool
> + * @param code button code to check for
> + *
> + * @return 1 if the tool supports this button code, 0 if it does not
> + */
> +int
> +libinput_tool_has_button(struct libinput_tool *tool,
> + uint32_t code);
> +
> +/**
> + * @ingroup event_tablet
> + *
> * Decrement the ref count of tool by one. When the ref count of tool reaches 0,
> * the memory allocated for tool will be freed.
> *
> diff --git a/src/libinput.sym b/src/libinput.sym
> index b31c231..c4b5344 100644
> --- a/src/libinput.sym
> +++ b/src/libinput.sym
> @@ -155,6 +155,7 @@ LIBINPUT_TABLET_SUPPORT {
> libinput_tool_get_serial;
> libinput_tool_get_type;
> libinput_tool_get_user_data;
> + libinput_tool_has_button;
> libinput_tool_has_axis;
> libinput_tool_ref;
> libinput_tool_set_user_data;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150222/8483f61c/attachment.sig>
More information about the wayland-devel
mailing list