+static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child)
+{
+ gint x, y, w, h, dx, dy;
+ GtkRequisition req;
+ gtk_window_set_position(GTK_WINDOW(child), GTK_WIN_POS_NONE);
+ gtk_widget_size_request(GTK_WIDGET(child), &req);
+
+ gdk_window_get_origin(GTK_WIDGET(parent)->window, &x, &y);
+ gdk_window_get_size(GTK_WIDGET(parent)->window, &w, &h);
+
+ /*
+ * One corner of the transient will be offset inwards, by 1/4
+ * of the parent window's size, from the corresponding corner
+ * of the parent window. The corner will be chosen so as to
+ * place the transient closer to the centre of the screen; this
+ * should avoid transients going off the edge of the screen on
+ * a regular basis.
+ */
+ if (x + w/2 < gdk_screen_width() / 2)
+ dx = x + w/4; /* work from left edges */
+ else
+ dx = x + 3*w/4 - req.width; /* work from right edges */
+ if (y + h/2 < gdk_screen_height() / 2)
+ dy = y + h/4; /* work from top edges */
+ else
+ dy = y + 3*h/4 - req.height; /* work from bottom edges */
+ gtk_widget_set_uposition(GTK_WIDGET(child), dx, dy);
+}
+