tablet: Replace tool-update with proximity-in

A proximity-in event is something we want, especially since the current drafted
wayland spec has a proximity-in event. Adding this also makes our events more
consistent. And since we can just report the current tool in use with
proximity-in events, we can get rid of the tool-update event.

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:51 -04:00 committed by Peter Hutterer
parent e18f713289
commit 8b1b988fd8
8 changed files with 61 additions and 66 deletions

View file

@ -99,6 +99,7 @@ tablet_update_tool(struct tablet_dispatch *tablet,
tablet_set_status(tablet, TABLET_TOOL_UPDATED);
}
tablet_mark_all_axes_changed(tablet, device);
tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
}
else
@ -250,8 +251,6 @@ tablet_process_misc(struct tablet_dispatch *tablet,
e->value != -1) {
tablet->current_tool_serial = e->value;
tablet_set_status(tablet, TABLET_TOOL_UPDATED);
tablet_unset_status(tablet,
TABLET_TOOL_OUT_OF_PROXIMITY);
}
break;
default:
@ -386,9 +385,9 @@ 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_UPDATED)) {
tablet_notify_tool_update(&device->base, time, tool);
tablet_unset_status(tablet, TABLET_TOOL_UPDATED);
} else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
tablet_notify_proximity_in(&device->base, time, tool);
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
}
if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {

View file

@ -35,7 +35,8 @@ enum tablet_status {
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_OUT_OF_PROXIMITY = 1 << 6,
TABLET_TOOL_ENTERING_PROXIMITY = 1 << 7
};
struct button_state {

View file

@ -218,9 +218,9 @@ tablet_notify_axis(struct libinput_device *device,
double *axes);
void
tablet_notify_tool_update(struct libinput_device *device,
uint32_t time,
struct libinput_tool *tool);
tablet_notify_proximity_in(struct libinput_device *device,
uint32_t time,
struct libinput_tool *tool);
void
tablet_notify_proximity_out(struct libinput_device *device,

View file

@ -195,7 +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_TOOL_UPDATE:
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
case LIBINPUT_EVENT_TABLET_BUTTON:
break;
@ -225,7 +225,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_TOOL_UPDATE:
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
case LIBINPUT_EVENT_TABLET_BUTTON:
break;
@ -255,7 +255,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_TOOL_UPDATE:
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
case LIBINPUT_EVENT_TABLET_BUTTON:
break;
@ -284,7 +284,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_TOOL_UPDATE:
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
case LIBINPUT_EVENT_TABLET_BUTTON:
return (struct libinput_event_tablet *) event;
@ -313,7 +313,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_TOOL_UPDATE:
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
case LIBINPUT_EVENT_TABLET_BUTTON:
break;
@ -1254,24 +1254,24 @@ tablet_notify_axis(struct libinput_device *device,
}
void
tablet_notify_tool_update(struct libinput_device *device,
uint32_t time,
struct libinput_tool *tool)
tablet_notify_proximity_in(struct libinput_device *device,
uint32_t time,
struct libinput_tool *tool)
{
struct libinput_event_tablet *tool_update_event;
struct libinput_event_tablet *proximity_in_event;
tool_update_event = zalloc(sizeof *tool_update_event);
if (!tool_update_event)
proximity_in_event = zalloc(sizeof *proximity_in_event);
if (!proximity_in_event)
return;
*tool_update_event = (struct libinput_event_tablet) {
*proximity_in_event = (struct libinput_event_tablet) {
.time = time,
.tool = tool,
};
post_device_event(device,
LIBINPUT_EVENT_TABLET_TOOL_UPDATE,
&tool_update_event->base);
LIBINPUT_EVENT_TABLET_PROXIMITY_IN,
&proximity_in_event->base);
}
void

View file

@ -261,10 +261,10 @@ enum libinput_event_type {
LIBINPUT_EVENT_TABLET_AXIS = 600,
/**
* Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET
* capability has changed its tool.
* Signals that a tool has come into proximity of a device with the @ref
* LIBINPUT_DEVICE_CAP_TABLET capability.
*/
LIBINPUT_EVENT_TABLET_TOOL_UPDATE,
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
@ -305,8 +305,8 @@ 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_TOOL_UPDATE, @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE and
* @ref LIBINPUT_EVENT_TABLET_BUTTON.
* LIBINPUT_EVENT_TABLET_PROXIMITY_IN, @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN
* and @ref LIBINPUT_EVENT_TABLET_BUTTON.
*/
struct libinput_event_tablet;
@ -918,17 +918,18 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event,
/**
* @ingroup event_tablet
*
* Return the new tool in use for this event.
* Returns the tool that came into proximity for this event.
* For tablet events that are not of type @ref
* LIBINPUT_EVENT_TABLET_TOOL_UPDATE, this function returns NULL. By default,
* the lifetime of each tool is bound to the lifetime of the event, so the tool
* will be destroyed when the event is destroyed. However, the lifetime of the
* tool may be extended by using libinput_tool_ref() to increment the reference
* count of the tool. Whenever libinput detects that the tool is in proximity of
* any tablet that's connected, it will return the same libinput_tool object.
* 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_TOOL_UPDATE.
* @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN.
*
* @note On tablets where the serial number of tools is not reported, each tool
* cannot be guaranteed to be unique.

View file

@ -55,7 +55,7 @@ START_TEST(proximity_in_out)
while ((event = libinput_get_event(li))) {
if (libinput_event_get_type(event) ==
LIBINPUT_EVENT_TABLET_TOOL_UPDATE) {
LIBINPUT_EVENT_TABLET_PROXIMITY_IN) {
struct libinput_tool * tool;
have_tool_update++;
@ -427,7 +427,7 @@ START_TEST(tool_serial)
libinput_dispatch(li);
while ((event = libinput_get_event(li))) {
if (libinput_event_get_type(event) ==
LIBINPUT_EVENT_TABLET_TOOL_UPDATE) {
LIBINPUT_EVENT_TABLET_PROXIMITY_IN) {
tablet_event = libinput_event_get_tablet_event(event);
tool = libinput_event_tablet_get_tool(tablet_event);
@ -453,16 +453,18 @@ START_TEST(serial_changes_tool)
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_drain_events(li);
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
litest_event(dev, EV_MSC, MSC_SERIAL, 2000);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
libinput_dispatch(li);
while ((event = libinput_get_event(li))) {
if (libinput_event_get_type(event) ==
LIBINPUT_EVENT_TABLET_TOOL_UPDATE) {
LIBINPUT_EVENT_TABLET_PROXIMITY_IN) {
tablet_event = libinput_event_get_tablet_event(event);
tool = libinput_event_tablet_get_tool(tablet_event);
@ -481,42 +483,34 @@ START_TEST(invalid_serials)
struct litest_device *dev = litest_current_device();
struct libinput *li = dev->libinput;
struct libinput_event *event;
bool tool_updated = false;
struct libinput_event_tablet *tablet_event;
struct libinput_tool *tool;
litest_drain_events(li);
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
litest_drain_events(li);
litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
litest_event(dev, EV_MSC, MSC_SERIAL, -1);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
libinput_dispatch(li);
while ((event = libinput_get_event(li))) {
if (libinput_event_get_type(event) ==
LIBINPUT_EVENT_TABLET_TOOL_UPDATE)
tool_updated = true;
LIBINPUT_EVENT_TABLET_PROXIMITY_IN) {
tablet_event = libinput_event_get_tablet_event(event);
tool = libinput_event_tablet_get_tool(tablet_event);
ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000);
}
libinput_event_destroy(event);
}
ck_assert(!tool_updated);
/* Make sure libinput doesn't report a tool update when the serial
* number goes back from -1 to what it was previously */
litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
litest_event(dev, EV_SYN, SYN_REPORT, 0);
libinput_dispatch(li);
while ((event = libinput_get_event(li))) {
if (libinput_event_get_type(event) ==
LIBINPUT_EVENT_TABLET_TOOL_UPDATE)
tool_updated = true;
libinput_event_destroy(event);
}
ck_assert(!tool_updated);
}
END_TEST
@ -537,7 +531,7 @@ START_TEST(tool_ref)
libinput_dispatch(li);
while ((event = libinput_get_event(li))) {
if (libinput_event_get_type(event) ==
LIBINPUT_EVENT_TABLET_TOOL_UPDATE) {
LIBINPUT_EVENT_TABLET_PROXIMITY_IN) {
break;
}
libinput_event_destroy(event);

View file

@ -243,8 +243,8 @@ print_event_header(struct libinput_event *ev)
case LIBINPUT_EVENT_TABLET_AXIS:
type = "TABLET_AXIS";
break;
case LIBINPUT_EVENT_TABLET_TOOL_UPDATE:
type = "TABLET_TOOL_UPDATE";
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
type = "TABLET_PROXIMITY_IN";
break;
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
type = "TABLET_PROXIMITY_OUT";
@ -424,7 +424,7 @@ print_touch_event_without_coords(struct libinput_event *ev)
}
static void
print_tool_update_event(struct libinput_event *ev)
print_proximity_in_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);
@ -543,8 +543,8 @@ handle_and_print_events(struct libinput *li)
case LIBINPUT_EVENT_TABLET_AXIS:
print_tablet_axis_event(ev);
break;
case LIBINPUT_EVENT_TABLET_TOOL_UPDATE:
print_tool_update_event(ev);
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
print_proximity_in_event(ev);
break;
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
print_proximity_out_event(ev);

View file

@ -376,7 +376,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
}
break;
case LIBINPUT_EVENT_TABLET_AXIS:
case LIBINPUT_EVENT_TABLET_TOOL_UPDATE:
case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
case LIBINPUT_EVENT_TABLET_BUTTON:
break;