4
votes

I'm stuck! Obviously... because I'm posting a question here.

I have built my own custom window controls for my OS X / cocoa app. The close button works great -- no problems. The minimize button doesn't work at all when I disable the titlebar.

enter image description here

So when the title bar is on like the image above and I hit this method, the minimizing works fine:

ViewController.h

@interface ViewController : NSViewController {

    - (IBAction)minimize:(id)sender;        
    @property (strong) IBOutlet NSButton *btn_minimize;

}
@end

ViewController.m

@implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
    }

    - (IBAction)minimize:(id)sender {
      [[NSApp mainWindow] performMiniaturize:self];
    }

    -(IBAction)terminate:(id)sender {
        [NSApp terminate:self];
    }
@end

Then if I disable the title bar, that same method stops working. No errors, nothing. I've tried both: [[NSApp mainWindow] miniaturize:nil]; and also [[NSApp mainWindow] performMiniaturize:self];. Neither of which worked. Actually... the both work IF the title bar is on. But once I turn it off, neither work.

titlebar turned off

app with no title bar

Thoughts / comments?

Oh, I'm using Storyboards, Xcode 7, and am targeting 10.10 and using the 10.11 SDK if that matters at all.

Thanks in advance.

2
When you disable/hide it what is the status of main menu bar (there should be validation, which means unsupported menu items are greyed out). If they are clickable do they work? (are they calling your viewController?)Marek H
[NSWindow performMiniaturize:] calls [minimizeButton performClick:esi], +[NSWindow _minimizeAll]: calls [ebx standardWindowButton:0x1] isEnabled] != 0x0) && ([ebx isVisible] != 0x0). Manual override calls private _minimizeToDock. This means if you want them to work, either you use private selectors or dislay those buttonsMarek H
Do you want to leave those buttons at this location?mangerlahn

2 Answers

4
votes

You have to keep the original "traffic light" buttons around and hide them manually.

Here's how I've configured the window:

self.titleVisibility = NSWindowTitleHidden;
self.titlebarAppearsTransparent = YES;
self.movableByWindowBackground = YES;

And here's how I've hidden the traffic lights:

for (id subview in self.contentView.superview.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
        NSView *titlebarView = [subview subviews][0];
        for (id button in titlebarView.subviews) {
            if ([button isKindOfClass:[NSButton class]]) {
                [button setHidden:YES];
            }
        }
    }
}

See sample project here.

0
votes

In my case, I wanted to completely remove the title bar and trigger the miniaturization through some other means (eg: a key assignment).

I found that ensuring that the window style mask includes NSMiniaturizableWindowMask was required in order for NSWindow::miniaturize to have an effect.