[gtk/wip/matthiasc/focus3: 24/32] Move maintaining the focus chain



commit 228b1639e77f6f6a862400e75eb9504237c7c43c
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Mar 8 13:52:46 2019 -0500

    Move maintaining the focus chain
    
    Put this code in the same place where we generate
    the crossing events.

 gtk/gtkmain.c   | 15 +++++++++++++++
 gtk/gtkwindow.c |  8 --------
 2 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index e3c8b930cc..92873dee1e 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1458,6 +1458,21 @@ synth_crossing (GtkWidget       *widget,
 
   if (gdk_event_get_event_type (source) == GDK_FOCUS_CHANGE)
     {
+      /* maintain focus chain */
+      if (enter || notify_type == GDK_NOTIFY_INFERIOR)
+        {
+          GtkWidget *parent = gtk_widget_get_parent (widget);
+          if (parent)
+            gtk_widget_set_focus_child (parent, widget);
+        }
+      else if (!enter && notify_type != GDK_NOTIFY_INFERIOR)
+        {
+          GtkWidget *parent = gtk_widget_get_parent (widget);
+          if (parent)
+            gtk_widget_set_focus_child (parent, NULL);
+        }
+
+      /* maintain widget state */
       if (notify_type == GDK_NOTIFY_ANCESTOR ||
           notify_type == GDK_NOTIFY_INFERIOR ||
           notify_type == GDK_NOTIFY_NONLINEAR)
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 85a965c169..976777717d 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -7168,7 +7168,6 @@ gtk_window_set_focus (GtkWindow *window,
 {
   GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
   GtkWidget *old_focus = NULL;
-  GtkWidget *f;
   GdkSeat *seat;
   GdkDevice *device;
   GdkEvent *event;
@@ -7200,13 +7199,6 @@ gtk_window_set_focus (GtkWindow *window,
 
   g_clear_object (&old_focus);
 
-  for (f = focus; f; f = gtk_widget_get_parent (f))
-    {
-      GtkWidget *parent = gtk_widget_get_parent (f);
-      if (parent)
-        gtk_widget_set_focus_child (parent, f);
-    }
-
   g_object_notify (G_OBJECT (window), "focus-widget");
 }
 


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