-
Notifications
You must be signed in to change notification settings - Fork 4
/
ShroudMenuBarView.m
112 lines (85 loc) · 2.65 KB
/
ShroudMenuBarView.m
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// ShroudMenuBarView.m
// Shroud
//
// Created by Nicholas Riley on 2/19/10.
// Copyright 2010 Nicholas Riley. All rights reserved.
//
#import "ShroudMenuBarView.h"
@implementation ShroudMenuBarView
- (id)initWithFrame:(NSRect)frameRect;
{
if ( (self = [super initWithFrame:frameRect]) == nil)
return nil;
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self frame] options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways owner:self userInfo:nil];
[self addTrackingArea:area];
[area release];
NSDistributedNotificationCenter *distributedNotificationCenter = [NSDistributedNotificationCenter defaultCenter];
[distributedNotificationCenter addObserver:self
selector:@selector(menuTrackingDidBegin:)
name:@"com.apple.HIToolbox.beginMenuTrackingNotification"
object:nil];
[distributedNotificationCenter addObserver:self
selector:@selector(menuTrackingDidEnd:)
name:@"com.apple.HIToolbox.endMenuTrackingNotification"
object:nil];
return self;
}
- (void)dealloc;
{
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)coverMenuBar:(BOOL)cover animatingWithDuration:(NSTimeInterval)duration;
{
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:duration];
[[[self window] animator] setAlphaValue:cover ? 1 : 0];
[NSAnimationContext endGrouping];
}
- (void)coverMenuBar:(BOOL)cover;
{
[self coverMenuBar:cover animatingWithDuration:0.1];
}
- (void)coverMenuBarIfNeededAnimatingWithDuration:(NSTimeInterval)duration;
{
if (mouseInMenuBar || peekInProgress)
return;
[self coverMenuBar:YES animatingWithDuration:duration];
}
- (void)setPeeking:(BOOL)peeking;
{
peekInProgress = peeking;
if (mouseInMenuBar || menuTrackingInProgress)
return;
[self coverMenuBar:!peeking];
}
- (void)mouseEntered:(NSEvent *)theEvent;
{
mouseInMenuBar = YES;
if (menuTrackingInProgress || peekInProgress)
return;
[self coverMenuBar:NO];
}
- (void)mouseExited:(NSEvent *)theEvent;
{
mouseInMenuBar = NO;
if (menuTrackingInProgress || peekInProgress)
return;
[self coverMenuBar:YES];
}
- (void)menuTrackingDidBegin:(NSNotification *)notification;
{
if (!mouseInMenuBar)
return;
menuTrackingInProgress = YES;
}
- (void)menuTrackingDidEnd:(NSNotification *)notification;
{
if (!menuTrackingInProgress)
return;
menuTrackingInProgress = NO;
// Immediately hide the menu bar so you don't see a flicker when the menu highlight disappears.
[self coverMenuBarIfNeededAnimatingWithDuration:0.01];
}
@end