This commit is contained in:
halx99 2025-12-06 09:24:37 +00:00 committed by GitHub
commit 160422b142
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -314,6 +314,7 @@ void _glfwPollMonitorsCocoa(void)
_glfw.monitorCount * sizeof(_GLFWmonitor*)); _glfw.monitorCount * sizeof(_GLFWmonitor*));
} }
NSArray* screens = [NSScreen screens];
for (uint32_t i = 0; i < displayCount; i++) for (uint32_t i = 0; i < displayCount; i++)
{ {
if (CGDisplayIsAsleep(displays[i])) if (CGDisplayIsAsleep(displays[i]))
@ -322,7 +323,7 @@ void _glfwPollMonitorsCocoa(void)
const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]);
NSScreen* screen = nil; NSScreen* screen = nil;
for (screen in [NSScreen screens]) for (screen in screens)
{ {
NSNumber* screenNumber = [screen deviceDescription][@"NSScreenNumber"]; NSNumber* screenNumber = [screen deviceDescription][@"NSScreenNumber"];
@ -332,6 +333,9 @@ void _glfwPollMonitorsCocoa(void)
if (CGDisplayUnitNumber([screenNumber unsignedIntValue]) == unitNumber) if (CGDisplayUnitNumber([screenNumber unsignedIntValue]) == unitNumber)
break; break;
} }
// fallback: when displays are in mirroring mode, only one NSScreen exists
if(screen == nil)
screen = [[NSScreen screens] firstObject];
// HACK: Compare unit numbers instead of display IDs to work around // HACK: Compare unit numbers instead of display IDs to work around
// display replacement on machines with automatic graphics // display replacement on machines with automatic graphics