Window with transparent background isn't cleared when its last widget is removed
Steps to reproduce
- Create a window with a transparent background, making sure to disable decorations, and put some widgets in it.
- Remove all of the widgets (after they've been rendered).
A simple test program
This code puts some buttons in a vertical box, which are removed from the box when clicked. The last button will stay visible after it's clicked (still highlighted, even if the mouse is released / moved away). Sorry if I messed up the memory management or something, I don't typically use GTK from C.#include <gtk/gtk.h>
static void remove_from_box(GtkWidget *button, GtkBox *box) {
gtk_box_remove(box, button);
}
static void activate(GtkApplication *app) {
GtkWindow *window = GTK_WINDOW(gtk_application_window_new(app));
gtk_window_set_decorated(window, false);
GtkCssProvider *style = gtk_css_provider_new();
gtk_css_provider_load_from_string(style, "window { background-color: transparent; }");
GdkDisplay *display = gdk_display_get_default();
gtk_style_context_add_provider_for_display(
display,
GTK_STYLE_PROVIDER(style),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
);
g_object_unref(style);
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
for (int i = 0; i < 5; i++) {
char *label = g_strdup_printf("Button %d", i + 1);
GtkWidget *button = gtk_button_new_with_label(label);
g_signal_connect(button, "clicked", G_CALLBACK(remove_from_box), box);
gtk_box_append(GTK_BOX(box), button);
}
gtk_window_set_child(window, box);
gtk_window_present(window);
}
int main(int argc, char **argv) {
GtkApplication *app =
gtk_application_new(NULL, G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
int status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
Current behavior
The last removed widget stays visible, even though it doesn't actually exist anymore.
Here are some screenshots of the test program, for reference:
... and after clicking all of the buttons, with the 4th one being last:
This "ghost button" doesn't respond well to resizing either:
I was also able to get this to happen:
Expected outcome
The widget should disappear properly, leaving the window fully transparent.
Version information
GTK 4.16.12 running on Arch Linux.
This happens on all the Wayland-based desktops I've tried it on (GNOME, Hyprland, and Sway)
Using Mesa version 24.3.4 with an AMD GPU (specifically the 6800 XT).
Additional information
This isn't exactly the most common situation to experience - indeed, having a fully transparent window is quite useless. A workaround for this is hiding the window when it doesn't have anything in it (which is probably the proper thing to do, anyway)