[PATCH libinput 04/23] Add the libinput_tool object
Stephen Chandler Paul
thatslyude at gmail.com
Thu Jun 12 20:28:25 PDT 2014
This will be used to represent a tool in use on a drawing tablet.
Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/libinput-private.h | 7 +++++
src/libinput.c | 29 ++++++++++++++++++++
src/libinput.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 109 insertions(+)
diff --git a/src/libinput-private.h b/src/libinput-private.h
index f6ba51c..83906f5 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -85,6 +85,13 @@ struct libinput_device {
int refcount;
};
+struct libinput_tool {
+ struct list link;
+ uint32_t serial;
+ enum libinput_tool_type type;
+ int refcount;
+};
+
typedef void (*libinput_source_dispatch_t)(void *data);
diff --git a/src/libinput.c b/src/libinput.c
index fee500e..def3e91 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -514,6 +514,35 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event)
return event->time;
}
+LIBINPUT_EXPORT enum libinput_tool_type
+libinput_tool_get_type(struct libinput_tool *tool)
+{
+ return tool->type;
+}
+
+LIBINPUT_EXPORT uint32_t
+libinput_tool_get_serial(struct libinput_tool *tool)
+{
+ return tool->serial;
+}
+
+LIBINPUT_EXPORT void
+libinput_tool_ref(struct libinput_tool *tool)
+{
+ tool->refcount++;
+}
+
+LIBINPUT_EXPORT void
+libinput_tool_unref(struct libinput_tool *tool)
+{
+ assert(tool->refcount > 0);
+
+ if (--tool->refcount == 0) {
+ list_remove(&tool->link);
+ free(tool);
+ }
+}
+
struct libinput_source *
libinput_add_fd(struct libinput *libinput,
int fd,
diff --git a/src/libinput.h b/src/libinput.h
index 18bb726..c0c9fae 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -183,6 +183,32 @@ enum libinput_tablet_axis {
};
/**
+ * @ingroup device
+ *
+ * An object representing a tool being used by the device. It must have the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET capability.
+ */
+struct libinput_tool;
+
+/**
+ * @ingroup device
+ *
+ * Available tool types for a device. It must have the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET capability.
+ */
+enum libinput_tool_type {
+ LIBINPUT_TOOL_NONE = -1,
+ LIBINPUT_TOOL_PEN = 0x140, /* Matches BTN_TOOL_PEN */
+ LIBINPUT_TOOL_ERASER,
+ LIBINPUT_TOOL_BRUSH,
+ LIBINPUT_TOOL_PENCIL,
+ LIBINPUT_TOOL_AIRBRUSH,
+ LIBINPUT_TOOL_FINGER,
+ LIBINPUT_TOOL_MOUSE,
+ LIBINPUT_TOOL_LENS
+};
+
+/**
* @ingroup base
*
* Event type for events returned by libinput_get_event().
@@ -875,6 +901,53 @@ uint32_t
libinput_event_tablet_get_time(struct libinput_event_tablet *event);
/**
+ * @ingroup event_tablet
+ *
+ * Return the type of tool type for a tool object
+ *
+ * @param tool The libinput tool
+ * @return The tool type for this tool object
+ */
+enum libinput_tool_type
+libinput_tool_get_type(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Increment the ref count of tool by one
+ *
+ * @param tool The tool to increment the ref count of
+ */
+void
+libinput_tool_ref(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Decrement the ref count of tool by one. When the ref count of tool reaches 0,
+ * the memory allocated for tool will be freed.
+ *
+ * @param tool The tool to decrement the ref count of
+ */
+void
+libinput_tool_unref(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the serial number of a tool
+ *
+ * @note Not all tablets report a serial number along with the type of tool
+ * being used. If the hardware does not provide a unique serial number, the
+ * serial number is always 0.
+ *
+ * @param tool The libinput tool
+ * @return The new tool serial triggering this event
+ */
+uint32_t
+libinput_tool_get_serial(struct libinput_tool *tool);
+
+/**
* @defgroup base Initialization and manipulation of libinput contexts
*/
--
1.8.5.5
More information about the wayland-devel
mailing list