From bcbf9f95fdf7a72628b26f8ef5e90872083e6916 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 26 Jun 2014 21:31:52 -0400 Subject: [PATCH] tablet: Include tool with all events Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 41 ++++++++++++++++++++++++++--------------- src/evdev-tablet.h | 13 ++++++------- src/libinput-private.h | 5 ++++- src/libinput.c | 10 ++++++++-- src/libinput.h | 19 +++++++------------ 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index e6595bc4..710e391e 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -94,10 +94,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, assert(tool != LIBINPUT_TOOL_NONE); if (enabled) { - if (tool != tablet->current_tool_type) { - tablet->current_tool_type = tool; - tablet_set_status(tablet, TABLET_TOOL_UPDATED); - } + tablet->current_tool_type = tool; tablet_mark_all_axes_changed(tablet, device); tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); @@ -126,7 +123,8 @@ normalize_tilt(const struct input_absinfo * absinfo) { static void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, - uint32_t time) + uint32_t time, + struct libinput_tool *tool) { struct libinput_device *base = &device->base; bool axis_update_needed = false; @@ -169,6 +167,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) tablet_notify_axis(base, time, + tool, tablet->changed_axes, tablet->axes); @@ -247,11 +246,9 @@ tablet_process_misc(struct tablet_dispatch *tablet, { switch (e->code) { case MSC_SERIAL: - if (e->value != (int32_t)tablet->current_tool_serial && - e->value != -1) { + if (e->value != -1) tablet->current_tool_serial = e->value; - tablet_set_status(tablet, TABLET_TOOL_UPDATED); - } + break; default: log_info(device->base.seat->libinput, @@ -297,6 +294,7 @@ static void tablet_notify_button_mask(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time, + struct libinput_tool *tool, uint32_t buttons, uint32_t button_base, enum libinput_button_state state) @@ -316,6 +314,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, tablet_notify_button(base, time, + tool, num_button + button_base - 1, state); } @@ -325,6 +324,7 @@ static void tablet_notify_buttons(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time, + struct libinput_tool *tool, enum libinput_button_state state) { uint32_t stylus_buttons; @@ -336,8 +336,13 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, stylus_buttons = tablet_get_released_buttons(tablet, stylus_buttons); - tablet_notify_button_mask(tablet, device, time, - stylus_buttons, BTN_TOUCH, state); + tablet_notify_button_mask(tablet, + device, + time, + tool, + stylus_buttons, + BTN_TOUCH, + state); } static void @@ -392,24 +397,30 @@ tablet_flush(struct tablet_dispatch *tablet, if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { sanitize_tablet_axes(tablet); - tablet_check_notify_axes(tablet, device, time); + tablet_check_notify_axes(tablet, device, time, tool); tablet_unset_status(tablet, TABLET_AXES_UPDATED); } if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { - tablet_notify_buttons(tablet, device, time, + tablet_notify_buttons(tablet, + device, + time, + tool, LIBINPUT_BUTTON_STATE_RELEASED); tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED); } if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) { - tablet_notify_buttons(tablet, device, time, + tablet_notify_buttons(tablet, + device, + time, + tool, LIBINPUT_BUTTON_STATE_PRESSED); tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); } if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { - tablet_notify_proximity_out(&device->base, time); + tablet_notify_proximity_out(&device->base, time, tool); tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index e6e66d74..4de4ceca 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -30,13 +30,12 @@ enum tablet_status { TABLET_NONE = 0, TABLET_AXES_UPDATED = 1 << 0, - TABLET_TOOL_UPDATED = 1 << 1, - TABLET_BUTTONS_PRESSED = 1 << 2, - TABLET_BUTTONS_RELEASED = 1 << 3, - TABLET_STYLUS_IN_CONTACT = 1 << 4, - TABLET_TOOL_LEAVING_PROXIMITY = 1 << 5, - TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6, - TABLET_TOOL_ENTERING_PROXIMITY = 1 << 7 + TABLET_BUTTONS_PRESSED = 1 << 1, + TABLET_BUTTONS_RELEASED = 1 << 2, + TABLET_STYLUS_IN_CONTACT = 1 << 3, + TABLET_TOOL_LEAVING_PROXIMITY = 1 << 4, + TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5, + TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6 }; struct button_state { diff --git a/src/libinput-private.h b/src/libinput-private.h index e59fe129..a396d783 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -214,6 +214,7 @@ touch_notify_touch_up(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, unsigned char *changed_axes, double *axes); @@ -224,11 +225,13 @@ tablet_notify_proximity_in(struct libinput_device *device, void tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time); + uint32_t time, + struct libinput_tool *tool); void tablet_notify_button(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, int32_t button, enum libinput_button_state state); void diff --git a/src/libinput.c b/src/libinput.c index f054c0d7..7d9d6a0f 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1230,6 +1230,7 @@ touch_notify_frame(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, unsigned char *changed_axes, double *axes) { @@ -1241,6 +1242,7 @@ tablet_notify_axis(struct libinput_device *device, *axis_event = (struct libinput_event_tablet) { .time = time, + .tool = tool, .axes = axes, }; @@ -1276,7 +1278,8 @@ tablet_notify_proximity_in(struct libinput_device *device, void tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time) + uint32_t time, + struct libinput_tool *tool) { struct libinput_event_tablet *proximity_out_update_event; @@ -1285,7 +1288,8 @@ tablet_notify_proximity_out(struct libinput_device *device, return; *proximity_out_update_event = (struct libinput_event_tablet) { - .time = time + .time = time, + .tool = tool, }; post_device_event(device, @@ -1296,6 +1300,7 @@ tablet_notify_proximity_out(struct libinput_device *device, void tablet_notify_button(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, int32_t button, enum libinput_button_state state) { @@ -1312,6 +1317,7 @@ tablet_notify_button(struct libinput_device *device, *button_event = (struct libinput_event_tablet) { .time = time, + .tool = tool, .button = button, .state = state, .seat_button_count = seat_button_count, diff --git a/src/libinput.h b/src/libinput.h index cfd27d61..37edac53 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -918,18 +918,13 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, /** * @ingroup event_tablet * - * Returns the tool that came into proximity for this event. - * For tablet events that are not of type @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_IN, this function returns NULL. By default, - * the lifetime of each tool will stay valid for as long as it is being used, - * and is destroyed when another tool comes into proximity. However, the - * lifetime of the tool may be extended by using libinput_tool_ref() to - * increment the reference count of the tool. This guarantees that whenever the - * tool comes back into proximity of the tablet, that the same structure will be - * used to represent the tool. - * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN. + * Returns the tool that was in use during this event. + * By default, each tool will stay valid for as long as it is being used, and is + * destroyed when another tool comes into proximity. However, the lifetime of + * the tool may be extended by using libinput_tool_ref() to increment the + * reference count of the tool. This guarantees that whenever the tool comes + * back into proximity of the tablet, that the same structure will be used to + * represent the tool. * * @note On tablets where the serial number of tools is not reported, each tool * cannot be guaranteed to be unique.