-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMenuBarHider.m
More file actions
100 lines (82 loc) · 2.24 KB
/
MenuBarHider.m
File metadata and controls
100 lines (82 loc) · 2.24 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
90
91
92
93
94
95
96
97
98
99
100
/*
* This file is part of the MenuBarHider project.
*
* Copyright 2010-2014 Crazor <crazor@gmail.com>
*
* MenuBarHider is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MenuBarHider is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MenuBarHider. If not, see <http://www.gnu.org/licenses/>.
*/
#import "MenuBarHider.h"
#import "JRSwizzle/JRSwizzle.h"
#import <Carbon/Carbon.h>
@interface NSScreen (MenuBarHider)
- (NSRect)myVisibleFrame;
@end
@implementation NSScreen (MenuBarHider)
- (NSRect)myVisibleFrame
{
return [self frame];
}
@end
@implementation MenuBarHider
static MenuBarHider *sharedInstance;
+ (void)load
{
#ifdef DEBUG
NSLog(@"MenuBarHider loaded.");
#endif
SetSystemUIMode(kUIModeAllSuppressed, 0);
[[NSApplication sharedApplication] addObserver:[MenuBarHider sharedInstance]
forKeyPath:@"currentSystemPresentationOptions"
options:(NSKeyValueObservingOptionNew
| NSKeyValueObservingOptionOld)
context:NULL];
[NSScreen jr_swizzleMethod:@selector(visibleFrame) withMethod:@selector(myVisibleFrame) error:NULL];
}
+ (void)initialize
{
static BOOL initialized = NO;
if (!initialized)
{
sharedInstance = [[MenuBarHider alloc] init];
initialized = YES;
}
}
+ (MenuBarHider *)sharedInstance
{
return sharedInstance;
}
- (id)init
{
if (sharedInstance)
{
[self dealloc];
return sharedInstance;
}
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if ([[NSApplication sharedApplication] isActive]
&&[[change objectForKey:@"new"] integerValue] == 0)
{
#ifdef DEBUG
NSLog(@"We need to change SystemUIMode back to auto-hide the menu bar.");
#endif
SetSystemUIMode(kUIModeAllSuppressed, 0);
}
}
@end