Skip to content

Instantly share code, notes, and snippets.

@atr000
Created August 20, 2010 00:57
Show Gist options
  • Save atr000/539334 to your computer and use it in GitHub Desktop.
Save atr000/539334 to your computer and use it in GitHub Desktop.
flashscreen.m
//
// flashscreen.m
// Command Utility
//
// Copyright Cucurbita. All rights reserved.
//
// gcc -framework AppKit flashscreen.m -o flashscreen
// gcc -DHAVE_WINDOW_FADE -framework AppKit flashscreen.m -o flashscreen
#import <AppKit/AppKit.h>
@interface flashscreenWindow : NSWindow {
}
@end
@implementation flashscreenWindow
- (id)initFullScreen
{
if ((self = [super initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) {
[self setBackgroundColor: [NSColor whiteColor]];
[self setLevel:CGShieldingWindowLevel()];
#ifdef HAVE_WINDOW_FADE
[self setAlphaValue:0.0];
#else
[self setAlphaValue:0.3];
#endif
[self setOpaque:NO];
[self setHasShadow:NO];
}
return self;
}
@end
@interface flashscreenDelegate: NSObject {
flashscreenWindow *window;
}
@end
@implementation flashscreenDelegate
- (void)dealloc
{
if (window) {
[window release];
}
[super dealloc];
}
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
window = [[flashscreenWindow alloc] initFullScreen];
[window makeKeyAndOrderFront:self];
#ifdef HAVE_WINDOW_FADE
float alpha = 0.0;
int i = 0;
for (i = 0; i < 3; i++) {
alpha += 0.1;
[window setAlphaValue:alpha];
[NSThread sleepForTimeInterval:0.040];
}
for (i = 0; i < 6; i++) {
alpha -= 0.05;
[window setAlphaValue:alpha];
[NSThread sleepForTimeInterval:0.020];
}
[[NSApplication sharedApplication] terminate:self];
#else
[NSTimer scheduledTimerWithTimeInterval:0.2
target:self selector:@selector(terminateFlashScreen:) userInfo:nil repeats:NO];
#endif
}
#ifndef HAVE_WINDOW_FADE
- (void)terminateFlashScreen:(NSTimer *)timer
{
[timer invalidate];
[[NSApplication sharedApplication] terminate:self];
}
#endif
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
if (window) {
[window orderOut:self];
}
}
@end
int main(int argc, const char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[[NSApplication sharedApplication] setDelegate:[flashscreenDelegate new]];
[[NSApplication sharedApplication] run];
[pool drain];
return 0;
}
/* EOF */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment