diff --git a/coresdk/src/backend/core_driver.cpp b/coresdk/src/backend/core_driver.cpp index 92d87ba7..652c0961 100644 --- a/coresdk/src/backend/core_driver.cpp +++ b/coresdk/src/backend/core_driver.cpp @@ -24,6 +24,13 @@ #include "easylogging++.h" +#include + +#ifdef __APPLE__ +// macOS-specific function to get display names (implemented in core_driver_macos.mm) +extern "C" const char* sk_macos_get_display_name(int display_index); +#endif + namespace splashkit_lib { // Storage for the system data @@ -94,7 +101,18 @@ namespace splashkit_lib disp.id = DISPLAY_PTR; +#ifdef __APPLE__ + // On macOS, SDL_GetDisplayName returns the display index instead of the name + // Use native macOS API to get the actual display name + const char* macos_name = sk_macos_get_display_name(idx); + if (macos_name && strlen(macos_name) > 0) { + disp.name = macos_name; + } else { + disp.name = SDL_GetDisplayName(idx); + } +#else disp.name = SDL_GetDisplayName(idx); +#endif SDL_GetCurrentDisplayMode(idx, &mode); disp.width = mode.w; diff --git a/coresdk/src/backend/core_driver_macos.mm b/coresdk/src/backend/core_driver_macos.mm new file mode 100644 index 00000000..bf19c624 --- /dev/null +++ b/coresdk/src/backend/core_driver_macos.mm @@ -0,0 +1,58 @@ +// +// core_driver_macos.mm +// splashkit +// +// macOS-specific display name retrieval using NSScreen API. +// This file is only compiled on macOS. +// + +#ifdef __APPLE__ + +#import +#import +#include + +extern "C" { + +/** + * Get the localized name of a display on macOS. + * + * SDL_GetDisplayName returns the display index as a string on newer macOS versions, + * so we use NSScreen.localizedName to get the actual display name. + * + * @param display_index The index of the display (0-based). + * @return The display name as a C string, or empty string if not found. + * The returned string is stored in a static buffer and is valid until + * the next call to this function. + */ +const char* sk_macos_get_display_name(int display_index) +{ + static char name_buffer[256]; + name_buffer[0] = '\0'; + + @autoreleasepool { + NSArray* screens = [NSScreen screens]; + + if (display_index < 0 || (NSUInteger)display_index >= screens.count) { + return name_buffer; + } + + NSScreen *screen = screens[display_index]; + + // localizedName is available on macOS 10.15+ + if (@available(macOS 10.15, *)) { + NSString *name = screen.localizedName; + + if (name && name.length > 0) { + strncpy(name_buffer, name.UTF8String, sizeof(name_buffer) - 1); + name_buffer[sizeof(name_buffer) - 1] = '\0'; + } + } + } + + return name_buffer; +} + +} // extern "C" + +#endif // __APPLE__ diff --git a/projects/cmake/CMakeLists.txt b/projects/cmake/CMakeLists.txt index 0780489a..fe60d8c2 100644 --- a/projects/cmake/CMakeLists.txt +++ b/projects/cmake/CMakeLists.txt @@ -219,6 +219,14 @@ file(GLOB SOURCE_FILES "${SK_EXT}/microui/src/*.c" ) +# Add macOS-specific Objective-C++ files +if (APPLE) + file(GLOB MACOS_SOURCE_FILES + "${SK_SRC}/backend/*.mm" + ) + list(APPEND SOURCE_FILES ${MACOS_SOURCE_FILES}) +endif() + # TEST FILE INCLUDES file(GLOB TEST_SOURCE_FILES "${SK_SRC}/test/*.cpp"