Expander: Also hide child GdkWindow when collapsed
authorDaniel Boles <dboles@src.gnome.org>
Thu, 24 Aug 2017 20:05:00 +0000 (21:05 +0100)
committerDaniel Boles <dboles@src.gnome.org>
Thu, 24 Aug 2017 20:18:55 +0000 (21:18 +0100)
Just adding/removing to/from the BoxGadget is not sufficient; that
leaves the GdkWindow hanging around, taking input, changing the cursor,
and all sorts of other nefarious shenanigans.

Resolve by ensuring the child’s GdkWindow is unmapped if collapsed.

Note: the reflexive solution is just to set_visible(child, expanded),
but it is best to avoid messing with the child’s :visible property.

https://bugzilla.gnome.org/show_bug.cgi?id=776937

gtk/gtkexpander.c

index ad84d5f3bfdda52fa7d331caa3ff5070c7a0da87..89f7582bdc542b25e8ea5003fd9dba6364bb8acd 100644 (file)
@@ -1088,6 +1088,26 @@ gtk_expander_focus (GtkWidget        *widget,
   return TRUE;
 }
 
+static void
+gtk_expander_update_child_mapped (GtkExpander *expander,
+                                  GtkWidget   *child)
+{
+  /* If collapsing, we must unmap the child, as gtk_box_gadget_remove() does
+   * not, so otherwise the child is not drawn but still consumes input in-place.
+   */
+
+  if (expander->priv->expanded &&
+      gtk_widget_get_realized (child) &&
+      gtk_widget_get_visible (child))
+    {
+      gtk_widget_map (child);
+    }
+  else
+    {
+      gtk_widget_unmap (child);
+    }
+}
+
 static void
 gtk_expander_add (GtkContainer *container,
                   GtkWidget    *widget)
@@ -1100,6 +1120,8 @@ gtk_expander_add (GtkContainer *container,
 
   if (expander->priv->expanded)
     gtk_box_gadget_insert_widget (GTK_BOX_GADGET (expander->priv->gadget), -1, widget);
+
+  gtk_expander_update_child_mapped (expander, widget);
 }
 
 static void
@@ -1274,6 +1296,8 @@ gtk_expander_set_expanded (GtkExpander *expander,
 
       gtk_widget_queue_resize (GTK_WIDGET (expander));
       gtk_expander_resize_toplevel (expander);
+
+      gtk_expander_update_child_mapped (expander, child);
     }
 
   g_object_notify (G_OBJECT (expander), "expanded");