0

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.

notedible
  • 983
  • 7
  • 9

1 Answers1

0

The only thing I can think of is on the Bundle Identifier on the Info.plist of the application. Maybe you can directly edit that file and see how that goes.

For this you can use plistbuddy:

/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' /Applications/YourApplication.app/Contents/Info.plist

Or use this on a script:

a=Finder; mdls -name kMDItemCFBundleIdentifier -raw "$(mdfind kMDItemContentType==com.apple.application-bundle | sed -E $'s|(.*/)(.*)|\\1\t\\2|' | grep -F $'\t'"$a".app -m1 | tr -d '\t')"

I strongly doubt it is something related to your code I don't see what could be causing it.

What could be causing it is if you are using Loadable bundles as plug ins for functionality inside of your original bundle, maybe that could be having an influence on your problem. Since you have tried doing a blank project to test this, this may not be the issue. Still worth a look.

Check if the linking of all your resources is correct and found, I've seen instances where the linking can have some unexpected effects on some settings of the project.

I don't think another program could be influencing or changing the behavior of your chosen Bundle Identifier, the only instance that could be the case is if both Bundle Identifiers are too closely related (and even that would be pretty surprising).

I hope this can give you some help or new ideas about the issue.

Jose Luis
  • 3,307
  • 3
  • 36
  • 53
  • Thanks for the ideas. As I mentioned I already changed the Bundle Identifier. I didn't specify but I did this both by directly editing the `Info.plist` in a built app bundle and in XCode prior to re-building. The problem still persists on that computer if I use the minimal working example code with the original bundle identifier, but not if I change it. I am really curious why this would persist over multiple reboots and with all the other things I tried. I am not using any Loadable bundles, and all resources are correct and found. Quite frustrating! – notedible Apr 08 '15 at 20:28