From d74307223fda5a8677a56a35416bdb62d12cd203 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 27 Mar 2021 21:05:27 +1100 Subject: [PATCH] [client] x11: set the window center via WM_SIZE_HINTS Due to the confusing nature of the x11 protocol, bit_gravity and win_gravity are not what they appear to be. These do not describe the window position but rather the pixels/subwindows when the window is resized. Instead set the gravity via the WM_SIZE_HINTS property which all modern window managers should respect. --- client/displayservers/X11/x11.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/client/displayservers/X11/x11.c b/client/displayservers/X11/x11.c index 4a4d74d1..46112457 100644 --- a/client/displayservers/X11/x11.c +++ b/client/displayservers/X11/x11.c @@ -138,18 +138,6 @@ static bool x11Init(const LG_DSInitParams params) } #endif - swaMask |= CWBitGravity | CWWinGravity; - if (params.center) - { - swa.bit_gravity = CenterGravity; - swa.win_gravity = CenterGravity; - } - else - { - swa.bit_gravity = NorthWestGravity; - swa.win_gravity = NorthWestGravity; - } - x11.window = XCreateWindow( x11.display, XDefaultRootWindow(x11.display), @@ -179,6 +167,15 @@ static bool x11Init(const LG_DSInitParams params) free(hint.res_name); free(hint.res_class); + if (params.center) + { + XSizeHints *xsh = XAllocSizeHints(); + xsh->flags = PWinGravity; + xsh->win_gravity = 5; //Center + XSetWMNormalHints(x11.display, x11.window, xsh); + XFree(xsh); + } + X11AtomsInit(); XSetWMProtocols(x11.display, x11.window, &x11atoms.WM_DELETE_WINDOW, 1);