Using [NSScreen screens] I'm able to get all of the screens attached to the computer and their sizes, however I'm trying to find out their positions relative to each other (like in Arrangement in the Display preferences). Is there a way 开发者_运维百科to do this? I've looked online and through the class references on Apple's developer site and found nothing. Thank you.
For each of the screens returned by [NSScreen screens]
you can call:
[screen frame]
to get an NSRect
containing the size
and offset
of each screen. The "main" screen (i.e. the one with the menu bar) will have offset (0, 0)
.
This should be a lot simpler than handling the -deviceDescription
.
Aha! I was browsing API and found out how to do it. If you get an NSScreen's -deviceDescription
, you can get its CGDirectDisplayID
. From there you can use the Quartz Display Services from ApplicationServices to get the CGDisplayBounds
, which shows the display size and position relative to all screens.
精彩评论