diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index af2f25c6..acab5a15 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -192,12 +192,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)); } @@ -471,18 +480,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); } @@ -509,9 +512,12 @@ tablet_flush(struct tablet_dispatch *tablet, 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); + memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); tablet_change_to_left_handed(device); } diff --git a/src/libinput-private.h b/src/libinput-private.h index 415aac46..33ce2db7 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 38c2fd79..aac6183d 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 5904d8b7..197c09e5 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 @@ -1004,11 +1008,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 94ed3cb9..036d701a 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); @@ -323,7 +323,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 a2f7261e..9f44cf61 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,39 @@ print_proximity_event(struct libinput_event *ev) state = libinput_event_tablet_get_proximity_state(t); - if (state == LIBINPUT_TOOL_PROXIMITY_IN) - state_str = "proximity-in"; - else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) - state_str = "proximity-out"; - else - abort(); - 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("\tdistance: %.2f ", dist); + else + printf("\tpressure: %.2f ", pressure); + + state_str = "proximity-in"; + } else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) { + state_str = "proximity-out"; + printf("\t"); + } else { + abort(); + } + printf("%s (%#x) %s", tool_str, libinput_tool_get_serial(tool), state_str); printf("\n");