-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowBlurSIMBL.m
128 lines (107 loc) · 3.51 KB
/
WindowBlurSIMBL.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// WindowBlurSIMBL.m
// WindowBlur
//
// Created by Joseph Spiros on 5/12/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "WindowBlurSIMBL.h"
#import "CGSInternal.h"
#import <objc/objc-class.h>
void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel)
{
Method orig_method = nil, alt_method = nil;
// First, look for the methods
orig_method = class_getInstanceMethod(aClass, orig_sel);
alt_method = class_getInstanceMethod(aClass, alt_sel);
// If both are found, swizzle them
if ((orig_method != nil) && (alt_method != nil))
{
char *temp1;
IMP temp2;
temp1 = orig_method->method_types;
orig_method->method_types = alt_method->method_types;
alt_method->method_types = temp1;
temp2 = orig_method->method_imp;
orig_method->method_imp = alt_method->method_imp;
alt_method->method_imp = temp2;
}
}
static NSMutableDictionary *instanceIDToIvars = nil;
static BOOL needToSwizzleDealloc = YES;
@implementation WindowBlurWindowHack
- (id)PRE__instanceID
{
return [NSValue valueWithPointer:self];
}
- (NSMutableDictionary *)PRE__ivars
{
NSMutableDictionary *ivars;
if (needToSwizzleDealloc)
{
MethodSwizzle([NSWindow class],
@selector(dealloc),
@selector(PRE__deallocSwizzler));
needToSwizzleDealloc = NO;
}
if (instanceIDToIvars == nil)
{
instanceIDToIvars = [[NSMutableDictionary alloc] init];
}
ivars = [instanceIDToIvars objectForKey:[self PRE__instanceID]];
if (ivars == nil)
{
ivars = [NSMutableDictionary dictionary];
[instanceIDToIvars setObject:ivars forKey:[self PRE__instanceID]];
}
return ivars;
}
- (void)PRE__deallocSwizzler
{
[instanceIDToIvars removeObjectForKey:[self PRE__instanceID]];
if ([instanceIDToIvars count] == 0)
{
[instanceIDToIvars release];
instanceIDToIvars = nil;
}
[self PRE__deallocSwizzler];
}
- (void)display {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if (floor(NSAppKitVersionNumber) > 824) {
NSString *filterName;
if (!(filterName = [[NSUserDefaults standardUserDefaults] stringForKey:@"WindowBlurSIMBL-FilterName"])) {
filterName = @"CIGaussianBlur";
}
NSDictionary *filterValues;
if (!(filterValues = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"WindowBlurSIMBL-FilterValues"])) {
filterValues = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:2.0] forKey:@"inputRadius"];
}
NSMutableDictionary *optionsDict = [NSMutableDictionary dictionaryWithDictionary:filterValues];
if (![optionsDict objectForKey:@"inputCenter"]) {
[optionsDict setObject:[CIVector vectorWithX:0.0 Y:0.0] forKey:@"inputCenter"];
}
CGSConnectionID con = CGSMainConnectionID();
if (con) {
NSNumber *filterNumber;
int filter;
if (filterNumber = [[self PRE__ivars] objectForKey:@"filter"]) {
filter = [filterNumber intValue];
CGSRemoveWindowFilter(con, [self windowNumber], filter);
}
if (noErr == CGSNewCIFilterByName(con, (CFStringRef)filterName, &filter)) {
CGSSetCIFilterValuesFromDictionary(con, filter, (CFDictionaryRef)optionsDict);
CGSAddWindowFilter(con, [self windowNumber], filter, kCGWindowFilterUnderlay);
[[self PRE__ivars] setObject:[NSNumber numberWithInt:filter] forKey:@"filter"];
}
}
}
#endif
[super display];
}
@end
@implementation WindowBlurSIMBL
+ (void)load {
[WindowBlurWindowHack poseAsClass:[NSWindow class]];
}
@end