[gnome-builder] focus: use traditional grabs to handle refocusing



commit ba9e94f6b9c0c140aa70cf6f15518607d4215d54
Author: Christian Hergert <christian hergert me>
Date:   Mon Apr 13 19:28:32 2015 -0700

    focus: use traditional grabs to handle refocusing
    
    This was mostly for handling out-focus of the search bar. This doesn't
    mess with focus issues quite as much as "set_focus" with a NULL child.

 src/search/gb-search-box.c   |    6 +---
 src/workbench/gb-workbench.c |   60 ++++++-----------------------------------
 2 files changed, 10 insertions(+), 56 deletions(-)
---
diff --git a/src/search/gb-search-box.c b/src/search/gb-search-box.c
index aecfa8f..77b39b1 100644
--- a/src/search/gb-search-box.c
+++ b/src/search/gb-search-box.c
@@ -196,12 +196,8 @@ gb_search_box_entry_key_press_event (GbSearchBox    *self,
     {
     case GDK_KEY_Escape:
       {
-        GtkWidget *toplevel;
-
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->button), FALSE);
-
-        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (entry));
-        gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
+        gtk_widget_grab_focus (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
 
         return GDK_EVENT_STOP;
       }
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 639381e..9960608 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -252,64 +252,24 @@ gb_workbench_drag_data_received (GtkWidget        *widget,
 }
 
 static void
-gb_workbench_realize (GtkWidget *widget)
+gb_workbench_grab_focus (GtkWidget *widget)
 {
   GbWorkbench *self = (GbWorkbench *)widget;
 
-  if (GTK_WIDGET_CLASS (gb_workbench_parent_class)->realize)
-    GTK_WIDGET_CLASS (gb_workbench_parent_class)->realize (widget);
-
-  gtk_widget_grab_focus (GTK_WIDGET (self->editor_workspace));
-}
-
-static gboolean
-update_focus (gpointer data)
-{
-  g_autoptr(GbWorkbench) self = data;
-
   g_assert (GB_IS_WORKBENCH (self));
 
-  if (gtk_widget_get_visible (GTK_WIDGET (self)))
-    {
-      GtkWidget *focus;
-
-      if ((focus = gtk_window_get_focus (GTK_WINDOW (self))))
-        {
-          GbWorkspace *workspace;
-
-          if ((workspace = gb_workbench_get_active_workspace (self)))
-            gtk_widget_grab_focus (GTK_WIDGET (workspace));
-        }
-    }
-
-  return G_SOURCE_REMOVE;
+  gtk_widget_grab_focus (GTK_WIDGET (self->editor_workspace));
 }
 
 static void
-gb_workbench_set_focus (GtkWindow *window,
-                        GtkWidget *widget)
+gb_workbench_realize (GtkWidget *widget)
 {
-  GbWorkbench *self = (GbWorkbench *)window;
-
-  g_return_if_fail (GB_IS_WORKBENCH (self));
-
-  /*
-   * The goal here is to focus the current workspace if we are trying to
-   * clear the workbench focus (from something like the global search).
-   */
+  GbWorkbench *self = (GbWorkbench *)widget;
 
-  GTK_WINDOW_CLASS (gb_workbench_parent_class)->set_focus (window, widget);
+  if (GTK_WIDGET_CLASS (gb_workbench_parent_class)->realize)
+    GTK_WIDGET_CLASS (gb_workbench_parent_class)->realize (widget);
 
-  if (!widget && !self->disposing)
-    {
-      /*
-       * We may go through a series of focus updates, so we cannot simply
-       * focus the current workspace here. So instead, we will queue the
-       * refocus to an idle handler so that we can check if the focus is
-       * still NULL after the series of events has settled.
-       */
-      g_idle_add (update_focus, g_object_ref (self));
-    }
+  gtk_widget_grab_focus (GTK_WIDGET (self->editor_workspace));
 }
 
 static void
@@ -433,7 +393,6 @@ gb_workbench_class_init (GbWorkbenchClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  GtkWindowClass *window_class = GTK_WINDOW_CLASS (klass);
 
   object_class->constructed = gb_workbench_constructed;
   object_class->dispose = gb_workbench_dispose;
@@ -441,12 +400,11 @@ gb_workbench_class_init (GbWorkbenchClass *klass)
   object_class->get_property = gb_workbench_get_property;
   object_class->set_property = gb_workbench_set_property;
 
+  widget_class->delete_event = gb_workbench_delete_event;
   widget_class->drag_data_received = gb_workbench_drag_data_received;
   widget_class->draw = gb_workbench_draw;
+  widget_class->grab_focus = gb_workbench_grab_focus;
   widget_class->realize = gb_workbench_realize;
-  widget_class->delete_event = gb_workbench_delete_event;
-
-  window_class->set_focus = gb_workbench_set_focus;
 
   gParamSpecs [PROP_ACTIVE_WORKSPACE] =
     g_param_spec_object ("active-workspace",


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