From 1ca03a186f80fcb2b05d650c9870da0e587dff3d Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 11 May 2018 09:00:46 +0100 Subject: [PATCH] gtkwin: factor out drawing_area_setup_simple(). I'm about to want to do this operation from more places, so here's a minor NFC refactoring that will simplify the next commit. --- unix/gtkwin.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index f528fe2f..0fd8b3fa 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -699,21 +699,31 @@ static void drawing_area_setup(struct gui_data *inst, int width, int height) #endif } +static void drawing_area_setup_simple(struct gui_data *inst) +{ + /* + * Wrapper on drawing_area_setup which fetches the width and + * height of the drawing area. We go directly to the inner version + * in the case where a new size allocation comes in (just in case + * GTK hasn't installed it in the normal place yet). + */ +#if GTK_CHECK_VERSION(2,0,0) + GdkRectangle alloc; + gtk_widget_get_allocation(inst->area, &alloc); +#else + GtkAllocation alloc = inst->area->allocation; +#endif + drawing_area_setup(inst, alloc.width, alloc.height); +} + static void area_realised(GtkWidget *widget, gpointer data) { struct gui_data *inst = (struct gui_data *)data; inst->drawing_area_realised = TRUE; if (inst->drawing_area_realised && inst->drawing_area_got_size && - !inst->drawing_area_setup_done) { -#if GTK_CHECK_VERSION(2,0,0) - GdkRectangle alloc; - gtk_widget_get_allocation(inst->area, &alloc); -#else - GtkAllocation alloc = inst->area->allocation; -#endif - drawing_area_setup(inst, alloc.width, alloc.height); - } + !inst->drawing_area_setup_done) + drawing_area_setup_simple(inst); } static void area_size_allocate(