From 36364192d59212dc48102e8ccb6d9162bf7fa78f Mon Sep 17 00:00:00 2001 From: Didas72 Date: Sat, 19 Jul 2025 22:29:08 +0100 Subject: [PATCH 1/2] Fixes GetWindowHandle returning a bad handle under Linux X11 --- src/platforms/rcore_desktop_glfw.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 9bbd6559a..038e1c649 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -74,9 +74,14 @@ #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) #include // Required for: timespec, nanosleep(), select() - POSIX - //#define GLFW_EXPOSE_NATIVE_X11 // WARNING: Exposing Xlib.h > X.h results in dup symbols for Font type //#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 #endif #if defined(__APPLE__) #include // Required for: usleep() @@ -705,6 +710,12 @@ void SetWindowFocused(void) glfwFocusWindow(platform.handle); } +#if defined(__linux__) +// 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) { @@ -713,12 +724,10 @@ void *GetWindowHandle(void) return glfwGetWin32Window(platform.handle); #endif #if defined(__linux__) - // NOTE: Returned handle is: unsigned long Window (X.h) - // typedef unsigned long XID; - // typedef XID Window; - //unsigned long id = (unsigned long)glfwGetX11Window(platform.handle); - //return NULL; // TODO: Find a way to return value... cast to void *? - return (void *)platform.handle; + // 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 #if defined(__APPLE__) // NOTE: Returned handle is: (objc_object *) From 7b017b60d9fa05c1d386c449ce2de07282ea689a Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 21 Jul 2025 10:57:21 +0200 Subject: [PATCH 2/2] Move global variable to right code section --- src/rtext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rtext.c b/src/rtext.c index 769b4783c..1330c5906 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -130,6 +130,7 @@ extern bool isGpuReady; // NOTE: Default font is loaded on InitWindow() and disposed on CloseWindow() [module: core] static Font defaultFont = { 0 }; #endif +static int textLineSpacing = 2; // Text vertical line spacing in pixels (between lines) //---------------------------------------------------------------------------------- // Other Modules Functions Declaration (required by text) @@ -145,7 +146,6 @@ static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode #if defined(SUPPORT_FILEFORMAT_BDF) static GlyphInfo *LoadFontDataBDF(const unsigned char *fileData, int dataSize, int *codepoints, int codepointCount, int *outFontSize); #endif -static int textLineSpacing = 2; // Text vertical line spacing in pixels (between lines) #if defined(SUPPORT_DEFAULT_FONT) extern void LoadFontDefault(void);