summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--src/x11_in_gtk2.c37
2 files changed, 38 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 5b12494..dca1e72 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ suil (0.8.3) unstable;
* Configure based on compiler target OS for cross-compilation
* Add Cocoa in Gtk wrapper (patch from Robin Gareus)
* Various Windows fixes (patches from Robin Gareus)
+ * Center X11 UIs in Gtk (patch from Robin Gareus)
* Add Gtk2 and X11 in Qt5 wrappers (patch from Rui Nuno Capela)
* Fix compilation with -Wl,--no-undefined
* Fix a few minor/unlikely memory errors
@@ -10,7 +11,7 @@ suil (0.8.3) unstable;
* Only report suil_ui_supported() if necessary wrapper is compiled in
* Upgrade to waf 1.8.14
- -- David Robillard <d@drobilla.net> Fri, 02 Oct 2015 20:55:54 -0400
+ -- David Robillard <d@drobilla.net> Sat, 28 Nov 2015 15:22:29 -0500
suil (0.8.2) stable;
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);
}
}