From 4819f181252b520caab2696d0812e2dd8cb168a9 Mon Sep 17 00:00:00 2001 From: Chris Cascioli Date: Tue, 17 Feb 2026 19:35:55 -0500 Subject: [PATCH] Added a getter to expose native window handle --- thirteen.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/thirteen.h b/thirteen.h index 37ab3db..530b863 100644 --- a/thirteen.h +++ b/thirteen.h @@ -89,6 +89,16 @@ namespace Thirteen using uint8 = unsigned char; using uint32 = unsigned int; +#if defined(THIRTEEN_PLATFORM_WINDOWS) + using NativeWindowHandle = HWND; +#elif defined(THIRTEEN_PLATFORM_WEB) + using NativeWindowHandle = void*; +#elif defined(THIRTEEN_PLATFORM_MACOS) + using NativeWindowHandle = void*; +#elif defined(THIRTEEN_PLATFORM_LINUX) + using NativeWindowHandle = int; +#endif + // ========== Function Prototypes ========== // Initializes window and DX12. Returns a pointer to the pixel buffer on success, or nullptr on failure. @@ -121,6 +131,9 @@ namespace Thirteen // Returns the current height of the rendering surface in pixels. [[nodiscard]] uint32 GetHeight(); + // Returns the platform-specific window handle. + [[nodiscard]] NativeWindowHandle GetWindowHandle(); + // Sets the size of the rendering surface. Recreates internal buffers. Returns the new pixel buffer pointer on success, or nullptr on failure. The returned pointer may differ from the one returned by Init(). [[nodiscard]] uint8* SetSize(uint32 width, uint32 height); @@ -191,8 +204,6 @@ namespace Thirteen #if defined(THIRTEEN_PLATFORM_WINDOWS) - using NativeWindowHandle = HWND; - struct PlatformWin32 { HWND hwnd = nullptr; @@ -646,7 +657,7 @@ namespace Thirteen } }; #elif defined(__EMSCRIPTEN__) - using NativeWindowHandle = void*; + struct PlatformWeb { static constexpr const char* c_canvasSelector = "#canvas"; @@ -1200,7 +1211,7 @@ namespace Thirteen } }; #elif defined(THIRTEEN_PLATFORM_MACOS) - using NativeWindowHandle = void*; + extern "C" void* MTLCreateSystemDefaultDevice(void); using NSUInteger = unsigned long; @@ -1571,8 +1582,6 @@ namespace Thirteen #elif defined(THIRTEEN_PLATFORM_LINUX) - using NativeWindowHandle = int; - struct PlatformLinuxX11GL { void * x11Library = nullptr; @@ -2220,6 +2229,11 @@ namespace Thirteen return Internal::height; } + NativeWindowHandle GetWindowHandle() + { + return Internal::platform->GetWindowHandle(); + } + uint8* SetSize(uint32 width, uint32 height) { using namespace Internal;