Determining dock position and size programmatically
Is there a way to determine the current location and size of the dock (and whether it's currently visible) programmatically? What I'm trying to do is determine a reasonable maximum window size for a game running in windowed mode. I've already accounted for the menu bar, but if possible I'd like to take the dock into account as well.
I'm using C++ and Objective-C, Cocoa, Xcode 3.1.2, and OS X 10.5.6.
I'm using C++ and Objective-C, Cocoa, Xcode 3.1.2, and OS X 10.5.6.
You could try taking a look at com.apple.dock.plist
Also take a look at -[NSScreen visibleFrame].
Thank you both for your replies. 'visibleFrame' works perfectly, thanks.
One other question, and I think I'll have it. Is there a way to determine the height of the title bar prior to creating a window? I gather you can get this information easily enough if you have an NSWindow instance to work with, but since this is for setting up the window in the first place, there's no instance available.
One other question, and I think I'll have it. Is there a way to determine the height of the title bar prior to creating a window? I gather you can get this information easily enough if you have an NSWindow instance to work with, but since this is for setting up the window in the first place, there's no instance available.
_jyk_ Wrote:Is there a way to determine the height of the title bar prior to creating a window? I gather you can get this information easily enough if you have an NSWindow instance to work with, but since this is for setting up the window in the first place, there's no instance available.
Looking at the documentation, it seems like you'd be able to calculate this from +frameRectForContentRect:styleMask: and/or +contentRectForFrameRect:styleMask:. I remember this having been a stumbling block for me in the past, too...
Thanks again for the help - everything seems to be working correctly.
I've written the following support functions:
Which are then used as follows:
This is the first Objective-C/Cocoa code I've had to write, so if any of you Cocoa experts sees anything amiss, please let me know.
I've written the following support functions:
Code:
void GetMaximizedWindowInfo(int* x, int* y, int* width, int* height)
{
*x = 0;
*y = 0;
*width = 0;
*height = 0;
CFDictionaryRef display = CGDisplayCurrentMode(kCGDirectMainDisplay);
CFNumberGetValue (
CFDictionaryGetValue(display, kCGDisplayWidth), kCFNumberSInt32Type, width);
CFNumberGetValue (
CFDictionaryGetValue(display, kCGDisplayHeight), kCFNumberSInt32Type, height);
NSArray* screens = [NSScreen screens];
if (screens != nil) {
NSScreen* screen = [screens objectAtIndex: 0];
if (screen != nil) {
NSRect frameRect = [screen visibleFrame];
unsigned int style =
NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask;
NSRect contentRect =
[NSWindow contentRectForFrameRect:frameRect styleMask:style];
*x = (int)frameRect.origin.x;
*y = (int)frameRect.origin.y;
*width = (int)contentRect.size.width;
*height = (int)contentRect.size.height;
}
}
}
void SetWindowPosition(int x, int y)
{
NSWindow* window = [NSApp mainWindow];
if (window != nil) {
NSPoint origin;
origin.x = (float)x;
origin.y = (float)y;
[window setFrameOrigin:origin];
}
}Which are then used as follows:
Code:
int x, y, width, height;
GetMaximizedWindowInfo(&x, &y, &width, &height);
SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
SetWindowPosition(x, y);This is the first Objective-C/Cocoa code I've had to write, so if any of you Cocoa experts sees anything amiss, please let me know.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| passing parameters to open -a programmatically | savage | 3 | 3,784 |
Dec 23, 2007 12:01 PM Last Post: OneSadCookie |
|
| Visual artefacts on OS X Dock | weichsel | 8 | 5,158 |
Sep 23, 2007 06:03 AM Last Post: weichsel |
|
| Get mouse speed instead of position? | Uuugggg | 3 | 2,794 |
Jun 13, 2007 02:01 PM Last Post: Uuugggg |
|

