[gtk/wip/matthiasc/focus2: 24/32] Protect against focus cycles



commit d946c0f3532c1410abb3a08b5d87bc8e1182cb51
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 3 02:52:57 2019 -0500

    Protect against focus cycles
    
    Now that next_focus_child wraps around for windows,
    GtkMenus cause an infinite lookp in next_Focus_child.
    Prevent that.

 gtk/gtkwidgetfocus.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkwidgetfocus.c b/gtk/gtkwidgetfocus.c
index 2be4f75369..691275d701 100644
--- a/gtk/gtkwidgetfocus.c
+++ b/gtk/gtkwidgetfocus.c
@@ -465,6 +465,9 @@ gtk_widget_get_next_focus (GtkWidget        *widget,
 {
   GtkWidget *prev;
   GtkWidget *next;
+  GHashTable *seen;
+
+  seen = g_hash_table_new (g_direct_hash, g_direct_equal);
 
   prev = NULL;
   do {
@@ -476,16 +479,23 @@ gtk_widget_get_next_focus (GtkWidget        *widget,
       }
     else if (gtk_widget_get_can_focus (next))
       {
-        return next;
+        break;
+      }
+    else if (g_hash_table_contains (seen, next))
+      {
+        next = NULL;
+        break;
       }
     else
       {
+        g_hash_table_add (seen, next);
         widget = next;
         prev = NULL;
       }
   } while (widget);
 
-  return NULL;
+  g_hash_table_unref (seen);
+  return next;
 }
 
 GtkWidget *


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