diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 6887307b..af2f25c6 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -472,10 +472,11 @@ tablet_flush(struct tablet_dispatch *tablet, 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_in(&device->base, - time, - tool, - tablet->axes); + tablet_notify_proximity(&device->base, + time, + tool, + LIBINPUT_TOOL_PROXIMITY_IN, + tablet->axes); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); } @@ -504,10 +505,11 @@ tablet_flush(struct tablet_dispatch *tablet, } if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { - tablet_notify_proximity_out(&device->base, - time, - tool, - tablet->axes); + tablet_notify_proximity(&device->base, + time, + tool, + LIBINPUT_TOOL_PROXIMITY_OUT, + 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 7b4a0d6e..415aac46 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -350,16 +350,11 @@ tablet_notify_axis(struct libinput_device *device, double *axes); void -tablet_notify_proximity_in(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes); - -void -tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes); +tablet_notify_proximity(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool, + enum libinput_tool_proximity_state state, + double *axes); void tablet_notify_button(struct libinput_device *device, diff --git a/src/libinput.c b/src/libinput.c index 5e7514b2..38c2fd79 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -88,6 +88,7 @@ struct libinput_event_tablet { double axes[LIBINPUT_TABLET_AXIS_CNT]; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; struct libinput_tool *tool; + enum libinput_tool_proximity_state proximity_state; }; static void @@ -194,8 +195,7 @@ libinput_event_get_pointer_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -224,8 +224,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -254,8 +253,7 @@ libinput_event_get_touch_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: return (struct libinput_event_touch *) event; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -283,8 +281,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: break; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: return (struct libinput_event_tablet *) event; } @@ -312,8 +309,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -629,6 +625,12 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event) return event->tool; } +LIBINPUT_EXPORT enum libinput_tool_proximity_state +libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) +{ + return event->proximity_state; +} + LIBINPUT_EXPORT uint32_t libinput_event_tablet_get_time(struct libinput_event_tablet *event) { @@ -1403,55 +1405,31 @@ tablet_notify_axis(struct libinput_device *device, } void -tablet_notify_proximity_in(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes) +tablet_notify_proximity(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool, + enum libinput_tool_proximity_state proximity_state, + double *axes) { - struct libinput_event_tablet *proximity_in_event; + struct libinput_event_tablet *proximity_event; - proximity_in_event = zalloc(sizeof *proximity_in_event); - if (!proximity_in_event) + proximity_event = zalloc(sizeof *proximity_event); + if (!proximity_event) return; - *proximity_in_event = (struct libinput_event_tablet) { + *proximity_event = (struct libinput_event_tablet) { .time = time, .tool = tool, + .proximity_state = proximity_state, }; - memcpy(proximity_in_event->axes, + memcpy(proximity_event->axes, axes, - sizeof(proximity_in_event->axes)); + sizeof(proximity_event->axes)); post_device_event(device, time, - LIBINPUT_EVENT_TABLET_PROXIMITY_IN, - &proximity_in_event->base); -} - -void -tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes) -{ - struct libinput_event_tablet *proximity_out_update_event; - - proximity_out_update_event = zalloc(sizeof *proximity_out_update_event); - if (!proximity_out_update_event) - return; - - *proximity_out_update_event = (struct libinput_event_tablet) { - .time = time, - .tool = tool, - }; - memcpy(proximity_out_update_event->axes, - axes, - sizeof(proximity_out_update_event->axes)); - - post_device_event(device, - time, - LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, - &proximity_out_update_event->base); + LIBINPUT_EVENT_TABLET_PROXIMITY, + &proximity_event->base); } void diff --git a/src/libinput.h b/src/libinput.h index 8b93bf36..5904d8b7 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -172,6 +172,17 @@ enum libinput_tool_type { LIBINPUT_TOOL_LENS }; +/** + * @ingroup device + * + * The state of proximity for a tool on a device. The device must have the @ref + * LIBINPUT_DEVICE_CAP_TABLET capability. + */ +enum libinput_tool_proximity_state { + LIBINPUT_TOOL_PROXIMITY_OUT = 0, + LIBINPUT_TOOL_PROXIMITY_IN = 1, +}; + /** * @ingroup base * @@ -220,36 +231,26 @@ enum libinput_event_type { LIBINPUT_EVENT_TABLET_AXIS = 600, /** - * Signals that a tool has come into proximity of a device with the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. + * Signals that a tool has come in or out of proximity of a device with + * the @ref LIBINPUT_DEVICE_CAP_TABLET capability. * - * Some tools may always be in proximity. For these tools, the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_IN is sent only once after @ref - * LIBINPUT_EVENT_DEVICE_ADDED, and likewise the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_OUT is sent only once before @ref + * 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 + * LIBINPUT_TOOL_PROXIMITY_OUT are sent only once before @ref * LIBINPUT_EVENT_DEVICE_REMOVED. * * If the tool that comes into proximity supports x/y coordinates, * libinput guarantees that both x and y are set in the proximity * event. - */ - LIBINPUT_EVENT_TABLET_PROXIMITY_IN, - /** - * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET - * capability has detected that there is no longer a tool in use. When - * this happens, the value of every axis should be assumed to have a - * value of 0 and any buttons that are currently held down on the stylus - * are marked as released. Button release events for each button that - * was held down on the stylus are sent before the initial proximity out - * event. * - * Some tools may always be in proximity. For these tools, the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_IN is sent only once after @ref - * LIBINPUT_EVENT_DEVICE_ADDED, and likewise the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_OUT is sent only once before @ref - * LIBINPUT_EVENT_DEVICE_REMOVED. + * When a tool goes out of proximity, the value of every axis should be + * assumed to have a value of 0 and any buttons that are currently held + * down on the stylus are marked as released. Button release events for + * each button that was held down on the stylus are sent before the + * initial proximity out event. */ - LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, + LIBINPUT_EVENT_TABLET_PROXIMITY, LIBINPUT_EVENT_TABLET_BUTTON }; @@ -345,8 +346,7 @@ struct libinput_event_touch; * * Tablet event representing an axis update, button press, or tool update. Valid * event types for this event are @ref LIBINPUT_EVENT_TABLET_AXIS, @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_IN, @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN - * and @ref LIBINPUT_EVENT_TABLET_BUTTON. + * LIBINPUT_EVENT_TABLET_PROXIMITY and @ref LIBINPUT_EVENT_TABLET_BUTTON. */ struct libinput_event_tablet; @@ -1092,6 +1092,19 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, struct libinput_tool * libinput_event_tablet_get_tool(struct libinput_event_tablet *event); +/** + * @ingroup event_tablet + * + * Returns the new proximity state of a tool from a proximity event. + * Used to check whether or not a tool came in or out of proximity during an + * event of type @ref LIBINPUT_EVENT_TABLET_PROXIMITY. + * + * @param event The libinput tablet event + * @return The new proximity state of the tool from the event. + */ +enum libinput_tool_proximity_state +libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event); + /** * @ingroup event_tablet * diff --git a/src/libinput.sym b/src/libinput.sym index d235e186..f9ccd98f 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -134,6 +134,7 @@ global: libinput_event_tablet_get_axis_value; libinput_event_tablet_get_button; libinput_event_tablet_get_button_state; + libinput_event_tablet_get_proximity_state; libinput_event_tablet_get_seat_button_count; libinput_event_tablet_get_time; libinput_event_tablet_get_tool; diff --git a/test/litest.c b/test/litest.c index 73228b47..199c0a17 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1152,11 +1152,8 @@ litest_event_type_str(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_AXIS: str = "TABLET AXIS"; break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - str = "TABLET PROX IN"; - break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: - str = "TABLET PROX OUT"; + case LIBINPUT_EVENT_TABLET_PROXIMITY: + str = "TABLET PROX"; break; case LIBINPUT_EVENT_TABLET_BUTTON: str = "TABLET BUTTON"; diff --git a/test/tablet.c b/test/tablet.c index 922915fc..94ed3cb9 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -55,7 +55,7 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_tool * tool; have_tool_update++; @@ -73,8 +73,14 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_OUT) - have_proximity_out = true; + LIBINPUT_EVENT_TABLET_PROXIMITY) { + struct libinput_event_tablet *t = + libinput_event_get_tablet_event(event); + + if (libinput_event_tablet_get_proximity_state(t) == + LIBINPUT_TOOL_PROXIMITY_OUT) + have_proximity_out = true; + } libinput_event_destroy(event); } @@ -626,7 +632,7 @@ START_TEST(tool_serial) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -663,7 +669,7 @@ START_TEST(serial_changes_tool) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -701,7 +707,7 @@ START_TEST(invalid_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -730,7 +736,7 @@ START_TEST(tool_ref) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { break; } libinput_event_destroy(event); @@ -825,7 +831,7 @@ START_TEST(tools_with_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); @@ -874,7 +880,7 @@ START_TEST(tools_without_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); @@ -922,7 +928,7 @@ START_TEST(tool_capabilities) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); struct libinput_tool *tool = @@ -946,7 +952,7 @@ START_TEST(tool_capabilities) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); struct libinput_tool *tool = diff --git a/tools/event-debug.c b/tools/event-debug.c index 1ca53c4a..32ccc795 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -109,11 +109,8 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_AXIS: type = "TABLET_AXIS"; break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - type = "TABLET_PROXIMITY_IN"; - break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: - type = "TABLET_PROXIMITY_OUT"; + case LIBINPUT_EVENT_TABLET_PROXIMITY: + type = "TABLET_PROXIMITY"; break; case LIBINPUT_EVENT_TABLET_BUTTON: type = "TABLET_BUTTON"; @@ -321,11 +318,13 @@ print_touch_event_without_coords(struct libinput_event *ev) } static void -print_proximity_in_event(struct libinput_event *ev) +print_proximity_event(struct libinput_event *ev) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); struct libinput_tool *tool = libinput_event_tablet_get_tool(t); - const char *tool_str; + enum libinput_tool_proximity_state state; + const char *tool_str, + *state_str; switch (libinput_tool_get_type(tool)) { case LIBINPUT_TOOL_NONE: @@ -359,16 +358,18 @@ print_proximity_in_event(struct libinput_event *ev) abort(); } - print_event_time(libinput_event_tablet_get_time(t)); - printf("%s (%#x)", tool_str, libinput_tool_get_serial(tool)); - printf("\n"); -} + state = libinput_event_tablet_get_proximity_state(t); -static void -print_proximity_out_event(struct libinput_event *ev) { - struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + 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)); + printf("%s (%#x) %s", + tool_str, libinput_tool_get_serial(tool), state_str); printf("\n"); } @@ -442,11 +443,8 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_AXIS: print_tablet_axis_event(ev); break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - print_proximity_in_event(ev); - break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: - print_proximity_out_event(ev); + case LIBINPUT_EVENT_TABLET_PROXIMITY: + print_proximity_event(ev); break; case LIBINPUT_EVENT_TABLET_BUTTON: print_tablet_button_event(ev); diff --git a/tools/event-gui.c b/tools/event-gui.c index 1857a2ef..063624f3 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -471,8 +471,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) } break; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; }