From 4912f67839be6992b09a80a7b605cfb26f8024d3 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 10 Apr 2020 21:20:04 +0200 Subject: Ensure that XSizeHints are set and updated This fixes the following regression introduced in db07a21d484: * The window may not have been realized when wrapper_wrap is called, in which case XSizeHints were not set. * Changes to XSizeHints were never queried, so the original mininum size was enforced even when the window called ui:resize(). --- src/x11_in_gtk2.c | 66 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/x11_in_gtk2.c b/src/x11_in_gtk2.c index d8f9578..612eefa 100644 --- a/src/x11_in_gtk2.c +++ b/src/x11_in_gtk2.c @@ -49,6 +49,7 @@ struct _SuilX11Wrapper { SuilX11SizeHints custom_size; SuilX11SizeHints base_size; SuilX11SizeHints min_size; + bool query_wm; }; struct _SuilX11WrapperClass { @@ -235,6 +236,38 @@ idle_size_request(gpointer user_data) return FALSE; } +/// Read XSizeHints and store the values for later use +static void +query_wm_hints(SuilX11Wrapper* wrap) +{ + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); + XSizeHints hints = {0}; + long supplied = 0; + + XGetWMNormalHints(GDK_WINDOW_XDISPLAY(window), + (Window)wrap->instance->ui_widget, + &hints, + &supplied); + + if (hints.flags & PMaxSize) { + wrap->max_size.width = hints.max_width; + wrap->max_size.height = hints.max_height; + wrap->max_size.is_set = true; + } + if (hints.flags & PBaseSize) { + wrap->base_size.width = hints.base_width; + wrap->base_size.height = hints.base_height; + wrap->base_size.is_set = true; + } + if (hints.flags & PMinSize) { + wrap->min_size.width = hints.min_width; + wrap->min_size.height = hints.min_height; + wrap->min_size.is_set = true; + } + + wrap->query_wm = false; +} + static void forward_size_request(SuilX11Wrapper* socket, GtkAllocation* allocation) @@ -245,6 +278,10 @@ forward_size_request(SuilX11Wrapper* socket, int width = allocation->width; int height = allocation->height; + if (socket->query_wm) { + query_wm_hints(socket); + } + if (socket->max_size.is_set) { width = MIN(width, socket->max_size.width); height = MIN(height, socket->max_size.height); @@ -367,6 +404,7 @@ suil_x11_wrapper_init(SuilX11Wrapper* self) self->custom_size = (SuilX11SizeHints){false, 0, 0}; self->base_size = (SuilX11SizeHints){false, 0, 0}; self->min_size = (SuilX11SizeHints){false, 0, 0}; + self->query_wm = true; } static int @@ -378,6 +416,9 @@ wrapper_resize(LV2UI_Feature_Handle handle, int width, int height) wrap->custom_size.height = height; wrap->custom_size.is_set = width > 0 && height > 0; + // Assume the plugin has also updated min/max size constraints + wrap->query_wm = true; + gtk_widget_queue_resize(GTK_WIDGET(handle)); return 0; } @@ -403,30 +444,7 @@ wrapper_wrap(SuilWrapper* wrapper, wrap->instance = instance; if (x_window_is_valid(wrap)) { - // Read XSizeHints and store the values for later use - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); - XSizeHints hints; - memset(&hints, 0, sizeof(hints)); - long supplied; - XGetWMNormalHints(GDK_WINDOW_XDISPLAY(window), - (Window)wrap->instance->ui_widget, - &hints, - &supplied); - if (hints.flags & PMaxSize) { - wrap->max_size.width = hints.max_width; - wrap->max_size.height = hints.max_height; - wrap->max_size.is_set = true; - } - if (hints.flags & PBaseSize) { - wrap->base_size.width = hints.base_width; - wrap->base_size.height = hints.base_height; - wrap->base_size.is_set = true; - } - if (hints.flags & PMinSize) { - wrap->min_size.width = hints.min_width; - wrap->min_size.height = hints.min_height; - wrap->min_size.is_set = true; - } + query_wm_hints(wrap); } const LV2UI_Idle_Interface* idle_iface = NULL; -- cgit v1.2.1