Get macbook internal screen using NSScreen

If I have an external monitor connected to my MacBook, how do I get a MacBook screen?

Any of the screens can be a screen with a menu and a docking station. They can also have the same permission, the same name, etc.

Is it possible to determine this without asking the user to turn off all screens except the MacBook screen?

+4
source share
1 answer

You can use CGDisplayIsBuiltin() to find out if the display is built-in.

Code example:

 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++; } 
+8
source

Source: https://habr.com/ru/post/1410962/


All Articles