Skip to content

Instantly share code, notes, and snippets.

@alexrozanski
Created May 15, 2011 08:00
Show Gist options
  • Save alexrozanski/972958 to your computer and use it in GitHub Desktop.
Save alexrozanski/972958 to your computer and use it in GitHub Desktop.
Reposition Traffic Lights
NSButton *closeButton = [self standardWindowButton:NSWindowCloseButton];
NSView *themeFrame = [closeButton superview];
CGFloat buttonYOrigin = NSMaxY(themeFrame.frame)-34;
//Alter the button frames
NSRect closeFrame = closeButton.frame;
closeFrame.origin.y = buttonYOrigin;
closeButton.frame = closeFrame;
/* (And do the same for the minimize and maximize buttons...) */
//Get the tracking area used by the window's theme frame view
NSArray *trackingAreas = [themeFrame trackingAreas];
if([trackingAreas count]>0) {
NSTrackingArea *trackingArea = [trackingAreas objectAtIndex:0];
//Alter the tracking area rectangle
NSRect trackingRect = [trackingArea rect];
trackingRect.origin.y = NSMinY(closeFrame);
//Create the new tracking area and set it on the window's theme frame view
NSTrackingArea *newTrackingArea = [[NSTrackingArea alloc] initWithRect:trackingRect
options:[trackingArea options]
owner:[trackingArea owner]
userInfo:[NSDictionary dictionary]];
[themeFrame removeTrackingArea:trackingArea];
[themeFrame addTrackingArea:newTrackingArea];
[newTrackingArea release];
}
@alexrozanski
Copy link
Author

Well it worked with my implementation, yes. The key to it working, I found was to set the userInfo property on the tracking area to [NSDictionary dictionary].

@aquaibm
Copy link

aquaibm commented May 15, 2011

Oh, I have tried to set userInfo to [trackingArea userInfo]. Setting userInfo to [NSDictionary dictionary] is new for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment