[gtk+/wip/wayland-tablet: 60/60] gtk3-demo: Add tool information to "Event axes" demo
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/wayland-tablet: 60/60] gtk3-demo: Add tool information to "Event axes" demo
- Date: Tue, 5 Apr 2016 12:49:36 +0000 (UTC)
commit f71c85b163882033e9f660ea8fcae152992cd948
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Apr 5 14:33:29 2016 +0200
gtk3-demo: Add tool information to "Event axes" demo
Print tool type and serial, if found.
demos/gtk-demo/event_axes.c | 44 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/demos/gtk-demo/event_axes.c b/demos/gtk-demo/event_axes.c
index 39f0f24..ba2a631 100644
--- a/demos/gtk-demo/event_axes.c
+++ b/demos/gtk-demo/event_axes.c
@@ -24,6 +24,7 @@
typedef struct {
GdkDevice *last_source;
+ GdkDeviceTool *last_tool;
gdouble *axes;
GdkRGBA color;
gdouble x;
@@ -99,12 +100,14 @@ update_axes_from_event (GdkEvent *event,
{
GdkDevice *device, *source_device;
GdkEventSequence *sequence;
+ GdkDeviceTool *tool;
gdouble x, y;
AxesInfo *info;
device = gdk_event_get_device (event);
source_device = gdk_event_get_source_device (event);
sequence = gdk_event_get_event_sequence (event);
+ tool = gdk_event_get_device_tool (event);
if (event->type == GDK_TOUCH_END ||
event->type == GDK_TOUCH_CANCEL)
@@ -142,6 +145,9 @@ update_axes_from_event (GdkEvent *event,
if (info->last_source != source_device)
info->last_source = source_device;
+ if (info->last_tool != tool)
+ info->last_tool = tool;
+
if (event->type == GDK_TOUCH_BEGIN ||
event->type == GDK_TOUCH_UPDATE ||
event->type == GDK_MOTION_NOTIFY ||
@@ -292,6 +298,31 @@ draw_axes_info (cairo_t *cr,
cairo_restore (cr);
}
+static const gchar *
+tool_type_to_string (GdkDeviceToolType tool_type)
+{
+ switch (tool_type)
+ {
+ case GDK_DEVICE_TOOL_TYPE_PEN:
+ return "Pen";
+ case GDK_DEVICE_TOOL_TYPE_ERASER:
+ return "Eraser";
+ case GDK_DEVICE_TOOL_TYPE_BRUSH:
+ return "Brush";
+ case GDK_DEVICE_TOOL_TYPE_PENCIL:
+ return "Pencil";
+ case GDK_DEVICE_TOOL_TYPE_AIRBRUSH:
+ return "Airbrush";
+ case GDK_DEVICE_TOOL_TYPE_MOUSE:
+ return "Mouse";
+ case GDK_DEVICE_TOOL_TYPE_LENS:
+ return "Lens cursor";
+ case GDK_DEVICE_TOOL_TYPE_UNKNOWN:
+ default:
+ return "Unknown";
+ }
+}
+
static void
draw_device_info (GtkWidget *widget,
cairo_t *cr,
@@ -313,6 +344,19 @@ draw_device_info (GtkWidget *widget,
g_string_append_printf (string, "\nSequence: %d",
GPOINTER_TO_UINT (sequence));
+ if (info->last_tool)
+ {
+ const gchar *tool_type;
+ guint64 serial;
+
+ tool_type = tool_type_to_string (gdk_device_tool_get_tool_type (info->last_tool));
+ serial = gdk_device_tool_get_serial (info->last_tool);
+ g_string_append_printf (string, "\nTool: %s", tool_type);
+
+ if (serial != 0)
+ g_string_append_printf (string, ", Serial: %lx", serial);
+ }
+
cairo_move_to (cr, 10, *y);
layout = gtk_widget_create_pango_layout (widget, string->str);
pango_cairo_show_layout (cr, layout);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]