Fatso
Fatso

Reputation: 1318

Strange NSScreen Coordinates

This is the constructor of my NSWindow subclass called FullScreenWindow :

- (id)initWithScreen:(NSScreen *)s {
NSRect contentRect = [s frame];
self = [super initWithContentRect:contentRect
                        styleMask:NSBorderlessWindowMask
                          backing:NSBackingStoreBuffered
                            defer:NO
                           screen:s];
if (self) {
    [self setCollectionBehavior:NSWindowCollectionBehaviorStationary|
                                NSWindowCollectionBehaviorCanJoinAllSpaces|
                                NSWindowCollectionBehaviorIgnoresCycle];
    [self setReleasedWhenClosed:YES];
    [self setBackgroundColor:[NSColor greenColor]];
    [self setAlphaValue:1.0];
    [self setOpaque:NO];
    [self setLevel:NSMainMenuWindowLevel-1];
}
return self;

}

I wanna add such an NSWindow to every display in [NSScreen screens] but when I connect a second display, the windows only display the right way if I set origin.x of contentRect to -1440 for the first display (and 0 for the second one). When I get origin.x values of the frames of the NSScreen instances it returns 0 for the first display and 1440 for the second one. Why are these coordinates shifted?

Upvotes: 4

Views: 1338

Answers (1)

Alexey F
Alexey F

Reputation: 1776

One of the [NSScreen screens] will have (0, 0) as origin.
Now imagine 2 axes: Y goes up from (0, 0) and X goes to the right.
All other screens will have coordinates with this coordinate system and screen.frame.origin will represent bottom left corner.

I could not find this in the documentation, so I found this experimenting with displays arrangement.
I had this picture with two monitors: main one 1366x768, secondary 1680x1050, aligned to the top.
I tried also different arrangements, moving #1 around #0, and my hypothesis was always correct.

Upvotes: 13

Related Questions