How to use the genie effect in Cocoa with undocumented Core Graphics functions.

Look familiar? The Mac OS X genie effect is a patented effect that is set as the default minimizing effect for windows in the Mac environment. Dating back to 2004, this animation involves a complex transformation of the source window in order to render it correctly on screen. Apple have not documented this feature for use in third party applications in Cocoa (It is available in Carbon). It is something else that makes up the private portion of the Core Graphics framework. However, keen developers like yourself can play with / use / abuse this awesome effect all you like.
The genie effect can be run using the private Core Graphics function CGSCreateGenieWindowAnimation. The requisites for this: A window to use the effect on, a connection to Core Graphics, and another window into which the source window goes. As an example, take a look at this code:
- (void)doGenieFrom:(NSWindow*)source to:(NSWindow*)destination backwards:(BOOL)backwards {
CGSAnimationRef ref;
int err;
err = CGSCreateGenieWindowAnimation(_CGSDefaultConnection(), [source windowNumber], [destination windowNumber], &ref);
if (backwards) {
[source orderWindow:NSWindowBelow relativeTo:[destination windowNumber]]; /* No different to makeKeyAndOrderFront]*////
[source setExcludedFromWindowsMenu:NO];
[source flushWindow];
}
if (0 == err) {
float x;
for (x = (backwards ? 1.0 : 0.0); (backwards ? (x >= 0.0) : (x <= 1.0)); (backwards ? (x -= 0.01) : (x += 0.01))) {
err = CGSSetWindowAnimationProgress(ref, x);
usleep(1000);
}
err = CGSReleaseWindowAnimation(ref);
}
if (backwards) {
[destination setExcludedFromWindowsMenu:YES];
[source makeKeyAndOrderFront:self];
[source setExcludedFromWindowsMenu:NO];
} else {
[source setExcludedFromWindowsMenu:YES];
[destination makeKeyAndOrderFront:self];
[destination setExcludedFromWindowsMenu:NO];
}
}
How easy is that? Of course, this only compiles if you #import a header file that defines the Core Graphics private functions. (ie, just add this file to your Xcode project, then add a #import “coregraphicsservices.h” line at the top of the page where you want to use private CGS functions).
In the age of smoking windows, flashing views and an unofficial redefinement of the HIG by developers, the genie animation can finally come out to play.
If you’re enthralled by the genie, here is a list of cool stuff you can do on your mac regarding minimizing windows / expose.
Thoughts about this post? Add a comment, I value your feedback.
8 Comments so far
Leave a commentcan we have a sample project?
proclaimed by SeoxyS on November 22, 2006 10:01 pm | Permalink
is it possible to run it agains a view instead of a window ?
divulged by Michal on November 22, 2006 10:38 pm | Permalink
The Genie effect is available via public APIs. Have a look at TransitionWindow and friends. See MacWindows.h.
I’m not sure if TransitionWindow is compatible with a NSWindow. - (void *)windowRef is probably required.
reasonded by Matthew Drayton on November 22, 2006 11:05 pm | Permalink
Sample project: the CGS Framework includes a demo app.
Running it on views is not possible as far as I’m aware, unless you write your own transform effect. (And it would look a little strange if the title bar stayed in place while the window transformed) - unless the view genied out from one window into another. Now that would be completely awesome!
And finally, Matt Drayton, you’re right. The Genie effect via MacWindows.h is available for Carbon. I didn’t realise this was available, so thanks.
However, most developers (especially new ones) tend to generally stick to Cocoa as much as they can. This method simply allows them to do so (and who doesn’t like to use undocumented code?
).
announced by Ankur on November 23, 2006 7:00 am | Permalink
Hm again, you can use it on views if you hide the view and make a borderless window on top and then apply it on the window.
Thanks ankur for the sample project
revealed by SeoxyS on November 23, 2006 4:38 pm | Permalink
i think that from the photo this is a great product but off course i cannot try it as i am using PC not MAC so why donot u make a PC windows version??
recorded by me on April 26, 2007 7:09 am | Permalink
WHERE CAN I DONLOAD THIS EFFECT FOR WINDOWS?
stated by nono on June 13, 2008 6:47 am | Permalink
Leave a comment