Created
June 8, 2012 02:52
-
-
Save tonyarnold/2893241 to your computer and use it in GitHub Desktop.
Retrieve the frame of the OS X desktop as a single NSRect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSScreen+CBAdditions.h | |
| // Hyperspaces | |
| // | |
| // Created by Tony Arnold on 2/11/10. | |
| // Copyright 2010 The CocoaBots. All rights reserved. | |
| // | |
| #import <Cocoa/Cocoa.h> | |
| @interface NSScreen (CBAdditions) | |
| + (NSRect)desktopFrame; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // NSScreen+CBAdditions.m | |
| // Hyperspaces | |
| // | |
| // Created by Tony Arnold on 2/11/10. | |
| // Copyright 2010 The CocoaBots. All rights reserved. | |
| // | |
| #import "NSScreen+CBAdditions.h" | |
| @implementation NSScreen (CBAdditions) | |
| + (NSRect)desktopFrame { | |
| NSArray *screens = [NSScreen screens]; | |
| NSRect frame = NSZeroRect; | |
| NSScreen *screen = nil; | |
| if (!screens) { | |
| return frame; | |
| } | |
| // Menubar is the 0th screen (according to the NSScreen docs) | |
| NSEnumerator *e = [screens objectEnumerator]; | |
| frame = [[screens objectAtIndex:0] frame]; | |
| while ((screen = [e nextObject])) { | |
| // Union the entirety of the frame (not just the visible area) | |
| frame = NSUnionRect(frame, [screen frame]); | |
| } | |
| return frame; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment