diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2016-04-05 14:33:29 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2016-04-06 16:12:13 +0200 |
commit | 48239ad72092a8115999872ed77b917f75e08bb8 (patch) | |
tree | 3f0d9443de82ad4531cdc77288b58b8d9ee0d64d /demos | |
parent | cd1604ae1c6a2c4fd8250cc10b460ef5aa8a6a8e (diff) | |
download | gtk+-48239ad72092a8115999872ed77b917f75e08bb8.tar.gz |
gtk3-demo: Add tool information to "Event axes" demo
Print tool type and serial, if found.
Diffstat (limited to 'demos')
-rw-r--r-- | 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 ea8ed67a1f..9ec163bb6d 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; @@ -93,12 +94,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) @@ -136,6 +139,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; + g_clear_pointer (&info->axes, g_free); if (event->type == GDK_TOUCH_BEGIN || @@ -297,6 +303,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, @@ -318,6 +349,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); |