0

On the first call of

    gtk_main();

The size of the window is set by the total size of the grid.

But on second calls, it doesn't update.

Code to replicate

int main(int argc, char **argv) {
    GtkWidget *mainWidget, *grid, *calculate;
    gtk_init(&argc, &argv);

    mainWidget = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    grid = gtk_grid_new();
    gtk_container_add(GTK_CONTAINER(mainWidget), grid);

    int i;
    static GtkWidget *a[10];
    for (i = 0; i != 10; i++) {
        char str[1];
        a[i] = gtk_button_new_with_label(str);
        gtk_grid_attach(GTK_GRID(grid), a[i], 1, i, 1, 1);
        g_signal_connect(a[i], "clicked", G_CALLBACK(gtk_main_quit), NULL);

    }

    gtk_window_set_decorated(mainWidget, FALSE);
    gtk_widget_show_all(mainWidget);

    gtk_main();
    for (i = 0; i != 9; i++) {
        gtk_container_remove(GTK_GRID(grid), a[i]);
    }
    gtk_widget_show_all(mainWidget);
    gtk_main();

    return 0;
}

Well. I tried to use GDB to find the function that calculates the size of the window on the first call but I'm having some trouble.

Albassort
  • 3
  • 2
  • Does this answer your question? [Shrink window in GTK+ dynamically when content shrinks?](https://stackoverflow.com/questions/8903140/shrink-window-in-gtk-dynamically-when-content-shrinks) – BobMorane Nov 29 '22 at 13:19

1 Answers1

0

So, as it turns out, unlike other toolkits. Not naming names (QT, Most Web Browsers), you (by default) cannot shrink a GTK window below its contents. So, a practical solution to this problem is.

gtk_window_resize(mainWidget, 1, 1)
Albassort
  • 3
  • 2