I was looking to accomplish exactly the same thing. I was able to do it by setting the superview of the titlebar view in a WAYAppStoreWindow (or INAppStoreWindow) to post frame change notifications and then observing frame change notifications on this view. Add the following observer in your setup:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowTitleBarFrameDidChange:)
name:NSViewFrameDidChangeNotification
object:window.titleBarView.superview];
And turn on/off frame change notifications when entered/exiting full-screen:
window.titleBarView.superview.postsFrameChangedNotifications = YES;
Then in the implementation of the windowTitleBarFrameWillChange:
method, check to see when the titlebar will show by comparing with the last y position of it’s superview’s frame. Here is the code:
// Window titlebar heights.
#define kWindowTitlebarHeightDefault 22.0
#define kWindowTitlebarHeightStandard 37.0
#define kWindowTitlebarHeightExtended 82.0
- (void) windowTitleBarFrameDidChange:(NSNotification *)notification;
{
NSView * titleBarView = [notification object]; // view is actually the titlebar container view
if (NSMinX(_lastTitleBarFrame) == NSMinX(titleBarView.frame) &&
NSWidth(_lastTitleBarFrame) == NSWidth(titleBarView.frame) &&
NSHeight(_lastTitleBarFrame) == NSHeight(titleBarView.frame) &&
NSMinY(_lastTitleBarFrame) == -kWindowTitlebarHeightDefault &&
NSMinY(titleBarView.frame) > -kWindowTitlebarHeightDefault) // titlebar will show
{
[self windowTitleBarWillShow];
}
else if (NSMinX(_lastTitleBarFrame) == NSMinX(titleBarView.frame) &&
NSWidth(_lastTitleBarFrame) == NSWidth(titleBarView.frame) &&
NSHeight(_lastTitleBarFrame) == NSHeight(titleBarView.frame) &&
NSMinY(_lastTitleBarFrame) == 0.0 && NSMinY(titleBarView.frame) < 0.0) // titlebar will hide
{
[self windowTitleBarWillHide:YES];
}
else if (NSWidth(_lastTitleBarFrame) != NSWidth([NSScreen mainScreen].frame) &&
NSWidth(titleBarView.frame) == NSWidth([NSScreen mainScreen].frame)) // just went full-screen
{
[self windowTitleBarWillHide:NO];
}
_lastTitleBarFrame = titleBarView.frame;
}
- (void) windowTitleBarWillHide:(BOOL)animate
{
WAYAppStoreWindow * window = (WAYAppStoreWindow *)[(NSWindowController *)[[self windowControllers] objectAtIndex:0] window];
NSView * themeFrame = window.titleBarView.superview.superview;
if (animate)
[themeFrame animator].alphaValue = 0.0;
else
themeFrame.alphaValue = 0.0;
}
- (void) windowTitleBarWillShow
{
WAYAppStoreWindow * window = (WAYAppStoreWindow *)[(NSWindowController *)[[self windowControllers] objectAtIndex:0] window];
NSView * themeFrame = window.titleBarView.superview.superview;
[themeFrame animator].alphaValue = 1.0;
}
- (void) windowWillEnterFullScreen:(NSNotification *)notification
{
WAYAppStoreWindow * window = [notification object];
[self setUpFullScreenTitleBarForWindow:window];
_lastTitleBarFrame = NSZeroRect;
}
- (void) windowDidEnterFullScreen:(NSNotification *)notification;
{
WAYAppStoreWindow * window = [notification object];
window.titleBarView.superview.postsFrameChangedNotifications = YES;
_fullscreenToolbarView.hidden = NO;
}
- (void) windowWillExitFullScreen:(NSNotification *)notification;
{
WAYAppStoreWindow * window = [notification object];
window.titleBarView.superview.postsFrameChangedNotifications = NO;
[self setUpStandardTitleBarForWindow:window];
}
- (void) setUpNormalTitleBarForWindow:(WAYAppStoreWindow *)window
{
window.appearance = nil;
window.showsTitle = NO;
window.titleBarHeight = kWindowTitlebarHeightExtended;
window.verticalTrafficLightButtons = YES;
window.centerTrafficLightButtons = YES;
window.trafficLightButtonsLeftMargin = 13.0;
_fullscreenToolbarView.hidden = YES;
}
- (void) setUpFullScreenTitleBarForWindow:(WAYAppStoreWindow *)window
{
window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark];
window.showsTitle = YES;
window.titleBarHeight = kWindowTitlebarHeightStandard;
window.verticalTrafficLightButtons = NO;
window.centerTrafficLightButtons = YES;
window.trafficLightButtonsLeftMargin = 13.0;
window.verticallyCenterTitle = YES;
_fullscreenToolbarView.hidden = YES;
_lastTitleBarFrame = NSZeroRect;
}
NB: I’m using a fork of WAYWindow that adds support for vertically centring the document title in the titlebar.