ComboBox: Really set list-mode popup transient-for
authorDaniel Boles <dboles@src.gnome.org>
Sun, 27 Aug 2017 23:12:02 +0000 (00:12 +0100)
committerDaniel Boles <dboles@src.gnome.org>
Mon, 28 Aug 2017 19:00:17 +0000 (20:00 +0100)
set_transient_for(toplevel) was only called in list_setup(). It was easy
to make a test showing a NULL :transient-for instead of the correct one.

So, move the call from list_setup() to popup_for_device(). Also do that
for window_group_add_window(), which means not calling it redundantly.

(I tried using a ComboBox:parent-set handler, but the Inspector’s CB
didn’t like that: it calls popup_for_device() twice and closes on button
release. Anyway, using popup() is much more concise than a new handler.)

gtk/gtkcombobox.c

index 743aa49408565603bba64267e8fe69776e4e8c3e..fa1e26c238868590883b110d27eb137f76a5e3b5 100644 (file)
@@ -1855,8 +1855,6 @@ gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
     {
       if (!priv->popup_window)
         {
-          GtkWidget *toplevel;
-
           priv->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
           gtk_widget_set_name (priv->popup_window, "gtk-combobox-popup-window");
 
@@ -1870,15 +1868,6 @@ gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
                             G_CALLBACK (gtk_combo_box_child_hide),
                             combo_box);
 
-          toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
-          if (GTK_IS_WINDOW (toplevel))
-            {
-              gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
-                                           GTK_WINDOW (priv->popup_window));
-              gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
-                                            GTK_WINDOW (toplevel));
-            }
-
           gtk_window_set_resizable (GTK_WINDOW (priv->popup_window), FALSE);
 
           priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
@@ -2335,8 +2324,12 @@ gtk_combo_box_popup_for_device (GtkComboBox *combo_box,
 
   toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo_box));
   if (GTK_IS_WINDOW (toplevel))
-    gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
-                                 GTK_WINDOW (priv->popup_window));
+    {
+      gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
+                                   GTK_WINDOW (priv->popup_window));
+      gtk_window_set_transient_for (GTK_WINDOW (priv->popup_window),
+                                    GTK_WINDOW (toplevel));
+    }
 
   gtk_widget_show_all (priv->scrolled_window);
   gtk_combo_box_list_position (combo_box, &x, &y, &width, &height);