[gtk+/wip/matthiasc/kill-event-signals: 49/58] menuitem: Use a motion event controller



commit be492a3f69b86bfe807bcb2771df9fafc70fe67c
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 2 11:07:56 2018 -0500

    menuitem: Use a motion event controller
    
    This lets us replace the ::enter/leave-notify-event handlers.
    Not that there is a FIXME here - we currently can't get the
    crossing mode from the event controller, so we have to fall
    back to gtk_get_current_event().

 gtk/gtkmenuitem.c        |   53 ++++++++++++++++++++++++++--------------------
 gtk/gtkmenuitemprivate.h |    2 +
 2 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index 4b5ce12..fdfe259 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -136,10 +136,12 @@ static void gtk_menu_item_get_property   (GObject          *object,
                                           GValue           *value,
                                           GParamSpec       *pspec);
 static void gtk_menu_item_destroy        (GtkWidget        *widget);
-static gboolean gtk_menu_item_enter      (GtkWidget        *widget,
-                                          GdkEventCrossing *event);
-static gboolean gtk_menu_item_leave      (GtkWidget        *widget,
-                                          GdkEventCrossing *event);
+static void gtk_menu_item_enter          (GtkEventController *controller,
+                                          double              x,
+                                          double              y,
+                                          gpointer            user_data);
+static void gtk_menu_item_leave          (GtkEventController *controller,
+                                          gpointer            user_data);
 static void gtk_menu_item_parent_cb      (GObject          *object,
                                           GParamSpec       *pspec,
                                           gpointer          user_data);
@@ -508,8 +510,6 @@ gtk_menu_item_class_init (GtkMenuItemClass *klass)
 
   widget_class->destroy = gtk_menu_item_destroy;
   widget_class->size_allocate = gtk_menu_item_size_allocate;
-  widget_class->enter_notify_event = gtk_menu_item_enter;
-  widget_class->leave_notify_event = gtk_menu_item_leave;
   widget_class->mnemonic_activate = gtk_menu_item_mnemonic_activate;
   widget_class->can_activate_accel = gtk_menu_item_can_activate_accel;
   widget_class->measure = gtk_menu_item_measure;
@@ -689,6 +689,10 @@ gtk_menu_item_init (GtkMenuItem *menu_item)
     priv->submenu_direction = GTK_DIRECTION_RIGHT;
   priv->submenu_placement = GTK_TOP_BOTTOM;
   priv->timer = 0;
+
+  priv->motion_controller = gtk_event_controller_motion_new (GTK_WIDGET (menu_item));
+  g_signal_connect (priv->motion_controller, "enter", G_CALLBACK (gtk_menu_item_enter), menu_item);
+  g_signal_connect (priv->motion_controller, "leave", G_CALLBACK (gtk_menu_item_leave), menu_item);
 }
 
 /**
@@ -748,6 +752,7 @@ gtk_menu_item_dispose (GObject *object)
   GtkMenuItem *menu_item = GTK_MENU_ITEM (object);
   GtkMenuItemPrivate *priv = menu_item->priv;
 
+  g_clear_object (&priv->motion_controller);
   g_clear_object (&priv->action_helper);
 
   if (priv->arrow_widget)
@@ -1126,44 +1131,46 @@ gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item,
   g_signal_emit (menu_item, menu_item_signals[TOGGLE_SIZE_ALLOCATE], 0, allocation);
 }
 
-static gboolean
-gtk_menu_item_enter (GtkWidget        *widget,
-                     GdkEventCrossing *event)
+static void
+gtk_menu_item_enter (GtkEventController *controller,
+                     double              x,
+                     double              y,
+                     gpointer            user_data)
 {
+  GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
   GtkWidget *menu_shell;
   GdkCrossingMode mode;
+  GdkEvent *event;
+
+  event = gtk_get_current_event (); /* FIXME controller event */
 
   gdk_event_get_crossing_mode ((GdkEvent *)event, &mode);
 
   if (mode == GDK_CROSSING_GTK_GRAB ||
       mode == GDK_CROSSING_GTK_UNGRAB ||
       mode == GDK_CROSSING_STATE_CHANGED)
-    return GDK_EVENT_STOP;
+    return;
 
   if (gdk_event_get_device ((GdkEvent*) event) ==
       gdk_event_get_source_device ((GdkEvent*) event))
-    return GDK_EVENT_STOP;
+    return;
 
-  menu_shell = gtk_widget_get_parent (widget);
+  menu_shell = gtk_widget_get_parent (GTK_WIDGET (menu_item));
 
-  if (GTK_IS_MENU_SHELL (menu_shell) && GTK_IS_MENU_ITEM (widget) &&
+  if (GTK_IS_MENU_SHELL (menu_shell) &&
       GTK_MENU_SHELL (menu_shell)->priv->active)
-    gtk_menu_shell_select_item (GTK_MENU_SHELL (menu_shell), widget);
-
-  return GDK_EVENT_STOP;
+    gtk_menu_shell_select_item (GTK_MENU_SHELL (menu_shell), GTK_WIDGET (menu_item));
 }
 
-static gboolean
-gtk_menu_item_leave (GtkWidget        *widget,
-                     GdkEventCrossing *event)
+static void
+gtk_menu_item_leave (GtkEventController *controller,
+                     gpointer            user_data)
 {
-  GtkMenuItem *menu_item = GTK_MENU_ITEM (widget);
-  GtkWidget *menu_shell = gtk_widget_get_parent (widget);
+  GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
+  GtkWidget *menu_shell = gtk_widget_get_parent (GTK_WIDGET (menu_item));
 
   if (GTK_IS_MENU_SHELL (menu_shell) && !menu_item->priv->submenu)
     gtk_menu_shell_deselect (GTK_MENU_SHELL (menu_shell));
-
-  return GDK_EVENT_STOP;
 }
 
 static void
diff --git a/gtk/gtkmenuitemprivate.h b/gtk/gtkmenuitemprivate.h
index dc10bca..73b943f 100644
--- a/gtk/gtkmenuitemprivate.h
+++ b/gtk/gtkmenuitemprivate.h
@@ -21,6 +21,7 @@
 #include <gtk/gtkmenuitem.h>
 #include <gtk/gtkactionhelper.h>
 #include <gtk/gtkcssnodeprivate.h>
+#include <gtk/gtkeventcontrollermotion.h>
 
 G_BEGIN_DECLS
 
@@ -38,6 +39,7 @@ struct _GtkMenuItemPrivate
   GtkActionHelper *action_helper;
 
   GtkWidget *arrow_widget;
+  GtkEventController *motion_controller;
 
   guint submenu_placement      : 1;
   guint submenu_direction      : 1;


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