From 9580ad46c37abe9c04ef3876bce9c3ef12c21497 Mon Sep 17 00:00:00 2001 From: redthing1 Date: Thu, 16 Oct 2025 14:00:18 -0700 Subject: [PATCH 1/2] fix window icon/dock integration with objc on macos --- profiler/src/BackendGlfw.cpp | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/profiler/src/BackendGlfw.cpp b/profiler/src/BackendGlfw.cpp index dc9206fd..5c3c3710 100644 --- a/profiler/src/BackendGlfw.cpp +++ b/profiler/src/BackendGlfw.cpp @@ -14,6 +14,13 @@ #include "Backend.hpp" #include "RunQueue.hpp" +#ifdef __APPLE__ +#include +#include +#include +#include "icon.hpp" +#endif + static GLFWwindow* s_window; static std::function s_redraw; @@ -23,6 +30,50 @@ static WindowPosition* s_winPos; static bool s_iconified; static float s_prevScale = -1; +#ifdef __APPLE__ +typedef long NSInteger; +typedef unsigned long NSUInteger; + +namespace +{ + +static void EnsureMacAppRegistration() +{ + static bool initialized = false; + if( initialized ) return; + initialized = true; + + id pool = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSAutoreleasePool"), sel_getUid("alloc")); + pool = ((id (*)(id, SEL))objc_msgSend)(pool, sel_getUid("init")); + + id app = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + ((void (*)(id, SEL, NSInteger))objc_msgSend)(app, sel_getUid("setActivationPolicy:"), (NSInteger)0); + ((void (*)(id, SEL, BOOL))objc_msgSend)(app, sel_getUid("activateIgnoringOtherApps:"), (BOOL)1); + + ((void (*)(id, SEL))objc_msgSend)(pool, sel_getUid("release")); +} + +static void SetMacAppIcon() +{ + id pool = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSAutoreleasePool"), sel_getUid("alloc")); + pool = ((id (*)(id, SEL))objc_msgSend)(pool, sel_getUid("init")); + + id data = ((id (*)(Class, SEL, const void*, NSUInteger))objc_msgSend)((Class)objc_getClass("NSData"), sel_getUid("dataWithBytes:length:"), (const void*)Icon_data, (NSUInteger)Icon_size); + id image = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSImage"), sel_getUid("alloc")); + image = ((id (*)(id, SEL, id))objc_msgSend)(image, sel_getUid("initWithData:"), data); + if( image ) + { + id app = ((id (*)(Class, SEL))objc_msgSend)((Class)objc_getClass("NSApplication"), sel_getUid("sharedApplication")); + ((void (*)(id, SEL, id))objc_msgSend)(app, sel_getUid("setApplicationIconImage:"), image); + ((void (*)(id, SEL))objc_msgSend)(image, sel_getUid("release")); + } + + ((void (*)(id, SEL))objc_msgSend)(pool, sel_getUid("release")); +} + +} +#endif + static void glfw_error_callback( int error, const char* description ) { @@ -109,6 +160,10 @@ Backend::Backend( const char* title, const std::function& redraw, const glfwSetWindowMaximizeCallback( s_window, glfw_window_maximize_callback ); #endif glfwSetWindowIconifyCallback( s_window, glfw_window_iconify_callback ); + +#ifdef __APPLE__ + EnsureMacAppRegistration(); +#endif } Backend::~Backend() @@ -190,11 +245,19 @@ void Backend::EndFrame() void Backend::SetIcon( uint8_t* data, int w, int h ) { +#ifdef __APPLE__ + (void)data; + (void)w; + (void)h; + EnsureMacAppRegistration(); + SetMacAppIcon(); +#else GLFWimage icon; icon.width = w; icon.height = h; icon.pixels = data; glfwSetWindowIcon( s_window, 1, &icon ); +#endif } void Backend::SetTitle( const char* title ) From 26254686150b3d9d7ce7ac53b286e40065d8c42b Mon Sep 17 00:00:00 2001 From: redthing1 Date: Thu, 16 Oct 2025 20:22:17 -0700 Subject: [PATCH 2/2] remove (void) unused markers --- profiler/src/BackendGlfw.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/profiler/src/BackendGlfw.cpp b/profiler/src/BackendGlfw.cpp index 5c3c3710..82eb5ed0 100644 --- a/profiler/src/BackendGlfw.cpp +++ b/profiler/src/BackendGlfw.cpp @@ -246,9 +246,6 @@ void Backend::EndFrame() void Backend::SetIcon( uint8_t* data, int w, int h ) { #ifdef __APPLE__ - (void)data; - (void)w; - (void)h; EnsureMacAppRegistration(); SetMacAppIcon(); #else