summaryrefslogtreecommitdiff
path: root/demos/gtk-demo/hypertext.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-06-09 22:29:26 -0400
committerMatthias Clasen <mclasen@redhat.com>2015-06-09 23:31:00 -0400
commit06726b4d4bbc3031158e484f4089c236fdbaffaa (patch)
tree581c7447b253750669e795baf60ae227846e69b7 /demos/gtk-demo/hypertext.c
parent85635457bc2204783a6a7b27435774aa5a93df35 (diff)
downloadgtk+-06726b4d4bbc3031158e484f4089c236fdbaffaa.tar.gz
gtk-demo: Make hypertext demo work with touch
Make tapping on the links work.
Diffstat (limited to 'demos/gtk-demo/hypertext.c')
-rw-r--r--demos/gtk-demo/hypertext.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/demos/gtk-demo/hypertext.c b/demos/gtk-demo/hypertext.c
index 28a7522319..7b541ea9dc 100644
--- a/demos/gtk-demo/hypertext.c
+++ b/demos/gtk-demo/hypertext.c
@@ -128,7 +128,7 @@ key_press_event (GtkWidget *text_view,
return FALSE;
}
-/* Links can also be activated by clicking.
+/* Links can also be activated by clicking or tapping.
*/
static gboolean
event_after (GtkWidget *text_view,
@@ -136,15 +136,30 @@ event_after (GtkWidget *text_view,
{
GtkTextIter start, end, iter;
GtkTextBuffer *buffer;
- GdkEventButton *event;
+ gdouble ex, ey;
gint x, y;
- if (ev->type != GDK_BUTTON_RELEASE)
- return FALSE;
+ if (ev->type == GDK_BUTTON_RELEASE)
+ {
+ GdkEventButton *event;
+
+ event = (GdkEventButton *)ev;
+ if (event->button != GDK_BUTTON_PRIMARY)
+ return FALSE;
+
+ ex = event->x;
+ ey = event->y;
+ }
+ else if (ev->type == GDK_TOUCH_END)
+ {
+ GdkEventTouch *event;
- event = (GdkEventButton *)ev;
+ event = (GdkEventTouch *)ev;
- if (event->button != GDK_BUTTON_PRIMARY)
+ ex = event->x;
+ ey = event->y;
+ }
+ else
return FALSE;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
@@ -156,13 +171,13 @@ event_after (GtkWidget *text_view,
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
GTK_TEXT_WINDOW_WIDGET,
- event->x, event->y, &x, &y);
+ ex, ey, &x, &y);
gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y);
follow_if_link (text_view, &iter);
- return FALSE;
+ return TRUE;
}
static gboolean hovering_over_link = FALSE;