I recently encountered a problem on some computers where creation of NSBorderlessWindowMask
fullscreen window will display on the primary screen instead of the screen.frame
I provide. If I create a new Cocoa program with the basic window creation code, then the fullscreen window is created correctly. However, reducing the code of the original program to that of the working minimal program still creates incorrect results.
If I then change the bundle identifier by adding a single character anywhere, so perhaps from com.blah.Program
to com.blah.tProgram
then the program works fine. Changing back to the original bundle identifier and the program stops working correctly.
I deleted all contents of ~/Library/Developer/Xcode/
, ensured there were no saved preferences with defaults delete [bundle identifier]
, deleted anything with the app name in the ~/Library/
, and restarted the computer with no change in behavior.
So in summary, I had an application with a problem. I reduced the code to the working minimal code and still had the problem. I changed the bundle identifier and the program started working correctly. I reverted the bundle identifier and the program stopped working correctly.
The minimal code in question is the following in place of the default AppDelegate.m
for a new Cocoa program with a single button bound to the selector pushbutton:
#import "AppDelegate.h"
@interface AppDelegate () {
NSWindow *_fullScreenWindow;
}
@property (weak) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (IBAction)pushbutton:(id)sender {
[self fullScreenWindow];
}
- (void)fullScreenWindow {
NSArray *screens = [NSScreen screens];
NSScreen *screen = screens[1];
NSRect screenFrame = [screen frame];
NSRect frame = NSMakeRect(0,0,screenFrame.size.width,screenFrame.size.height);
NSWindow *window = [[NSWindow alloc] initWithContentRect:screenFrame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES];
[window orderFront:nil];
[window setFrame:screenFrame display:YES animate:NO];
_fullScreenWindow = window;
}
@end
The code is honestly irrelevant as I can solve the problem regardless of the bundle identifier by using NSZeroRect
for initWithContentRect:
, but I would like to know why the bundle identifier is causing this problem with the given code so that I can determine if the original problem was somewhere in my larger code, something in the Cocoa API, or something external entirely.
Is there anywhere else that something might be saved in the system? Could some other program be changing the behavior of any program with my chosen bundle identifier and if so, how would I find this program? Any other ideas?
Not sure if it's relevant but this is with XCode 6.1.1 on Yosemite 10.10.2 targeting OS X 10.10.