Ok, I've narrowed it down. I stripped my code down to the relevant pieces to demonstrate the effect, getting rid of more and more stuff until the problem went away. The critical bit is setting a window border:
Code:
gtk_container_set_border_width (GTK_CONTAINER (window), 6);
If I comment this line in the code below, the drawing area sits snug in the window, without borders, but with proper initial size, and the re-sizing works properly now. It appears to me GTK cannot deal properly with hints with these borders, if the aspect ratio too high. I have ruled out the window manager by running this test code in a session without window manager. There, I cannot re-size but I can clearly tell the window is opened again with the same excessive width, and wrong aspect ratio.
Here is the demonstrator:
Code:
#include <gtk/gtk.h>
typedef struct
{
float min_width, min_height;
} WININFO;
void destroy_handler (GtkObject *object, gpointer meter)
{
gtk_main_quit();
}
void create (WININFO *info)
{
GtkWidget *window, *drawing_area;
GdkGeometry hints;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
gtk_container_set_border_width (GTK_CONTAINER (window), 6);
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy_handler), info);
drawing_area = gtk_drawing_area_new();
gtk_container_add (GTK_CONTAINER (window), drawing_area);
hints.min_width = info->min_width;
hints.min_height = info->min_height;
hints.min_aspect = hints.max_aspect = (float) info->min_width / info->min_height;
gtk_window_set_geometry_hints (GTK_WINDOW (window), drawing_area, & hints, GDK_HINT_MIN_SIZE | GDK_HINT_ASPECT);
gtk_widget_show_all (window);
}
int main(int argc, char*argv[])
{
WININFO info;
info.min_width = 300;
info.min_height = 30;
gtk_init (& argc, & argv);
create (& info);
gtk_main();
return 0;
}
The code is built with
Code:
gcc test.c `pkg-config gtk+-2.0 --cflags --libs`