summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-11-28 15:22:48 -0500
committerDavid Robillard <d@drobilla.net>2015-11-28 15:22:48 -0500
commitf26478e12c443bf693198bfe63dae77c3879c354 (patch)
treeac6109352e9287bbb25345c2d8e5e9a27306e0b3 /src
parenta816f8cbb2652ea6b9471a7fd98f21541b56d3c7 (diff)
downloadsuil-f26478e12c443bf693198bfe63dae77c3879c354.tar.gz
suil-f26478e12c443bf693198bfe63dae77c3879c354.tar.bz2
suil-f26478e12c443bf693198bfe63dae77c3879c354.zip
Center X11 UIs in Gtk
Diffstat (limited to 'src')
-rw-r--r--src/x11_in_gtk2.c37
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);
}
}