Skip to content

Instantly share code, notes, and snippets.

@karstenBriksoft
Created October 6, 2012 16:38
Show Gist options
  • Save karstenBriksoft/3845417 to your computer and use it in GitHub Desktop.
Save karstenBriksoft/3845417 to your computer and use it in GitHub Desktop.
getting the coordinates of a status item
// based on code from http://the-useful.blogspot.de/2012/01/getting-nsstatusitem-co-ordinates.html
@implementation NSStatusItem (Position)
- (NSRect)frame
{
if (self.view)
{
return [[self.view window] frame];
}
NSImage* image = self.image;
NSImage* alternateImage = self.alternateImage;
id target = self.target;
SEL action = self.action;
BOOL highlightMode = self.highlightMode;
NSRect viewFrame = NSZeroRect;
viewFrame.size = image.size;
NSView *statusBarView = [[NSView alloc] initWithFrame: viewFrame];
self.view = statusBarView;
NSRect rect = [[statusBarView window] frame];
self.view = nil;
self.image = image;
self.alternateImage = alternateImage;
self.highlightMode = highlightMode;
self.action = action;
self.target = target;
return rect;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment