diff --git a/src/x11_init.c b/src/x11_init.c index 393eb277..ab07fe32 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -417,6 +417,8 @@ static void detectEWMH(void) getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW"); _glfw.x11.NET_FRAME_EXTENTS = getSupportedAtom(supportedAtoms, atomCount, "_NET_FRAME_EXTENTS"); + _glfw.x11.NET_REQUEST_FRAME_EXTENTS = + getSupportedAtom(supportedAtoms, atomCount, "_NET_REQUEST_FRAME_EXTENTS"); _glfw.x11.NET_WM_BYPASS_COMPOSITOR = getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_BYPASS_COMPOSITOR"); diff --git a/src/x11_platform.h b/src/x11_platform.h index dad69aef..0eb27fb5 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -121,6 +121,7 @@ typedef struct _GLFWlibraryX11 Atom NET_WM_BYPASS_COMPOSITOR; Atom NET_ACTIVE_WINDOW; Atom NET_FRAME_EXTENTS; + Atom NET_REQUEST_FRAME_EXTENTS; Atom MOTIF_WM_HINTS; // Xdnd (drag and drop) atoms diff --git a/src/x11_window.c b/src/x11_window.c index b744c89d..f577a511 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -55,6 +55,17 @@ typedef struct #define MWM_HINTS_DECORATIONS (1L << 1) +// Returns whether the event is a selection event +// +static Bool isFrameExtentsEvent(Display* display, XEvent* event, XPointer pointer) +{ + _GLFWwindow* window = (_GLFWwindow*) pointer; + return event->type == PropertyNotify && + event->xproperty.state == PropertyNewValue && + event->xproperty.window == window->x11.handle && + event->xproperty.atom == _glfw.x11.NET_FRAME_EXTENTS; +} + // Translates an X event modifier state mask // static int translateState(int state) @@ -360,6 +371,27 @@ static GLboolean createWindow(_GLFWwindow* window, PropModeReplace, (unsigned char*) &version, 1); } + if (_glfw.x11.NET_REQUEST_FRAME_EXTENTS) + { + // Ensure _NET_FRAME_EXTENTS is set, allowing glfwGetWindowFrameSize to + // function before the window is mapped + + XEvent event; + memset(&event, 0, sizeof(event)); + + event.type = ClientMessage; + event.xclient.window = window->x11.handle; + event.xclient.format = 32; // Data is 32-bit longs + event.xclient.message_type = _glfw.x11.NET_REQUEST_FRAME_EXTENTS; + + XSendEvent(_glfw.x11.display, + _glfw.x11.root, + False, + SubstructureNotifyMask | SubstructureRedirectMask, + &event); + XIfEvent(_glfw.x11.display, &event, isFrameExtentsEvent, (XPointer) window); + } + _glfwPlatformSetWindowTitle(window, wndconfig->title); XRRSelectInput(_glfw.x11.display, window->x11.handle,