mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 21:14:35 +00:00
Cocoa: Use modern API to get display name
On Apple Silicon, IOKit is deprecated and there will be no
matching io_service that we can query for name. Luckilly,
NSScreen got an API to fetch the display name in 10.15.
This is a blocker to get glfw running on Apple Silicon.
Fixes #1809.
Closes #1833.
(cherry picked from commit 2bc52ca82e
)
This commit is contained in:
parent
14921d1e24
commit
8746f68d61
@ -41,6 +41,22 @@
|
||||
//
|
||||
static char* getDisplayName(CGDirectDisplayID displayID)
|
||||
{
|
||||
// IOKit doesn't work on Apple Silicon anymore. Luckilly, 10.15 introduced -[NSScreen localizedName].
|
||||
// Use it if available, and fall back to IOKit otherwise.
|
||||
if ([NSScreen instancesRespondToSelector:@selector(localizedName)])
|
||||
{
|
||||
for(NSScreen *screen in [NSScreen screens])
|
||||
{
|
||||
if ([[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue] == displayID)
|
||||
{
|
||||
NSString *name = [screen valueForKey:@"localizedName"];
|
||||
if (name)
|
||||
{
|
||||
return _glfw_strdup([name UTF8String]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
io_iterator_t it;
|
||||
io_service_t service;
|
||||
CFDictionaryRef info;
|
||||
|
Loading…
Reference in New Issue
Block a user