diff options
Diffstat (limited to 'src/x11_in_gtk2.c')
-rw-r--r-- | src/x11_in_gtk2.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/x11_in_gtk2.c b/src/x11_in_gtk2.c index df3720d..e46fe8d 100644 --- a/src/x11_in_gtk2.c +++ b/src/x11_in_gtk2.c @@ -163,9 +163,44 @@ forward_size_request(SuilX11Wrapper* socket, { GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(socket->plug)); if (x_window_is_valid(socket)) { + // Calculate allocation size constrained to X11 limits for widget + int width = allocation->width; + int height = allocation->height; + XSizeHints hints; + XGetNormalHints(GDK_WINDOW_XDISPLAY(window), + (Window)socket->instance->ui_widget, + &hints); + if (hints.flags & PMaxSize) { + width = MIN(width, hints.max_width); + height = MIN(height, hints.max_height); + } + if (hints.flags & PMinSize) { + width = MAX(width, hints.min_width); + height = MAX(height, hints.min_height); + } + + // Resize widget window XResizeWindow(GDK_WINDOW_XDISPLAY(window), (Window)socket->instance->ui_widget, - allocation->width, allocation->height); + width, height); + + // Get actual widget geometry + Window root; + int wx, wy; + unsigned int ww, wh; + unsigned int ignored; + XGetGeometry(GDK_WINDOW_XDISPLAY(window), + (Window)socket->instance->ui_widget, + &root, + &wx, &wy, &ww, &wh, + &ignored, &ignored); + + // Center widget in allocation + wx = (allocation->width - ww) / 2; + wy = (allocation->height - wh) / 2; + XMoveWindow(GDK_WINDOW_XDISPLAY(window), + (Window)socket->instance->ui_widget, + wx, wy); } } |