Sunday, August 27, 2006

Green Circle of Confusion

Do you know what the green circle in the title bar of your windows does? What happens if you option-click it? You're not alone.

According to Apple's HIG, it toggles between a user state and a standard state -- it doesn't maximize your window -- and the HIG explicitely advice against maximizing your window. However, this is exactly what Carbon's standard window handler does. If you want to change it, you are advised to write a listener to the kEventWindowZoom event.

However, implementing the kEventWindowZoom yourself is a bad idea, because no one really knows what this button should do. Try Option-Clicking the zoom box in several apps and see what happens for instance. Finder, for example, does weird things. But, hey, we're used to that, aren't we?

Fortunately, you can get around writing your own kEventWindowZoom handler most of the time. You only need to implement an kEventWindowGetIdealSize handler and return the standard state size of your window. The standard window handler does the rest. Option-Clicking moves the window into the upper left window, as it turns out. Here's how Vim responds to that event:

static OSStatus onWindow(EventHandlerCallRef handler,
EventRef event, void *data)
Point p;

UInt32 attributes;
GetEventParameter(event, kEventParamAttributes, typeUInt32, NULL,
sizeof(UInt32), NULL, &attributes);

case kEventWindowGetIdealSize:
/* ideal width is current */
p.h = Columns * gui.char_width + gui_get_base_width();
/* ideal height is as high as we can get */
p.v = 15 * 1024;
SetEventParameter(event, kEventParamDimensions, typeQDPoint,
sizeof(p), &p);

return noErr;


Post a Comment

<< Home