public
Description: A handy OS X menu icon application for launching commands in Terminal.app and iTerm.
Homepage: http://mbcharbonneau.github.com/terminalicious
Clone URL: git://github.com/mbcharbonneau/terminalicious.git
terminalicious / DSHTransparentWindow.m
100755 89 lines (70 sloc) 1.95 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// DSHTransparentWindow.m
// Terminalicious
//
// Created by Marc Charbonneau on 3/13/05.
// Copyright 2005 Downtown Software House. All rights reserved.
//
 
#import "DSHTransparentWindow.h"
#import "DSHController.h"
 
@implementation DSHTransparentWindow
 
#pragma mark API
 
- (void)fadeWithTimer:(NSTimer *)aTimer
{
if ([self alphaValue] > 0.0)
{
        // If window is still partially opaque, reduce its opacity and wait
// until the next fire date.
 
        [self setAlphaValue:[self alphaValue] - 0.2];
    }
else
{
        [aTimer invalidate];
        [super orderOut:nil];
    }
}
 
#pragma mark NSWindow Overrides
 
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
{
if ( ![super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:flag] )
return nil;
 
    // Set the background color to clear. Our content view will handle drawing
// a partially transparent background.
 
    [self setBackgroundColor:[NSColor clearColor]];
    [self setOpaque:NO];
 
    return self;
}
 
- (BOOL)canBecomeKeyWindow
{
// Custom windows that use the NSBorderlessWindowMask can't become key by
// default, we need to change this.
 
    return YES;
}
 
- (void)keyDown:(NSEvent *)theEvent
{
unsigned short keyCode = [theEvent keyCode];
 
if ( keyCode == 53 )
{
[[self delegate] escPressed:self];
}
else if ( keyCode == 36 || keyCode == 76 )
{
[[self delegate] controlTextDidEndEditing:nil];
}
}
 
- (void)orderOut:(id)sender
{
// Begin the fade sequence.
 
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(fadeWithTimer:) userInfo:nil repeats:YES];
}
 
- (void)orderFront:(id)sender
{
[super orderFront:sender];
[self setAlphaValue:1.0];
}
 
- (void)makeKeyAndOrderFront:(id)sender
{
[super makeKeyAndOrderFront:sender];
[self setAlphaValue:1.0];
}
 
@end