From d9427b1e6fcfbd02748402e2842664362103c759 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 29 Apr 2026 17:42:51 +0200 Subject: [PATCH] REVIEWED: Avoid static variable floating around and include it to PlatformData struct --- src/platforms/rcore_desktop_glfw.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index c2bd869e7..191a3130e 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -111,6 +111,12 @@ //---------------------------------------------------------------------------------- typedef struct { GLFWwindow *handle; // GLFW window handle (graphic device) +#if defined(__linux__) && defined(_GLFW_X11) + // Local storage for the window handle returned by glfwGetX11Window + // This is needed as X11 handles are integers and may not fit inside a pointer depending on platform + // Storing the handle locally and returning a pointer in GetWindowHandle allows the code to work regardless of pointer width + XID windowHandleX11; +#endif } PlatformData; //---------------------------------------------------------------------------------- @@ -755,12 +761,6 @@ void SetWindowFocused(void) glfwFocusWindow(platform.handle); } -#if defined(__linux__) && defined(_GLFW_X11) -// Local storage for the window handle returned by glfwGetX11Window -// This is needed as X11 handles are integers and may not fit inside a pointer depending on platform -// Storing the handle locally and returning a pointer in GetWindowHandle allows the code to work regardless of pointer width -static XID X11WindowHandle; -#endif // Get native window handle void *GetWindowHandle(void) { @@ -778,17 +778,16 @@ void *GetWindowHandle(void) } else { - X11WindowHandle = glfwGetX11Window(platform.handle); - return &X11WindowHandle; + platform.windowHandleX11 = glfwGetX11Window(platform.handle); + return &platform.windowHandleX11; } #else return glfwGetWaylandWindow(platform.handle); #endif #elif defined(_GLFW_X11) // Store the window handle localy and return a pointer to the variable instead - // Reasoning detailed in the declaration of X11WindowHandle - X11WindowHandle = glfwGetX11Window(platform.handle); - return &X11WindowHandle; + platform.windowHandleX11 = glfwGetX11Window(platform.handle); + return &platform.windowHandleX11; #endif #endif #if defined(__APPLE__)