+static gboolean not_size_allocated_yet(GtkWidget *w)
+{
+ /*
+ * This function tests whether a widget has not yet taken up space
+ * on the screen which it will occupy in future. (Therefore, it
+ * returns true only if the widget does exist but does not have a
+ * size allocation. A null widget is already taking up all the
+ * space it ever will.)
+ */
+ if (!w)
+ return FALSE; /* nonexistent widgets aren't a problem */
+
+#if GTK_CHECK_VERSION(2,18,0) /* skip if no gtk_widget_get_allocation */
+ {
+ GtkAllocation a;
+ gtk_widget_get_allocation(w, &a);
+ if (a.height == 0 || a.width == 0)
+ return TRUE; /* widget exists but has no size yet */
+ }
+#endif
+
+ return FALSE;
+}
+
+static void try_shrink_drawing_area(frontend *fe)
+{
+ if (fe->drawing_area_shrink_pending &&
+ !not_size_allocated_yet(fe->menubar) &&
+ !not_size_allocated_yet(fe->statusbar)) {
+ /*
+ * In order to permit the user to resize the window smaller as
+ * well as bigger, we call this function after the window size
+ * has ended up where we want it. This shouldn't shrink the
+ * window immediately; it just arranges that the next time the
+ * user tries to shrink it, they can.
+ *
+ * However, at puzzle creation time, we defer the first of
+ * these operations until after the menu bar and status bar
+ * are actually visible. On Ubuntu 12.04 I've found that these
+ * can take a while to be displayed, and that it's a mistake
+ * to reduce the drawing area's size allocation before they've
+ * turned up or else the drawing area makes room for them by
+ * shrinking to less than the size we intended.
+ */
+ gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), 1, 1);
+ fe->drawing_area_shrink_pending = FALSE;
+ }
+}
+
+static gint configure_window(GtkWidget *widget,
+ GdkEventConfigure *event, gpointer data)
+{
+ frontend *fe = (frontend *)data;
+ /*
+ * When the main puzzle window changes size, it might be because
+ * the menu bar or status bar has turned up after starting off
+ * absent, in which case we should have another go at enacting a
+ * pending shrink of the drawing area.
+ */
+ try_shrink_drawing_area(fe);
+ return FALSE;
+}
+