Peter Zich
Peter Zich

Reputation: 512

Determining Screen Positions in Objective-C (NSScreen)

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.

Upvotes: 5

Views: 1295

Answers (2)

Alnitak
Alnitak

Reputation: 339786

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.

Upvotes: 6

Peter Zich
Peter Zich

Reputation: 512

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.

Upvotes: 4

Related Questions