REVIEWED: Avoid static variable floating around and include it to PlatformData struct

This commit is contained in:
Ray 2026-04-29 17:42:51 +02:00
parent da55d9067c
commit d9427b1e6f

View File

@ -111,6 +111,12 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
typedef struct { typedef struct {
GLFWwindow *handle; // GLFW window handle (graphic device) 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; } PlatformData;
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -755,12 +761,6 @@ void SetWindowFocused(void)
glfwFocusWindow(platform.handle); 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 // Get native window handle
void *GetWindowHandle(void) void *GetWindowHandle(void)
{ {
@ -778,17 +778,16 @@ void *GetWindowHandle(void)
} }
else else
{ {
X11WindowHandle = glfwGetX11Window(platform.handle); platform.windowHandleX11 = glfwGetX11Window(platform.handle);
return &X11WindowHandle; return &platform.windowHandleX11;
} }
#else #else
return glfwGetWaylandWindow(platform.handle); return glfwGetWaylandWindow(platform.handle);
#endif #endif
#elif defined(_GLFW_X11) #elif defined(_GLFW_X11)
// Store the window handle localy and return a pointer to the variable instead // Store the window handle localy and return a pointer to the variable instead
// Reasoning detailed in the declaration of X11WindowHandle platform.windowHandleX11 = glfwGetX11Window(platform.handle);
X11WindowHandle = glfwGetX11Window(platform.handle); return &platform.windowHandleX11;
return &X11WindowHandle;
#endif #endif
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__)