In the below code, I create two windows, and use a window delegate to make sure that whenever the first is fullscreened, its menubar and dock are hidden properly. However, when I fullscreen the first window and go back to the desktop to see my second window, the second window's minimize button is grayed out and using miniaturize on it will not work either. I've tried various things; it seems like if I fullscreen the second window and the unfullscreen it, it then becomes minimizable without additional side effects. Is there any reason why this is happening? This seems like a bug in AppKit... so how do I work around it programmatically?
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>
@property (strong) NSWindow *mainWindow;
@property (strong) NSWindow *secondaryWindow;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSRect mainRect = NSMakeRect(100, 300, 400, 300);
self.mainWindow = [[NSWindow alloc] initWithContentRect:mainRect
styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable)
backing:NSBackingStoreBuffered
defer:NO];
[self.mainWindow setTitle:@"Main Window (Go Fullscreen Here)"];
[self.mainWindow setDelegate:self];
NSTextField *mainLabel = [NSTextField labelWithString:@"1. Click the green zoom/fullscreen button on THIS window.\n\n2. Look at the other window's yellow minimize button."];
[mainLabel setFrame:NSMakeRect(20, 100, 360, 100)];
[[self.mainWindow contentView] addSubview:mainLabel];
[self.mainWindow makeKeyAndOrderFront:nil];
NSRect secondaryRect = NSMakeRect(550, 300, 400, 300);
self.secondaryWindow = [[NSWindow alloc] initWithContentRect:secondaryRect
styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable)
backing:NSBackingStoreBuffered
defer:NO];
[self.secondaryWindow setTitle:@"Secondary Window (The Victim)"];
NSButton *testButton = [NSButton buttonWithTitle:@"Try code [window miniaturize:]" target:self action:@selector(attemptProgrammaticMinimize:)];
[testButton setFrame:NSMakeRect(80, 130, 240, 40)];
[[self.secondaryWindow contentView] addSubview:testButton];
[self.secondaryWindow makeKeyAndOrderFront:nil];
}
- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions {
return NSApplicationPresentationFullScreen |
NSApplicationPresentationHideMenuBar |
NSApplicationPresentationHideDock;
}
- (void)attemptProgrammaticMinimize:(id)sender {
[self.secondaryWindow miniaturize:nil];
NSLog(@"[Repro] Minimize attempted");
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSApplication *app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
AppDelegate *delegate = [[AppDelegate alloc] init];
[app setDelegate:delegate];
[app activateIgnoringOtherApps:YES];
[app run];
}
return 0;
}
3
0
421