[PATCH libinput] tablet: drop LIBINPUT_TABLET_AXIS_NONE from the API

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Feb 12 07:25:31 PST 2015


On Mon, Feb 9, 2015 at 8:29 PM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> This constant isn't used in the public API, let's drop it. To make it easier
> to use it internally and avoid accidental boolean comparisions with axes, bump
> all real axes up to start at 1.
>
> Internally that means we drop the AXIS_CNT since it'd be misleading and
> instead use MAX or MAX + 1 everywhere.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---

I am not a big fan of using X as the first axis in the for loops. It's
just that it feels wrong to read "for X to MAX". Though besides adding
a MIN (or FIRST/LAST), there is not much we can do.

With or without this, the patch is still
Reviewed-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>

Cheers,
Benjamin

> This one is for the tablet-support branch.
>
>  src/evdev-tablet.c     |  8 +++++---
>  src/evdev-tablet.h     |  8 +++++---
>  src/libinput-private.h |  4 ++--
>  src/libinput.c         |  4 ++--
>  src/libinput.h         | 13 ++++++-------
>  5 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
> index f80d642..0d2fc1f 100644
> --- a/src/evdev-tablet.c
> +++ b/src/evdev-tablet.c
> @@ -75,7 +75,7 @@ tablet_mark_all_axes_changed(struct tablet_dispatch *tablet,
>  {
>         enum libinput_tablet_axis a;
>
> -       for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) {
> +       for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) {
>                 if (libevdev_has_event_code(device->evdev,
>                                             EV_ABS,
>                                             axis_to_evcode(a)))
> @@ -130,7 +130,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
>         bool axis_update_needed = false;
>         int a;
>
> -       for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) {
> +       for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) {
>                 const struct input_absinfo *absinfo;
>
>                 if (!bit_is_set(tablet->changed_axes, a))
> @@ -562,7 +562,9 @@ tablet_init(struct tablet_dispatch *tablet,
>         tablet->current_tool_type = LIBINPUT_TOOL_NONE;
>         list_init(&tablet->tool_list);
>
> -       for (axis = 0; axis < LIBINPUT_TABLET_AXIS_CNT; axis++) {
> +       for (axis = LIBINPUT_TABLET_AXIS_X;
> +            axis <= LIBINPUT_TABLET_AXIS_MAX;
> +            axis++) {
>                 if (libevdev_has_event_code(device->evdev,
>                                             EV_ABS,
>                                             axis_to_evcode(axis)))
> diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h
> index cb37577..4f35417 100644
> --- a/src/evdev-tablet.h
> +++ b/src/evdev-tablet.h
> @@ -27,6 +27,8 @@
>
>  #include "evdev.h"
>
> +#define LIBINPUT_TABLET_AXIS_NONE 0
> +
>  enum tablet_status {
>         TABLET_NONE = 0,
>         TABLET_AXES_UPDATED = 1 << 0,
> @@ -46,9 +48,9 @@ struct tablet_dispatch {
>         struct evdev_dispatch base;
>         struct evdev_device *device;
>         unsigned char status;
> -       unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)];
> -       double axes[LIBINPUT_TABLET_AXIS_CNT];
> -       unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_CNT)];
> +       unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
> +       double axes[LIBINPUT_TABLET_AXIS_MAX + 1];
> +       unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
>
>         /* Only used for tablets that don't report serial numbers */
>         struct list tool_list;
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index 7b4a0d6..a751990 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -30,7 +30,7 @@
>  #include "libinput.h"
>  #include "libinput-util.h"
>
> -#define LIBINPUT_TABLET_AXIS_CNT LIBINPUT_TABLET_AXIS_TILT_Y + 1
> +#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_TILT_Y
>
>  struct libinput_source;
>
> @@ -188,7 +188,7 @@ struct libinput_tool {
>         struct list link;
>         uint32_t serial;
>         enum libinput_tool_type type;
> -       unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_CNT)];
> +       unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
>         int refcount;
>         void *user_data;
>  };
> diff --git a/src/libinput.c b/src/libinput.c
> index 487331c..801a295 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -85,8 +85,8 @@ struct libinput_event_tablet {
>         enum libinput_button_state state;
>         uint32_t seat_button_count;
>         uint32_t time;
> -       double axes[LIBINPUT_TABLET_AXIS_CNT];
> -       unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)];
> +       double axes[LIBINPUT_TABLET_AXIS_MAX + 1];
> +       unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
>         struct libinput_tool *tool;
>  };
>
> diff --git a/src/libinput.h b/src/libinput.h
> index 02957e8..634c786 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -137,13 +137,12 @@ enum libinput_pointer_axis_source {
>   * LIBINPUT_DEVICE_CAP_TABLET capability.
>   */
>  enum libinput_tablet_axis {
> -       LIBINPUT_TABLET_AXIS_NONE = -1,
> -       LIBINPUT_TABLET_AXIS_X = 0,
> -       LIBINPUT_TABLET_AXIS_Y = 1,
> -       LIBINPUT_TABLET_AXIS_DISTANCE = 2,
> -       LIBINPUT_TABLET_AXIS_PRESSURE = 3,
> -       LIBINPUT_TABLET_AXIS_TILT_X = 4,
> -       LIBINPUT_TABLET_AXIS_TILT_Y = 5,
> +       LIBINPUT_TABLET_AXIS_X = 1,
> +       LIBINPUT_TABLET_AXIS_Y = 2,
> +       LIBINPUT_TABLET_AXIS_DISTANCE = 3,
> +       LIBINPUT_TABLET_AXIS_PRESSURE = 4,
> +       LIBINPUT_TABLET_AXIS_TILT_X = 5,
> +       LIBINPUT_TABLET_AXIS_TILT_Y = 6,
>  };
>
>  /**
> --
> 2.1.0
>
> _______________________________________________
> 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