[gtk+] gtk-demo: Stop using ::motion-notify-event in the hypertext demo



commit 4d31a89ec02c408a5702d0b1db8f7c15ce3f7e15
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jan 15 23:24:50 2018 -0500

    gtk-demo: Stop using ::motion-notify-event in the hypertext demo
    
    We already have a generic ::event handler, just use it for this.

 demos/gtk-demo/hypertext.c |   47 +++++++++++++++----------------------------
 1 files changed, 17 insertions(+), 30 deletions(-)
---
diff --git a/demos/gtk-demo/hypertext.c b/demos/gtk-demo/hypertext.c
index 0cbaf35..bf06118 100644
--- a/demos/gtk-demo/hypertext.c
+++ b/demos/gtk-demo/hypertext.c
@@ -131,11 +131,15 @@ key_press_event (GtkWidget *text_view,
   return FALSE;
 }
 
+static void set_cursor_if_appropriate (GtkTextView *text_view,
+                                       gint         x,
+                                       gint         y);
+
 /* Links can also be activated by clicking or tapping.
  */
 static gboolean
-event_after (GtkWidget *text_view,
-             GdkEvent  *ev)
+event_cb (GtkWidget *text_view,
+          GdkEvent  *ev)
 {
   GtkTextIter start, end, iter;
   GtkTextBuffer *buffer;
@@ -145,6 +149,11 @@ event_after (GtkWidget *text_view,
 
   type = gdk_event_get_event_type (ev);
 
+  gdk_event_get_coords (ev, &ex, &ey);
+  gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
+                                         GTK_TEXT_WINDOW_WIDGET,
+                                         ex, ey, &x, &y);
+
   if (type == GDK_BUTTON_RELEASE)
     {
       guint button;
@@ -153,14 +162,17 @@ event_after (GtkWidget *text_view,
       if (button != GDK_BUTTON_PRIMARY)
         return FALSE;
     }
+  else if (type == GDK_MOTION_NOTIFY)
+    {
+      set_cursor_if_appropriate (GTK_TEXT_VIEW (text_view), x, y);
+      return FALSE;
+    }
   else if (type == GDK_TOUCH_END)
     {
     }
   else
     return FALSE;
 
-  gdk_event_get_coords (ev, &ex, &ey);
-
   buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
 
   /* we shouldn't follow a link if the user has selected something */
@@ -168,10 +180,6 @@ event_after (GtkWidget *text_view,
   if (gtk_text_iter_get_offset (&start) != gtk_text_iter_get_offset (&end))
     return FALSE;
 
-  gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
-                                         GTK_TEXT_WINDOW_WIDGET,
-                                         ex, ey, &x, &y);
-
   if (gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (text_view), &iter, x, y))
     follow_if_link (text_view, &iter);
 
@@ -223,25 +231,6 @@ set_cursor_if_appropriate (GtkTextView    *text_view,
     g_slist_free (tags);
 }
 
-/* Update the cursor image if the pointer moved.
- */
-static gboolean
-motion_notify_event (GtkWidget      *text_view,
-                     GdkEventMotion *event)
-{
-  gdouble ex, ey;
-  gint x, y;
-
-  gdk_event_get_coords ((GdkEvent *)event, &ex, &ey);
-  gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (text_view),
-                                         GTK_TEXT_WINDOW_WIDGET,
-                                         ex, ey, &x, &y);
-
-  set_cursor_if_appropriate (GTK_TEXT_VIEW (text_view), x, y);
-
-  return FALSE;
-}
-
 GtkWidget *
 do_hypertext (GtkWidget *do_widget)
 {
@@ -269,9 +258,7 @@ do_hypertext (GtkWidget *do_widget)
       g_signal_connect (view, "key-press-event",
                         G_CALLBACK (key_press_event), NULL);
       g_signal_connect (view, "event",
-                        G_CALLBACK (event_after), NULL);
-      g_signal_connect (view, "motion-notify-event",
-                        G_CALLBACK (motion_notify_event), NULL);
+                        G_CALLBACK (event_cb), NULL);
 
       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]