Skip to content

Conversation

@ralphweng2023
Copy link

Description

This PR fixes the display_name() function returning display index numbers ("0", "1", "2") instead of actual display names on macOS.

Problem

On newer macOS versions, SDL_GetDisplayName() returns the display index as a string instead of the actual display name. This is a known SDL2 limitation.

Before:

Display Number: 1
Name: 0

After:

Display Number: 1
Name: Built-in Retina Display

Root Cause

SDL_GetDisplayName() in SDL2 does not properly retrieve display names on macOS 10.15+ (Catalina and later).

Solution

Use native macOS NSScreen.localizedName API via Objective-C++ to get proper display names. The implementation:

  1. Adds a new core_driver_macos.mm file with macOS-specific code
  2. Uses NSScreen.localizedName which returns proper names like "Built-in Retina Display" or "DELL U2720Q"
  3. Falls back to SDL_GetDisplayName() on older macOS versions (pre-10.15) or other platforms

Files Changed

  • core_driver.cpp: Added macOS-specific code path using sk_macos_get_display_name()
  • core_driver_macos.mm: New Objective-C++ file implementing the macOS NSScreen API
  • CMakeLists.txt: Updated to include .mm files in the macOS build

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. Created standalone test program using NSScreen.localizedName:
$ /tmp/test_macos_display
Number of screens: 1
Display 0: 'Built-in Retina Display'
  1. Built SplashKit on macOS with the fix:
cd projects/cmake
cmake --preset macOS
cmake --build build/
# Build succeeded

Testing Checklist

  • Code compiles without errors on macOS
  • Native macOS API returns correct display name
  • Falls back gracefully on older macOS versions
  • Tested on Linux (no changes to Linux path)
  • Tested on Windows (no changes to Windows path)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Root cause: SDL_GetDisplayName returns display index ('0', '1', etc.)
instead of actual display names on newer macOS versions.

Solution: Use native macOS NSScreen.localizedName API via Objective-C++
to get proper display names like 'Built-in Retina Display'.

Changes:
- core_driver.cpp: Add macOS-specific code path using sk_macos_get_display_name()
- core_driver_macos.mm: New Objective-C++ file implementing NSScreen API
- CMakeLists.txt: Add macOS .mm files to build

Tested on macOS - now correctly returns 'Built-in Retina Display'
instead of '0'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants