[gtk/gbsneto/shortcuts-rebased: 56/104] treeview: Redo event forwarding hack



commit c70acaa89113a82e0d00c780f17660b2beb29733
Author: Benjamin Otte <otte redhat com>
Date:   Sun Aug 12 21:32:42 2018 +0200

    treeview: Redo event forwarding hack
    
    Reorder the event controllers so that key forwarding to the search
    entries really happens after shortcut triggering.

 gtk/gtktreeview.c | 70 +++++++++++++++++++++++++++----------------------------
 1 file changed, 34 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index f21eb3ad75..ddbb90a389 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -22,7 +22,6 @@
 
 #include "gtkadjustmentprivate.h"
 #include "gtkbox.h"
-#include "gtkbindings.h"
 #include "gtkbuildable.h"
 #include "gtkbutton.h"
 #include "gtkcelllayout.h"
@@ -52,6 +51,7 @@
 #include "gtkrendericonprivate.h"
 #include "gtkscrollable.h"
 #include "gtksettingsprivate.h"
+#include "gtkshortcutcontroller.h"
 #include "gtksnapshot.h"
 #include "gtkstylecontextprivate.h"
 #include "gtktooltip.h"
@@ -596,16 +596,16 @@ static void     gtk_tree_view_size_allocate        (GtkWidget      *widget,
 static void     gtk_tree_view_snapshot             (GtkWidget        *widget,
                                                     GtkSnapshot      *snapshot);
 
+static gboolean gtk_tree_view_forward_controller_key_pressed  (GtkEventControllerKey *key,
+                                                               guint                  keyval,
+                                                               guint                  keycode,
+                                                               GdkModifierType        state,
+                                                               GtkTreeView           *tree_view);
 static gboolean gtk_tree_view_key_controller_key_pressed  (GtkEventControllerKey *key,
                                                            guint                  keyval,
                                                            guint                  keycode,
                                                            GdkModifierType        state,
                                                            GtkTreeView           *tree_view);
-static void     gtk_tree_view_key_controller_key_released (GtkEventControllerKey *key,
-                                                           guint                  keyval,
-                                                           guint                  keycode,
-                                                           GdkModifierType        state,
-                                                           GtkTreeView           *tree_view);
 static void     gtk_tree_view_key_controller_focus_out    (GtkEventControllerKey *key,
                                                            GdkCrossingMode        mode,
                                                            GdkNotifyType          detail,
@@ -1622,6 +1622,7 @@ gtk_tree_view_init (GtkTreeView *tree_view)
   GtkCssNode *widget_node;
   GtkGesture *gesture;
   GtkEventController *controller;
+  GList *list, *controllers;
 
   priv = tree_view->priv = gtk_tree_view_get_instance_private (tree_view);
 
@@ -1689,6 +1690,24 @@ gtk_tree_view_init (GtkTreeView *tree_view)
   gtk_css_node_set_state (priv->header_node, gtk_css_node_get_state (widget_node));
   g_object_unref (priv->header_node);
 
+  controller = gtk_event_controller_key_new ();
+  g_signal_connect (controller, "key-pressed",
+                    G_CALLBACK (gtk_tree_view_forward_controller_key_pressed), tree_view);
+  gtk_widget_add_controller (GTK_WIDGET (tree_view), controller);
+
+  controllers = _gtk_widget_list_controllers (GTK_WIDGET (tree_view), GTK_PHASE_BUBBLE);
+  for (list = controllers; list; list = list->next)
+    {
+      if (GTK_IS_SHORTCUT_CONTROLLER (list->data))
+        {
+          g_object_ref (list->data);
+          gtk_widget_remove_controller (GTK_WIDGET (tree_view), list->data);
+          gtk_widget_add_controller (GTK_WIDGET (tree_view), list->data);
+          break;
+        }
+    }
+  g_list_free (controllers);
+
   priv->multipress_gesture = gtk_gesture_multi_press_new ();
   gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), 0);
   g_signal_connect (priv->multipress_gesture, "pressed",
@@ -1736,8 +1755,6 @@ gtk_tree_view_init (GtkTreeView *tree_view)
   controller = gtk_event_controller_key_new ();
   g_signal_connect (controller, "key-pressed",
                     G_CALLBACK (gtk_tree_view_key_controller_key_pressed), tree_view);
-  g_signal_connect (controller, "key-released",
-                    G_CALLBACK (gtk_tree_view_key_controller_key_released), tree_view);
   g_signal_connect (controller, "focus-out",
                     G_CALLBACK (gtk_tree_view_key_controller_focus_out), tree_view);
   gtk_widget_add_controller (GTK_WIDGET (tree_view), controller);
@@ -5151,7 +5168,6 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key,
 {
   GtkWidget *widget = GTK_WIDGET (tree_view);
   GtkWidget *button;
-  GdkEvent *event;
 
   if (tree_view->priv->rubber_band_status)
     {
@@ -5271,16 +5287,16 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key,
         }
     }
 
-  /* Handle the keybindings. */
-  event = gtk_get_current_event ();
-  if (gtk_bindings_activate_event (G_OBJECT (widget), (GdkEventKey *)event))
-    {
-      g_object_unref (event);
-      return TRUE;
-    }
-
-  g_object_unref (event);
+  return FALSE;
+}
 
+static gboolean
+gtk_tree_view_forward_controller_key_pressed (GtkEventControllerKey *key,
+                                              guint                  keyval,
+                                              guint                  keycode,
+                                              GdkModifierType        state,
+                                              GtkTreeView           *tree_view)
+{
   if (tree_view->priv->search_entry_avoid_unhandled_binding)
     {
       tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
@@ -5347,24 +5363,6 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key,
   return FALSE;
 }
 
-static void
-gtk_tree_view_key_controller_key_released (GtkEventControllerKey *key,
-                                           guint                  keyval,
-                                           guint                  keycode,
-                                           GdkModifierType        state,
-                                           GtkTreeView           *tree_view)
-{
-  GdkEvent *event;
-
-  if (tree_view->priv->rubber_band_status)
-    return;
-
-  /* Handle the keybindings. */
-  event = gtk_get_current_event ();
-  gtk_bindings_activate_event (G_OBJECT (tree_view), (GdkEventKey *)event);
-  g_object_unref (event);
-}
-
 static void
 gtk_tree_view_motion_controller_enter (GtkEventControllerMotion *controller,
                                        double                    x,


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