tablet: Include tool with all events

Signed-off-by: Stephen Chandler Paul <thatslyude@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Stephen Chandler Paul 2014-06-26 21:31:52 -04:00 committed by Peter Hutterer
parent 8b1b988fd8
commit bcbf9f95fd
5 changed files with 51 additions and 37 deletions

View file

@ -94,10 +94,7 @@ tablet_update_tool(struct tablet_dispatch *tablet,
assert(tool != LIBINPUT_TOOL_NONE); assert(tool != LIBINPUT_TOOL_NONE);
if (enabled) { if (enabled) {
if (tool != tablet->current_tool_type) { tablet->current_tool_type = tool;
tablet->current_tool_type = tool;
tablet_set_status(tablet, TABLET_TOOL_UPDATED);
}
tablet_mark_all_axes_changed(tablet, device); tablet_mark_all_axes_changed(tablet, device);
tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
@ -126,7 +123,8 @@ normalize_tilt(const struct input_absinfo * absinfo) {
static void static void
tablet_check_notify_axes(struct tablet_dispatch *tablet, tablet_check_notify_axes(struct tablet_dispatch *tablet,
struct evdev_device *device, struct evdev_device *device,
uint32_t time) uint32_t time,
struct libinput_tool *tool)
{ {
struct libinput_device *base = &device->base; struct libinput_device *base = &device->base;
bool axis_update_needed = false; 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_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
tablet_notify_axis(base, tablet_notify_axis(base,
time, time,
tool,
tablet->changed_axes, tablet->changed_axes,
tablet->axes); tablet->axes);
@ -247,11 +246,9 @@ tablet_process_misc(struct tablet_dispatch *tablet,
{ {
switch (e->code) { switch (e->code) {
case MSC_SERIAL: case MSC_SERIAL:
if (e->value != (int32_t)tablet->current_tool_serial && if (e->value != -1)
e->value != -1) {
tablet->current_tool_serial = e->value; tablet->current_tool_serial = e->value;
tablet_set_status(tablet, TABLET_TOOL_UPDATED);
}
break; break;
default: default:
log_info(device->base.seat->libinput, log_info(device->base.seat->libinput,
@ -297,6 +294,7 @@ static void
tablet_notify_button_mask(struct tablet_dispatch *tablet, tablet_notify_button_mask(struct tablet_dispatch *tablet,
struct evdev_device *device, struct evdev_device *device,
uint32_t time, uint32_t time,
struct libinput_tool *tool,
uint32_t buttons, uint32_t buttons,
uint32_t button_base, uint32_t button_base,
enum libinput_button_state state) enum libinput_button_state state)
@ -316,6 +314,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet,
tablet_notify_button(base, tablet_notify_button(base,
time, time,
tool,
num_button + button_base - 1, num_button + button_base - 1,
state); state);
} }
@ -325,6 +324,7 @@ static void
tablet_notify_buttons(struct tablet_dispatch *tablet, tablet_notify_buttons(struct tablet_dispatch *tablet,
struct evdev_device *device, struct evdev_device *device,
uint32_t time, uint32_t time,
struct libinput_tool *tool,
enum libinput_button_state state) enum libinput_button_state state)
{ {
uint32_t stylus_buttons; uint32_t stylus_buttons;
@ -336,8 +336,13 @@ tablet_notify_buttons(struct tablet_dispatch *tablet,
stylus_buttons = stylus_buttons =
tablet_get_released_buttons(tablet, stylus_buttons); tablet_get_released_buttons(tablet, stylus_buttons);
tablet_notify_button_mask(tablet, device, time, tablet_notify_button_mask(tablet,
stylus_buttons, BTN_TOUCH, state); device,
time,
tool,
stylus_buttons,
BTN_TOUCH,
state);
} }
static void static void
@ -392,24 +397,30 @@ tablet_flush(struct tablet_dispatch *tablet,
if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
sanitize_tablet_axes(tablet); 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); tablet_unset_status(tablet, TABLET_AXES_UPDATED);
} }
if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { 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); LIBINPUT_BUTTON_STATE_RELEASED);
tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED); tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED);
} }
if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) { 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); LIBINPUT_BUTTON_STATE_PRESSED);
tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED);
} }
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { 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_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
} }

View file

@ -30,13 +30,12 @@
enum tablet_status { enum tablet_status {
TABLET_NONE = 0, TABLET_NONE = 0,
TABLET_AXES_UPDATED = 1 << 0, TABLET_AXES_UPDATED = 1 << 0,
TABLET_TOOL_UPDATED = 1 << 1, TABLET_BUTTONS_PRESSED = 1 << 1,
TABLET_BUTTONS_PRESSED = 1 << 2, TABLET_BUTTONS_RELEASED = 1 << 2,
TABLET_BUTTONS_RELEASED = 1 << 3, TABLET_STYLUS_IN_CONTACT = 1 << 3,
TABLET_STYLUS_IN_CONTACT = 1 << 4, TABLET_TOOL_LEAVING_PROXIMITY = 1 << 4,
TABLET_TOOL_LEAVING_PROXIMITY = 1 << 5, TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5,
TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6, TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6
TABLET_TOOL_ENTERING_PROXIMITY = 1 << 7
}; };
struct button_state { struct button_state {

View file

@ -214,6 +214,7 @@ touch_notify_touch_up(struct libinput_device *device,
void void
tablet_notify_axis(struct libinput_device *device, tablet_notify_axis(struct libinput_device *device,
uint32_t time, uint32_t time,
struct libinput_tool *tool,
unsigned char *changed_axes, unsigned char *changed_axes,
double *axes); double *axes);
@ -224,11 +225,13 @@ tablet_notify_proximity_in(struct libinput_device *device,
void void
tablet_notify_proximity_out(struct libinput_device *device, tablet_notify_proximity_out(struct libinput_device *device,
uint32_t time); uint32_t time,
struct libinput_tool *tool);
void void
tablet_notify_button(struct libinput_device *device, tablet_notify_button(struct libinput_device *device,
uint32_t time, uint32_t time,
struct libinput_tool *tool,
int32_t button, int32_t button,
enum libinput_button_state state); enum libinput_button_state state);
void void

View file

@ -1230,6 +1230,7 @@ touch_notify_frame(struct libinput_device *device,
void void
tablet_notify_axis(struct libinput_device *device, tablet_notify_axis(struct libinput_device *device,
uint32_t time, uint32_t time,
struct libinput_tool *tool,
unsigned char *changed_axes, unsigned char *changed_axes,
double *axes) double *axes)
{ {
@ -1241,6 +1242,7 @@ tablet_notify_axis(struct libinput_device *device,
*axis_event = (struct libinput_event_tablet) { *axis_event = (struct libinput_event_tablet) {
.time = time, .time = time,
.tool = tool,
.axes = axes, .axes = axes,
}; };
@ -1276,7 +1278,8 @@ tablet_notify_proximity_in(struct libinput_device *device,
void void
tablet_notify_proximity_out(struct libinput_device *device, 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; struct libinput_event_tablet *proximity_out_update_event;
@ -1285,7 +1288,8 @@ tablet_notify_proximity_out(struct libinput_device *device,
return; return;
*proximity_out_update_event = (struct libinput_event_tablet) { *proximity_out_update_event = (struct libinput_event_tablet) {
.time = time .time = time,
.tool = tool,
}; };
post_device_event(device, post_device_event(device,
@ -1296,6 +1300,7 @@ tablet_notify_proximity_out(struct libinput_device *device,
void void
tablet_notify_button(struct libinput_device *device, tablet_notify_button(struct libinput_device *device,
uint32_t time, uint32_t time,
struct libinput_tool *tool,
int32_t button, int32_t button,
enum libinput_button_state state) enum libinput_button_state state)
{ {
@ -1312,6 +1317,7 @@ tablet_notify_button(struct libinput_device *device,
*button_event = (struct libinput_event_tablet) { *button_event = (struct libinput_event_tablet) {
.time = time, .time = time,
.tool = tool,
.button = button, .button = button,
.state = state, .state = state,
.seat_button_count = seat_button_count, .seat_button_count = seat_button_count,

View file

@ -918,18 +918,13 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event,
/** /**
* @ingroup event_tablet * @ingroup event_tablet
* *
* Returns the tool that came into proximity for this event. * Returns the tool that was in use during this event.
* For tablet events that are not of type @ref * By default, each tool will stay valid for as long as it is being used, and is
* LIBINPUT_EVENT_TABLET_PROXIMITY_IN, this function returns NULL. By default, * destroyed when another tool comes into proximity. However, the lifetime of
* the lifetime of each tool will stay valid for as long as it is being used, * the tool may be extended by using libinput_tool_ref() to increment the
* and is destroyed when another tool comes into proximity. However, the * reference count of the tool. This guarantees that whenever the tool comes
* lifetime of the tool may be extended by using libinput_tool_ref() to * back into proximity of the tablet, that the same structure will be used to
* increment the reference count of the tool. This guarantees that whenever the * represent the tool.
* 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.
* *
* @note On tablets where the serial number of tools is not reported, each tool * @note On tablets where the serial number of tools is not reported, each tool
* cannot be guaranteed to be unique. * cannot be guaranteed to be unique.