Cocoa, full-screen mode, and windows
Cocoa, full-screen mode, and windows
- Subject: Cocoa, full-screen mode, and windows
- From: John Stiles <email@hidden>
- Date: Fri, 11 Feb 2005 11:09:25 -0800
[originally posted on MacGamesDev]
A week or two ago, you may remember a post I made about full-screen mode and the Cocoa event system. For those who are curious, I eventually decided to use a borderless window in full-screen mode (and keep my current event structure). The main motivating factors here were that: (a) pbuffers apparently only work in windowed mode, (b) the penalty for not switching into fullscreen mode is apparently quite minimal and (c) the alternatives were pretty hackish.
OK, now I've got everything running full-screen—I use CoreGraphics to capture all screens and select the mode I want, and then make an NSWindow with the proper bounds. I have one problem, though—what are the
proper bounds? I've found that when I first enter full-screen mode, I can just use [[MyNSWindowSubclass alloc] initWithContentRect:NSMakeRect( 0, 0, screenWidth, screenHeight )… and all is well. However, this trick fails me if I then change the screen resolution and try to resize the window. I use CGDisplaySwitchToMode to change resolution on the still-captured display, and then do:
NSRect windowFrame = [glWindow frameRectForContentRect:NSMakeRect( 0, 0, newWidth, newHeight )];
[glWindow setFrame:windowFrame display:NO];
But the window moves to the wrong place—it's always too high or too low. (Horizontally, it seems OK.)
I have a suspicion that this is because AppKit has not caught up with the second mode switch—I've found that while CGDisplayBounds will return the proper values for the screen (it thinks it's at 0,0,new-width,new-height), [[[NSScreen screens] objectAtIndex:0] frame] seems to return "stale" information from before the mode switch (0,0,old-width,old-height). In fact, NSScreen always seems to be stuck at the resolution from immediately after the original mode switch. Based on that hunch, I could probably figure out where AppKit
thinks the origin of that screen is, and kludge the window position I request to match, but there's got to be a better way :)
Has anyone dealt with this before? Is there a cleaner way to deal with it? I can't believe I'm struggling with the concept of "make this window cover the screen", but there you have it :)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden