Saturday, November 6, 2010

Cocoa: Black Window Titlebar

Starting with Quicktime X and now with Facetime, Apple has introduced a new black ui titlebar. There's no NS component at the moment or any flag of NSWindow, so I've decided to throw away ten minutes to write my own black titlebar.
I've created a NSWindow class (BlackWindow.h/BlackWindow.m) that initializes a window without borders (styleMask NSBorderlessWindowMask) and I've created a NSView that draws the titlebar (BlackWindowTitleView.h/BlackWindowTitleView.m).
The titlebar redraws itself when some changes are applied to the window. With key value observing for title, document edited, ... and NSNotificationCenter for KeyNotifications the titlebar knows what to do.

Source code can be found on my GitHub under blog-code/MacBlackWindow.
git clone https://github.com/matteobertozzi/blog-code.git

3 comments:

  1. Looks great, but there's a few problems with this approach. The window doesn't work with Spaces and can't be closed with Cmd-W. A probable better approach would be to overload NSThemeFrame's drawRect: method draw the black frame there.

    ReplyDelete
  2. I cannot get this to work at all. The window just shows up without a bar at all. Your sample project works but mine does not?

    ReplyDelete