[gnome-builder/wip/gtk4-port] libide/gui: be tolerant of focus changes



commit a8fdcfbc90d6d66f4e4005b8a86e967d1d1c38a5
Author: Christian Hergert <chergert redhat com>
Date:   Sat Apr 2 03:23:05 2022 -0700

    libide/gui: be tolerant of focus changes
    
    This allows focus changes without changing the current page so that we
    dont lose menus when trying to use them.

 src/libide/gui/ide-workspace.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 68920df2b..e7c97aeed 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -69,10 +69,7 @@ typedef struct
   /* Vertical box for children */
   GtkBox *box;
 
-  /* Raw pointer to the last IdePage that was focused. This is never
-   * dereferenced and only used to compare to determine if we've changed focus
-   * into a new IdePage that must be propagated to the addins.
-   */
+  /* Weak pointer to the current page. */
   gpointer current_page_ptr;
 } IdeWorkspacePrivate;
 
@@ -266,9 +263,14 @@ ide_workspace_notify_focus_widget (IdeWorkspace *self,
 
   focus = ide_workspace_get_focus_page (self);
 
-  if ((gpointer)focus != priv->current_page_ptr)
+  if (priv->current_page_ptr != (gpointer)focus)
     {
-      priv->current_page_ptr = focus;
+      /* Focus changed, but old page is still valid */
+      if (focus == NULL)
+        IDE_EXIT;
+
+      /* Focus changed, and we have a new widget */
+      g_set_weak_pointer (&priv->current_page_ptr, focus);
 
       if (priv->addins != NULL)
         {
@@ -441,6 +443,8 @@ ide_workspace_dispose (GObject *object)
 
   g_assert (IDE_IS_WORKSPACE (self));
 
+  g_clear_weak_pointer (&priv->current_page_ptr);
+
   /* Unload addins immediately */
   ide_clear_and_destroy_object (&priv->addins);
 


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