Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions coresdk/src/backend/core_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

#include "easylogging++.h"

#include <cstring>

#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
Expand Down Expand Up @@ -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;
Expand Down
58 changes: 58 additions & 0 deletions coresdk/src/backend/core_driver_macos.mm
Original file line number Diff line number Diff line change
@@ -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 <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#include <cstring>

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<NSScreen *>* 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__
8 changes: 8 additions & 0 deletions projects/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down