[PATCH libinput 2/2] tablet: Add TABLET_FRAME event

Stephen Chandler Paul thatslyude at gmail.com
Sun Jul 13 16:19:29 PDT 2014


This event is used to signify the end of a sequence of events from the tablet.
This is required since the wayland protocol for tablets also has a frame event,
and it's impossible to tell where an event frame ends if libinput doesn't tell
us.

Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
---
 src/evdev-tablet.c     | 12 +++++++++++-
 src/evdev-tablet.h     |  3 ++-
 src/libinput-private.h |  7 +++++++
 src/libinput.c         | 28 ++++++++++++++++++++++++++++
 src/libinput.h         |  7 ++++++-
 tools/event-debug.c    | 15 +++++++++++++++
 tools/event-gui.c      |  1 +
 7 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index d1ad4bb..09b4b6b 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -164,12 +164,14 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
 
 	if (axis_update_needed &&
 	    !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) &&
-	    !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
+	    !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
 		tablet_notify_axis(base,
 				   time,
 				   tool,
 				   tablet->changed_axes,
 				   tablet->axes);
+		tablet_set_status(tablet, TABLET_FRAME_NEEDED);
+	}
 
 	memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
 }
@@ -391,12 +393,14 @@ tablet_flush(struct tablet_dispatch *tablet,
 		/* Release all stylus buttons */
 		tablet->button_state.stylus_buttons = 0;
 		tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
+		tablet_set_status(tablet, TABLET_FRAME_NEEDED);
 	} else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
 		tablet_notify_proximity_in(&device->base,
 					   time,
 					   tool,
 					   tablet->axes);
 		tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
+		tablet_set_status(tablet, TABLET_FRAME_NEEDED);
 	}
 
 	if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
@@ -412,6 +416,7 @@ tablet_flush(struct tablet_dispatch *tablet,
 				      tool,
 				      LIBINPUT_BUTTON_STATE_RELEASED);
 		tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED);
+		tablet_set_status(tablet, TABLET_FRAME_NEEDED);
 	}
 
 	if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) {
@@ -421,6 +426,7 @@ tablet_flush(struct tablet_dispatch *tablet,
 				      tool,
 				      LIBINPUT_BUTTON_STATE_PRESSED);
 		tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED);
+		tablet_set_status(tablet, TABLET_FRAME_NEEDED);
 	}
 
 	if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
@@ -431,6 +437,10 @@ tablet_flush(struct tablet_dispatch *tablet,
 		tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
 		tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
 	}
+	if (tablet_has_status(tablet, TABLET_FRAME_NEEDED)) {
+		tablet_notify_frame(&device->base, time, tool, tablet->axes);
+		tablet_unset_status(tablet, TABLET_FRAME_NEEDED);
+	}
 
 	/* Update state */
 	memcpy(&tablet->prev_button_state,
diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h
index 1b53d20..e5c8654 100644
--- a/src/evdev-tablet.h
+++ b/src/evdev-tablet.h
@@ -35,7 +35,8 @@ enum tablet_status {
 	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
+	TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6,
+	TABLET_FRAME_NEEDED = 1 << 7
 };
 
 struct button_state {
diff --git a/src/libinput-private.h b/src/libinput-private.h
index dbdf5e6..f348dd8 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -237,6 +237,13 @@ tablet_notify_button(struct libinput_device *device,
 		     double *axes,
 		     int32_t button,
 		     enum libinput_button_state state);
+
+void
+tablet_notify_frame(struct libinput_device *device,
+		    uint32_t time,
+		    struct libinput_tool *tool,
+		    double *axes);
+
 void
 touch_notify_frame(struct libinput_device *device,
 		   uint32_t time);
diff --git a/src/libinput.c b/src/libinput.c
index 5d26bc9..48775ad 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -198,6 +198,7 @@ libinput_event_get_pointer_event(struct libinput_event *event)
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
 	case LIBINPUT_EVENT_TABLET_BUTTON:
+	case LIBINPUT_EVENT_TABLET_FRAME:
 		break;
 	}
 
@@ -228,6 +229,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event)
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
 	case LIBINPUT_EVENT_TABLET_BUTTON:
+	case LIBINPUT_EVENT_TABLET_FRAME:
 		break;
 	}
 
@@ -258,6 +260,7 @@ libinput_event_get_touch_event(struct libinput_event *event)
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
 	case LIBINPUT_EVENT_TABLET_BUTTON:
+	case LIBINPUT_EVENT_TABLET_FRAME:
 		break;
 	}
 
@@ -287,6 +290,7 @@ libinput_event_get_tablet_event(struct libinput_event *event)
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
 	case LIBINPUT_EVENT_TABLET_BUTTON:
+	case LIBINPUT_EVENT_TABLET_FRAME:
 		return (struct libinput_event_tablet *) event;
 	}
 
@@ -316,6 +320,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event)
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
 	case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
 	case LIBINPUT_EVENT_TABLET_BUTTON:
+	case LIBINPUT_EVENT_TABLET_FRAME:
 		break;
 	}
 
@@ -1338,6 +1343,29 @@ tablet_notify_button(struct libinput_device *device,
 			  &button_event->base);
 }
 
+void
+tablet_notify_frame(struct libinput_device *device,
+		    uint32_t time,
+		    struct libinput_tool *tool,
+		    double *axes)
+{
+	struct libinput_event_tablet *frame_event;
+
+	frame_event = zalloc(sizeof *frame_event);
+	if (!frame_event)
+		return;
+
+	*frame_event = (struct libinput_event_tablet) {
+		.time = time,
+		.tool = tool,
+	};
+	memcpy(frame_event->axes, axes, sizeof(frame_event->axes));
+
+	post_device_event(device,
+			  LIBINPUT_EVENT_TABLET_FRAME,
+			  &frame_event->base);
+}
+
 static void
 libinput_post_event(struct libinput *libinput,
 		    struct libinput_event *event)
diff --git a/src/libinput.h b/src/libinput.h
index 14e533e..3643d5e 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -275,7 +275,12 @@ enum libinput_event_type {
 	 * event.
 	 */
 	LIBINPUT_EVENT_TABLET_PROXIMITY_OUT,
-	LIBINPUT_EVENT_TABLET_BUTTON
+	LIBINPUT_EVENT_TABLET_BUTTON,
+	/**
+	 * Signals the end of a sequence of events from a device with the @ref
+	 * LIBINPUT_DEVICE_CAP_TABLET capability.
+	 */
+	LIBINPUT_EVENT_TABLET_FRAME
 };
 
 struct libinput;
diff --git a/tools/event-debug.c b/tools/event-debug.c
index acf9d81..f442313 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -252,6 +252,9 @@ print_event_header(struct libinput_event *ev)
 	case LIBINPUT_EVENT_TABLET_BUTTON:
 		type = "TABLET_BUTTON";
 		break;
+	case LIBINPUT_EVENT_TABLET_FRAME:
+		type = "TABLET_FRAME";
+		break;
 	}
 
 	printf("%-7s	%s	", libinput_device_get_sysname(dev), type);
@@ -415,6 +418,15 @@ print_tablet_axis_event(struct libinput_event *ev)
 }
 
 static void
+print_tablet_frame_event(struct libinput_event *ev)
+{
+	struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev);
+
+	print_event_time(libinput_event_tablet_get_time(t));
+	printf("\n");
+}
+
+static void
 print_touch_event_without_coords(struct libinput_event *ev)
 {
 	struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
@@ -552,6 +564,9 @@ handle_and_print_events(struct libinput *li)
 		case LIBINPUT_EVENT_TABLET_BUTTON:
 			print_tablet_button_event(ev);
 			break;
+		case LIBINPUT_EVENT_TABLET_FRAME:
+			print_tablet_frame_event(ev);
+			break;
 		}
 
 		libinput_event_destroy(ev);
diff --git a/tools/event-gui.c b/tools/event-gui.c
index 7bc3828..739183e 100644
--- a/tools/event-gui.c
+++ b/tools/event-gui.c
@@ -379,6 +379,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
 		case LIBINPUT_EVENT_TABLET_PROXIMITY_IN:
 		case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT:
 		case LIBINPUT_EVENT_TABLET_BUTTON:
+		case LIBINPUT_EVENT_TABLET_FRAME:
 			break;
 		}
 
-- 
1.8.5.5



More information about the wayland-devel mailing list