Get the internal macbook screen with NSScreen

╄→尐↘猪︶ㄣ 提交于 2020-06-08 05:53:06

问题


If I have an external monitor connected to my MacBook, how would I retrieve the MacBook screen?

Either of the screens could be the screen with the menubar and the dock. They could also have the same resolution, the same name etc..

Is it posible to determine it without requesting the user to unplug all screens except the MacBook screen?


回答1:


You can use CGDisplayIsBuiltin() to find out if the display is builtin.

Example code:

int i = 0;
for(NSScreen* screen in [NSScreen screens]) {
    NSDictionary* screenDictionary = [screen deviceDescription];
    NSNumber* screenID = [screenDictionary objectForKey:@"NSScreenNumber"];
    CGDirectDisplayID aID = [screenID unsignedIntValue];     
    NSLog(@"Screen number %i is%@ builtin", i, CGDisplayIsBuiltin(aID)? @"": @" not");
    i++;
}


来源:https://stackoverflow.com/questions/10469563/get-the-internal-macbook-screen-with-nsscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!