[gtk+] tests: Stop using ::motion-notify-event



commit 81b8f0493a1cc09cbc5386e7f4cb8cb6f13db6e3
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jan 15 23:15:51 2018 -0500

    tests: Stop using ::motion-notify-event
    
    We can use the generic ::event signal here.

 tests/motion-compression.c |   15 +++++++++------
 tests/testpopup.c          |   19 +++++++++++--------
 tests/testwidgetfocus.c    |   17 ++++++++++-------
 3 files changed, 30 insertions(+), 21 deletions(-)
---
diff --git a/tests/motion-compression.c b/tests/motion-compression.c
index 82f949c..81ff7c2 100644
--- a/tests/motion-compression.c
+++ b/tests/motion-compression.c
@@ -4,11 +4,12 @@
 GtkAdjustment *adjustment;
 int cursor_x, cursor_y;
 
-static void
-on_motion_notify (GtkWidget      *window,
-                  GdkEventMotion *event)
+static gboolean
+event_cb (GtkWidget *window,
+          GdkEvent  *event)
 {
-  if (gdk_event_get_window ((GdkEvent*)event) == gtk_widget_get_window (window))
+  if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY &&
+      gdk_event_get_window (event) == gtk_widget_get_window (window))
     {
       gdouble x, y;
       float processing_ms = gtk_adjustment_get_value (adjustment);
@@ -19,6 +20,8 @@ on_motion_notify (GtkWidget      *window,
       cursor_y = y;
       gtk_widget_queue_draw (window);
     }
+
+  return GDK_EVENT_PROPAGATE;
 }
 
 static void
@@ -67,8 +70,8 @@ main (int argc, char **argv)
   gtk_widget_set_vexpand (da, TRUE);
   gtk_box_pack_end (GTK_BOX (vbox), da);
   
-  g_signal_connect (window, "motion-notify-event",
-                    G_CALLBACK (on_motion_notify), NULL);
+  g_signal_connect (window, "event",
+                    G_CALLBACK (event_cb), NULL);
   g_signal_connect (window, "destroy",
                     G_CALLBACK (gtk_main_quit), NULL);
 
diff --git a/tests/testpopup.c b/tests/testpopup.c
index 0e564ef..504c67d 100644
--- a/tests/testpopup.c
+++ b/tests/testpopup.c
@@ -19,13 +19,16 @@ place_popup (GtkWidget *parent,
   gint width, height;
   gdouble x, y;
 
-  gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
-  gdk_event_get_root_coords (event, &x, &y);
-  gtk_window_move (GTK_WINDOW (popup),
-                   (int) x - width / 2,
-                   (int) y - height / 2);
-
-  return FALSE;
+  if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
+    {
+      gtk_window_get_size (GTK_WINDOW (popup), &width, &height);
+      gdk_event_get_root_coords (event, &x, &y);
+      gtk_window_move (GTK_WINDOW (popup),
+                       (int) x - width / 2,
+                       (int) y - height / 2);
+    }
+
+  return GDK_EVENT_PROPAGATE;
 }
 
 static gboolean
@@ -40,7 +43,7 @@ on_map (GtkWidget *parent)
 
   gtk_widget_set_size_request (GTK_WIDGET (popup), 20, 20);
   gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
-  g_signal_connect (parent, "motion-notify-event", G_CALLBACK (place_popup), popup);
+  g_signal_connect (parent, "event", G_CALLBACK (place_popup), popup);
 
   gtk_widget_show (popup);
 
diff --git a/tests/testwidgetfocus.c b/tests/testwidgetfocus.c
index c527abf..2366e7c 100644
--- a/tests/testwidgetfocus.c
+++ b/tests/testwidgetfocus.c
@@ -203,18 +203,21 @@ gtk_focus_widget_snapshot (GtkWidget *widget, GtkSnapshot *snapshot)
 }
 
 static gboolean
-gtk_focus_widget_motion_notify_event (GtkWidget *widget,
-                                      GdkEventMotion *event)
+gtk_focus_widget_event (GtkWidget *widget,
+                        GdkEvent  *event)
 {
   GtkFocusWidget *self = GTK_FOCUS_WIDGET (widget);
   gdouble x, y;
 
-  gdk_event_get_coords ((GdkEvent *)event, &x, &y);
+  if (gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
+    {
+      gdk_event_get_coords ((GdkEvent *)event, &x, &y);
 
-  self->mouse_x = x;
-  self->mouse_y = y;
+      self->mouse_x = x;
+      self->mouse_y = y;
 
-  gtk_widget_queue_draw (widget);
+      gtk_widget_queue_draw (widget);
+    }
 
   return GDK_EVENT_PROPAGATE;
 }
@@ -261,7 +264,7 @@ gtk_focus_widget_class_init (GtkFocusWidgetClass *klass)
   widget_class->snapshot = gtk_focus_widget_snapshot;
   widget_class->measure = gtk_focus_widget_measure;
   widget_class->size_allocate = gtk_focus_widget_size_allocate;
-  widget_class->motion_notify_event = gtk_focus_widget_motion_notify_event;
+  widget_class->event = gtk_focus_widget_event;
 
   gtk_widget_class_set_css_name (widget_class, "focuswidget");
 }


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