[gtk-demo] gtk_window_set_transient_for() is called after gtk_widget_show(), which sometimes makes WM fails to get the transient property
Steps to reproduce
- Run gtk3-demo/gtk4-demo
- Select any demo item
- Click "Run" button
Current behavior
GTK4 child windows/dialogs often fail to locate in the center of the parent window (which is GTK Demo window) because WM doesn't get the right transient property. (Debug messages from WM have proved that.)
Expected outcome
GTK4 child windows/dialogs should locate in the center of the parent window (which is GTK Demo window).
Version information
GTK 4.2.1 Linux, openSUSE Tumbleweed 20210701
Additional information
I also analyzed the source code of gtk4-demo for your convenience.
-
In main.c, gtk_demo_run() is called when "Run" button is pressed. (https://gitlab.gnome.org/GNOME/gtk/-/blob/master/demos/gtk-demo/main.c#L267)
-
In gtk_demo_run(), "self->func (window)" is called BEFORE gtk_window_set_transient_for() is called which sets the transient property. (https://gitlab.gnome.org/GNOME/gtk/-/blob/master/demos/gtk-demo/main.c#L155)
-
Taking dialog.c as an example, with regard to "self->func (window)", "window" refers to the parent window, and "func" refers to "do_dialog" in dialog.c
-
do_dialog() calls gtk_widget_show(). (https://gitlab.gnome.org/GNOME/gtk/-/blob/master/demos/gtk-demo/dialog.c#L187)
That should explain the race condition. gtk_widget_show() is called before gtk_window_set_transient_for(), and I don't know why it's intended to do that.