소스 검색

Added suggestions by planetis-m

Diogo Diniz 1 개월 전
부모
커밋
59c979a59d
1개의 변경된 파일35개의 추가작업 그리고 8개의 파일을 삭제
  1. 35 8
      src/platforms/rcore_desktop_glfw.c

+ 35 - 8
src/platforms/rcore_desktop_glfw.c

@@ -74,17 +74,29 @@
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
     #include <sys/time.h>               // 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 <unistd.h>                 // 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 *)