[PATCH libinput v2 6/8] tablet: Include starting values of axes in proximity events
Peter Hutterer
peter.hutterer at who-t.net
Wed Feb 18 21:31:27 PST 2015
On Wed, Feb 18, 2015 at 01:42:27AM -0500, Stephen Chandler Paul wrote:
> Having a motion event that's sent right after the original proximity event just
> to give the values of each axis is somewhat redundant. Since we already include
> the values of each axis with each type of event, we may as well use the
> proximity event to give the client the starting values for each axis on the
> tablet.
>
> Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
merged, thanks (well, the diff, I had alread pushed v1 of that)
Cheers,
Peter
> ---
> src/evdev-tablet.c | 38 ++++++++++++++++++++++----------------
> src/libinput-private.h | 1 +
> src/libinput.c | 7 ++++++-
> src/libinput.h | 10 +++++++---
> test/tablet.c | 8 ++++----
> tools/event-debug.c | 38 +++++++++++++++++++++++++++++++++-----
> 6 files changed, 73 insertions(+), 29 deletions(-)
>
> Changes
> - Don't mark all axes as changed on proximity out events
> - Clear the changed_axes before sending proximity out events, so that we
> ignore the unwanted reset to 0 for all axis values from evdev.
>
> diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
> index ec4fbfc..73dbef0 100644
> --- a/src/evdev-tablet.c
> +++ b/src/evdev-tablet.c
> @@ -191,12 +191,21 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
> * it's there, but can't properly receive any data from the tool. */
> if (axis_update_needed &&
> !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) &&
> - !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
> - tablet_notify_axis(base,
> - time,
> - tool,
> - tablet->changed_axes,
> - tablet->axes);
> + !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
> + if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY))
> + tablet_notify_proximity(&device->base,
> + time,
> + tool,
> + LIBINPUT_TOOL_PROXIMITY_IN,
> + tablet->changed_axes,
> + tablet->axes);
> + else
> + tablet_notify_axis(base,
> + time,
> + tool,
> + tablet->changed_axes,
> + tablet->axes);
> + }
>
> memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
> }
> @@ -470,18 +479,12 @@ tablet_flush(struct tablet_dispatch *tablet,
> /* Release all stylus buttons */
> tablet->button_state.stylus_buttons = 0;
> tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
> - } else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
> - tablet_notify_proximity(&device->base,
> - time,
> - tool,
> - LIBINPUT_TOOL_PROXIMITY_IN,
> - tablet->axes);
> - tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
> - }
> -
> - if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
> + } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED) ||
> + tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
> sanitize_tablet_axes(tablet);
> tablet_check_notify_axes(tablet, device, time, tool);
> +
> + tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
> tablet_unset_status(tablet, TABLET_AXES_UPDATED);
> }
>
> @@ -504,11 +507,14 @@ tablet_flush(struct tablet_dispatch *tablet,
> }
>
> if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
> + memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
> tablet_notify_proximity(&device->base,
> time,
> tool,
> LIBINPUT_TOOL_PROXIMITY_OUT,
> + tablet->changed_axes,
> tablet->axes);
> +
> tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
> tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
>
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index 415aac4..33ce2db 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -354,6 +354,7 @@ tablet_notify_proximity(struct libinput_device *device,
> uint32_t time,
> struct libinput_tool *tool,
> enum libinput_tool_proximity_state state,
> + unsigned char *changed_axes,
> double *axes);
>
> void
> diff --git a/src/libinput.c b/src/libinput.c
> index 38c2fd7..aac6183 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -569,7 +569,8 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event,
> struct evdev_device *device =
> (struct evdev_device *) event->base.device;
>
> - if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS)
> + if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS &&
> + event->base.type != LIBINPUT_EVENT_TABLET_PROXIMITY)
> return 0;
>
> switch(axis) {
> @@ -1409,6 +1410,7 @@ tablet_notify_proximity(struct libinput_device *device,
> uint32_t time,
> struct libinput_tool *tool,
> enum libinput_tool_proximity_state proximity_state,
> + unsigned char *changed_axes,
> double *axes)
> {
> struct libinput_event_tablet *proximity_event;
> @@ -1425,6 +1427,9 @@ tablet_notify_proximity(struct libinput_device *device,
> memcpy(proximity_event->axes,
> axes,
> sizeof(proximity_event->axes));
> + memcpy(proximity_event->changed_axes,
> + changed_axes,
> + sizeof(proximity_event->changed_axes));
>
> post_device_event(device,
> time,
> diff --git a/src/libinput.h b/src/libinput.h
> index 1f5ce20..91d0aaa 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -234,6 +234,10 @@ enum libinput_event_type {
> * Signals that a tool has come in or out of proximity of a device with
> * the @ref LIBINPUT_DEVICE_CAP_TABLET capability.
> *
> + * Proximity events contain each of the current values for each axis,
> + * and these values may be extracted from them in the same way they are
> + * with @ref LIBINPUT_EVENT_TABLET_AXIS events.
> + *
> * Some tools may always be in proximity. For these tools, events with
> * state @ref LIBINPUT_TOOL_PROXIMITY_IN are sent only once after @ref
> * LIBINPUT_EVENT_DEVICE_ADDED, and likewise events with state @ref
> @@ -1005,11 +1009,11 @@ libinput_event_touch_get_base_event(struct libinput_event_touch *event);
> * @ingroup event_tablet
> *
> * Checks if an axis was updated in this event or return 0 otherwise.
> - * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS,
> - * this function returns 0.
> + * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS or
> + * type @ref LIBINPUT_EVENT_TABLET_PROXIMITY, this function returns 0.
> *
> * @note It is an application bug to call this function for events other than
> - * @ref LIBINPUT_EVENT_TABLET_AXIS.
> + * @ref LIBINPUT_EVENT_TABLET_AXIS and @ref LIBINPUT_EVENT_TABLET_PROXIMITY.
> *
> * @param event The libinput tablet event
> * @param axis The axis to check for updates
> diff --git a/test/tablet.c b/test/tablet.c
> index 96857a9..d67d954 100644
> --- a/test/tablet.c
> +++ b/test/tablet.c
> @@ -174,7 +174,7 @@ START_TEST(motion)
> libinput_dispatch(li);
>
> litest_wait_for_event_of_type(li,
> - LIBINPUT_EVENT_TABLET_AXIS,
> + LIBINPUT_EVENT_TABLET_PROXIMITY,
> -1);
>
> while ((event = libinput_get_event(li))) {
> @@ -183,7 +183,7 @@ START_TEST(motion)
>
> tablet_event = libinput_event_get_tablet_event(event);
> ck_assert_int_eq(libinput_event_get_type(event),
> - LIBINPUT_EVENT_TABLET_AXIS);
> + LIBINPUT_EVENT_TABLET_PROXIMITY);
>
>
> x_changed = libinput_event_tablet_axis_has_changed(
> @@ -277,7 +277,7 @@ START_TEST(left_handed)
> libinput_dispatch(li);
> libinput_device_config_left_handed_set(dev->libinput_device, 1);
>
> - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
> + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1);
>
> while ((event = libinput_get_event(li))) {
> tablet_event = libinput_event_get_tablet_event(event);
> @@ -320,7 +320,7 @@ START_TEST(left_handed)
> * proximity */
> litest_tablet_proximity_in(dev, 0, 100, axes);
>
> - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
> + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1);
>
> while ((event = libinput_get_event(li))) {
> tablet_event = libinput_event_get_tablet_event(event);
> diff --git a/tools/event-debug.c b/tools/event-debug.c
> index 844f8de..be3d9e9 100644
> --- a/tools/event-debug.c
> +++ b/tools/event-debug.c
> @@ -325,6 +325,8 @@ print_proximity_event(struct libinput_event *ev)
> enum libinput_tool_proximity_state state;
> const char *tool_str,
> *state_str;
> + double x, y;
> + double dist, pressure;
>
> switch (libinput_tool_get_type(tool)) {
> case LIBINPUT_TOOL_NONE:
> @@ -360,14 +362,40 @@ print_proximity_event(struct libinput_event *ev)
>
> state = libinput_event_tablet_get_proximity_state(t);
>
> - if (state == LIBINPUT_TOOL_PROXIMITY_IN)
> - state_str = "came into proximity";
> - else if (state == LIBINPUT_TOOL_PROXIMITY_OUT)
> - state_str = "left proximity";
> + print_event_time(libinput_event_tablet_get_time(t));
> +
> + if (state == LIBINPUT_TOOL_PROXIMITY_IN) {
> + x = libinput_event_tablet_get_axis_value(
> + t, LIBINPUT_TABLET_AXIS_X);
> + y = libinput_event_tablet_get_axis_value(
> + t, LIBINPUT_TABLET_AXIS_Y);
> + printf("\t%.2f/%.2f", x, y);
> +
> + x = libinput_event_tablet_get_axis_value(
> + t, LIBINPUT_TABLET_AXIS_TILT_X);
> + y = libinput_event_tablet_get_axis_value(
> + t, LIBINPUT_TABLET_AXIS_TILT_Y);
> + printf("\ttilt: %.2f/%.2f ", x, y);
> +
> + dist = libinput_event_tablet_get_axis_value(
> + t, LIBINPUT_TABLET_AXIS_DISTANCE);
> + pressure = libinput_event_tablet_get_axis_value(
> + t, LIBINPUT_TABLET_AXIS_PRESSURE);
> +
> + if (dist)
> + printf("distance: %.2f ", dist);
> + else
> + printf("pressure: %.2f ", pressure);
> +
> + state_str = "proximity in";
> + } else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) {
> + state_str = "proximity out";
> +
> + printf("\t");
> + }
> else
> abort();
>
> - print_event_time(libinput_event_tablet_get_time(t));
> printf("%s (%#x) %s",
> tool_str, libinput_tool_get_serial(tool), state_str);
> printf("\n");
> --
> 1.9.5
>
More information about the wayland-devel
mailing list