Reputation: 5434
I have 3 External screens on my MBP Retina 15" - Using Preferences/Displays to "arrange" the monitors in a way that mimics how they're arranged in real life.
I have a small mouse position printing utility I got off of the app store. as the mouse travels, it prints the logical location of it-- and it seems to be compatible with the display arrangement.
My task is to write a program that'll enumerate them, and output the logical (top/left) coordinates of each monitor. so that those match the output of that mouse position printing utility when it's at the top/left corner. (that utility already flips the Y-coordinate) so my primary display monitor is 0,0 on the top/left corner.
I am using NSScreen's frame quite successfully, but no matter what I do, i cannot convert the Y axis output (origin.y) to top to bottom instead of cocoa's bottom to top.
How do I flip the frame NSRect on each screen such that the display arrangement is still respected?
Upvotes: 2
Views: 1295
Reputation: 34243
To get the screen frames in Quartz coordinates, you can use the Quartz Display Services API:
for(NSScreen* screen in [NSScreen screens])
{
NSRect cocoaScreenFrame = [screen frame];
CGDirectDisplayID displayID = [[screen deviceDescription][@"NSScreenNumber"] unsignedIntValue];
CGRect quartzScreenFrame = CGDisplayBounds(displayID);
NSLog(@"Screen frame in Cocoa coordinate space: %@", NSStringFromRect(cocoaScreenFrame));
NSLog(@"Screen frame in Quartz coordinate space:%@", NSStringFromRect(quartzScreenFrame));
}
If you need to convert arbitrary points or rects (e.g. mouse locations or window frames) to that coordinate space, you can take a look at this answer: In Objective-C (OS X), is the "global display" coordinate space used by Quartz Display Services the same as Cocoa's "screen" coordinate space?
Upvotes: 7