Incorrect behavior of GTK_WINDOW_POPUP in full screen on macOS
The following problem appears when using the latest GTK 3.24 from git on macOS and when running the created binary inside a macOS app bundle (it doesn't happen when running the binary from the command-line, apparently macOS does something differently for a bundle).
When a popup is created using gtk_window_new(GTK_WINDOW_POPUP)
and the application is in the full screen mode, the created popup also becomes full screen and opened in a separate workspace as if it were an ordinary window and not a popup. This for instance happens with the following Geany binaries
https://download.geany.org/snapshots/geany-1.38_osx.dmg
https://download.geany.org/snapshots/geany-1.38_osx_arm64.dmg
where the Scintilla component uses gtk_window_new(GTK_WINDOW_POPUP)
to create autocompletion popups - this basically makes the application unusable in full screen.
This problem has some history - it used to be broken, it got fixed at some later point (I haven't been able to bisect it to the point where it got fixed on macOS 13 because older GTK versions are quite broken on it) and then broken again - I bisected it to this commit that broke it
I have been able to create a simple reproducer below. To reproduce this issue:
- Compile the code below.
- Create a bundle using https://gitlab.gnome.org/GNOME/gtk-mac-bundler. One can use the bundle description from the examples directory and just point it to the generated binary.
- Launch the bundle and maximize the window using the green button in the title bar so it becomes full screen.
- Click the button to create the popup - the popup becomes another full screen window opened in a separate workspace and the whole application gets to a very strange state where it's hard to even close it normally. Compare this with the expected behavior when you run the binary from the command-line where it just creates the popup in the center of the main window.
#include <gtk/gtk.h>
// gcc `pkg-config --cflags gtk+-3.0` demo.c -o demo `pkg-config --libs gtk+-3.0`
static GtkWidget *popup;
gint CloseAppWindow (GtkWidget *widget, gpointer *data)
{
gtk_main_quit();
return FALSE;
}
void button_event (GtkWidget *widget, gpointer *data)
{
popup = gtk_window_new(GTK_WINDOW_POPUP);
gtk_window_set_position(GTK_WINDOW(popup), GTK_WIN_POS_CENTER_ALWAYS);
gtk_widget_show(popup);
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *frame;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Fullscreen problem");
g_signal_connect(window, "delete_event", G_CALLBACK (CloseAppWindow), NULL);
button = gtk_button_new_with_label ("Create popup");
g_signal_connect(button, "clicked", G_CALLBACK (button_event), NULL);
frame = gtk_frame_new(NULL);
gtk_container_set_border_width(GTK_CONTAINER(frame), 50);
gtk_container_add(GTK_CONTAINER(frame), button);
gtk_container_add(GTK_CONTAINER(window), frame);
gtk_widget_show_all(window);
gtk_main ();
return 0;
}