forked from ciaran/Blurminal
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Blurminal.m
63 lines (50 loc) · 2.11 KB
/
Blurminal.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
#import "Blurminal.h"
#import "JRSwizzle.h"
typedef void* CGSConnectionID;
extern OSStatus CGSNewConnection (const void** attr, CGSConnectionID* id);
@implementation NSWindow (TTWindow)
// Found here:
// http://www.aeroxp.org/board/index.php?s=d18e98cabed9ce5ad27f9449b4e2298f&showtopic=8984&pid=116022&st=0&#entry116022
- (void)enableBlur
{
CGSConnectionID _myConnection;
CGSNewConnection(NULL , &_myConnection);
uint32_t __compositingFilter = 0;
CGSNewCIFilterByName (_myConnection, (CFStringRef)@"CIGaussianBlur", &__compositingFilter);
NSDictionary* optionsDict = [NSDictionary dictionaryWithObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"Blurminal Radius"] forKey:@"inputRadius"];
CGSSetCIFilterValuesFromDictionary(_myConnection, __compositingFilter, (CFDictionaryRef)optionsDict);
CGSAddWindowFilter(_myConnection, [self windowNumber], __compositingFilter, 1);
}
- (void)enableBlurIfCorrectWindow:(BOOL)delay
{
if([self isKindOfClass:NSClassFromString(@"TTWindow")] || [self isKindOfClass:NSClassFromString(@"VisorWindow")])
{
if (delay == TRUE) {
[self performSelector:@selector(enableBlur) withObject:nil afterDelay:0]; // FIXME
} else {
[self enableBlur];
}
}
}
- (id)Blurred_initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
{
if(self = [self Blurred_initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation])
{
// The window has to be onscreen to get a windowNumber, so we run the enableBlur after the event loop
[self enableBlurIfCorrectWindow:TRUE];
}
return self;
}
@end
@implementation Blurminal
+ (void)load
{
for (id window in [NSApp orderedWindows]) {
[window enableBlurIfCorrectWindow:FALSE];
}
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:1.0],@"Blurminal Radius",
nil]];
[[NSWindow class] jr_swizzleMethod:@selector(initWithContentRect:styleMask:backing:defer:) withMethod:@selector(Blurred_initWithContentRect:styleMask:backing:defer:) error:NULL];
}
@end