From 93f86fa07413709749e5bad2823e2553515df44d Mon Sep 17 00:00:00 2001 From: Didas72 Date: Thu, 14 Aug 2025 14:30:29 +0100 Subject: [PATCH 1/4] fixes #5110 Adds more filters for conditional build of GetWindowHandle with glfw --- src/platforms/rcore_desktop_glfw.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 92f77d3bc..81a6a41f3 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -75,13 +75,15 @@ #include // Required for: timespec, nanosleep(), select() - POSIX //#define GLFW_EXPOSE_NATIVE_WAYLAND - #define GLFW_EXPOSE_NATIVE_X11 - #define Font X11Font // Hack to fix 'Font' name collision - // The definition and references to the X11 Font type will be replaced by 'X11Font' - // Works as long as the current file consistently references any X11 Font as X11Font - // Since it is never referenced (as of writting), this does not pose an issue - #include "GLFW/glfw3native.h" // Required for: glfwGetX11Window() - #undef Font // Revert hack and allow normal raylib Font usage + #ifdef _GLFW_X11 + #define GLFW_EXPOSE_NATIVE_X11 + #define Font X11Font // Hack to fix 'Font' name collision + // The definition and references to the X11 Font type will be replaced by 'X11Font' + // Works as long as the current file consistently references any X11 Font as X11Font + // Since it is never referenced (as of writting), this does not pose an issue + #include "GLFW/glfw3native.h" // Required for: glfwGetX11Window() + #undef Font // Revert hack and allow normal raylib Font usage + #endif #endif #if defined(__APPLE__) #include // Required for: usleep() @@ -710,7 +712,7 @@ void SetWindowFocused(void) glfwFocusWindow(platform.handle); } -#if defined(__linux__) +#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 @@ -723,7 +725,7 @@ void *GetWindowHandle(void) // NOTE: Returned handle is: void *HWND (windows.h) return glfwGetWin32Window(platform.handle); #endif -#if defined(__linux__) +#if defined(__linux__) && 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); From 59c979a59d35215c4ca29a3c359dc9db2bc99ba4 Mon Sep 17 00:00:00 2001 From: Diogo Diniz Date: Thu, 14 Aug 2025 18:46:45 +0100 Subject: [PATCH 2/4] Added suggestions by planetis-m --- src/platforms/rcore_desktop_glfw.c | 43 ++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 81a6a41f3..f903af741 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -74,17 +74,29 @@ #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) #include // Required for: timespec, nanosleep(), select() - POSIX - //#define GLFW_EXPOSE_NATIVE_WAYLAND - #ifdef _GLFW_X11 +#if defined(_GLFW_X11) || defined(_GLFW_WAYLAND) + // Set appropriate expose macros based on available backends + #if defined(_GLFW_X11) #define GLFW_EXPOSE_NATIVE_X11 #define Font X11Font // Hack to fix 'Font' name collision // The definition and references to the X11 Font type will be replaced by 'X11Font' // Works as long as the current file consistently references any X11 Font as X11Font // Since it is never referenced (as of writting), this does not pose an issue - #include "GLFW/glfw3native.h" // Required for: glfwGetX11Window() + #endif + + #if defined(_GLFW_WAYLAND) + #define GLFW_EXPOSE_NATIVE_WAYLAND + #endif + + // Include native header only once, regardless of how many backends are defined + #include "GLFW/glfw3native.h" // Required for: glfwGetX11Window() and glfwGetWaylandWindow() + + // Clean up X11-specific hacks + #if defined(_GLFW_X11) #undef Font // Revert hack and allow normal raylib Font usage #endif #endif +#endif #if defined(__APPLE__) #include // Required for: usleep() @@ -725,11 +737,26 @@ void *GetWindowHandle(void) // NOTE: Returned handle is: void *HWND (windows.h) return glfwGetWin32Window(platform.handle); #endif -#if defined(__linux__) && 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; +#if defined(__linux__) + #if defined(_GLFW_WAYLAND) + #if defined(_GLFW_X11) + int platformID = glfwGetPlatform(); + if (platformID == GLFW_PLATFORM_WAYLAND) { + return glfwGetWaylandWindow(platform.handle); + } + else { + X11WindowHandle = glfwGetX11Window(platform.handle); + return &X11WindowHandle; + } + #else + return glfwGetWaylandWindow(platform.handle); + #endif + #else if 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; + #endif #endif #if defined(__APPLE__) // NOTE: Returned handle is: (objc_object *) From eae1296b08317e485320d722fc0f54ab5b91ba12 Mon Sep 17 00:00:00 2001 From: Diogo Diniz Date: Thu, 14 Aug 2025 18:56:31 +0100 Subject: [PATCH 3/4] Fixed bad macro logic --- src/platforms/rcore_desktop_glfw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index f903af741..46ced651c 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -751,7 +751,7 @@ void *GetWindowHandle(void) #else return glfwGetWaylandWindow(platform.handle); #endif - #else if defined(_GLFW_X11) + #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); From 3ef5ee878c9da52f7fae46f957e45960e3ccc059 Mon Sep 17 00:00:00 2001 From: Diogo Diniz Date: Thu, 14 Aug 2025 19:58:22 +0100 Subject: [PATCH 4/4] Adjusted formatting to comply with contribution guidelines --- src/platforms/rcore_desktop_glfw.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 46ced651c..082898915 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -75,25 +75,24 @@ #include // Required for: timespec, nanosleep(), select() - POSIX #if defined(_GLFW_X11) || defined(_GLFW_WAYLAND) - // Set appropriate expose macros based on available backends + // Set appropriate expose macros based on available backends #if defined(_GLFW_X11) #define GLFW_EXPOSE_NATIVE_X11 - #define Font X11Font // Hack to fix 'Font' name collision - // The definition and references to the X11 Font type will be replaced by 'X11Font' - // Works as long as the current file consistently references any X11 Font as X11Font - // Since it is never referenced (as of writting), this does not pose an issue + #define Font X11Font // Hack to fix 'Font' name collision + // The definition and references to the X11 Font type will be replaced by 'X11Font' + // Works as long as the current file consistently references any X11 Font as X11Font + // Since it is never referenced (as of writting), this does not pose an issue #endif #if defined(_GLFW_WAYLAND) #define GLFW_EXPOSE_NATIVE_WAYLAND #endif - - // Include native header only once, regardless of how many backends are defined - #include "GLFW/glfw3native.h" // Required for: glfwGetX11Window() and glfwGetWaylandWindow() - - // Clean up X11-specific hacks - #if defined(_GLFW_X11) - #undef Font // Revert hack and allow normal raylib Font usage + + #include "GLFW/glfw3native.h" // Include native header only once, regardless of how many backends are defined + // Required for: glfwGetX11Window() and glfwGetWaylandWindow() + + #if defined(_GLFW_X11) // Clean up X11-specific hacks + #undef Font // Revert hack and allow normal raylib Font usage #endif #endif #endif @@ -741,10 +740,12 @@ void *GetWindowHandle(void) #if defined(_GLFW_WAYLAND) #if defined(_GLFW_X11) int platformID = glfwGetPlatform(); - if (platformID == GLFW_PLATFORM_WAYLAND) { + if (platformID == GLFW_PLATFORM_WAYLAND) + { return glfwGetWaylandWindow(platform.handle); } - else { + else + { X11WindowHandle = glfwGetX11Window(platform.handle); return &X11WindowHandle; }