5 // Created by Joseph Spiros on 5/12/09.
6 // Copyright 2009 __MyCompanyName__. All rights reserved.
9 #import "WindowBlurSIMBL.h"
10 #import "CGSInternal.h"
11 #import <objc/objc-class.h>
13 void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel)
15 Method orig_method = nil, alt_method = nil;
17 // First, look for the methods
18 orig_method = class_getInstanceMethod(aClass, orig_sel);
19 alt_method = class_getInstanceMethod(aClass, alt_sel);
21 // If both are found, swizzle them
22 if ((orig_method != nil) && (alt_method != nil))
27 temp1 = orig_method->method_types;
28 orig_method->method_types = alt_method->method_types;
29 alt_method->method_types = temp1;
31 temp2 = orig_method->method_imp;
32 orig_method->method_imp = alt_method->method_imp;
33 alt_method->method_imp = temp2;
37 static NSMutableDictionary *instanceIDToIvars = nil;
38 static BOOL needToSwizzleDealloc = YES;
40 @implementation WindowBlurWindowHack
44 return [NSValue valueWithPointer:self];
47 - (NSMutableDictionary *)PRE__ivars
49 NSMutableDictionary *ivars;
51 if (needToSwizzleDealloc)
53 MethodSwizzle([NSWindow class],
55 @selector(PRE__deallocSwizzler));
56 needToSwizzleDealloc = NO;
59 if (instanceIDToIvars == nil)
61 instanceIDToIvars = [[NSMutableDictionary alloc] init];
64 ivars = [instanceIDToIvars objectForKey:[self PRE__instanceID]];
67 ivars = [NSMutableDictionary dictionary];
68 [instanceIDToIvars setObject:ivars forKey:[self PRE__instanceID]];
74 - (void)PRE__deallocSwizzler
76 [instanceIDToIvars removeObjectForKey:[self PRE__instanceID]];
77 if ([instanceIDToIvars count] == 0)
79 [instanceIDToIvars release];
80 instanceIDToIvars = nil;
83 [self PRE__deallocSwizzler];
87 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
88 if (floor(NSAppKitVersionNumber) > 824) {
90 if (!(filterName = [[NSUserDefaults standardUserDefaults] stringForKey:@"WindowBlurSIMBL-FilterName"])) {
91 filterName = @"CIGaussianBlur";
93 NSDictionary *filterValues;
94 if (!(filterValues = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"WindowBlurSIMBL-FilterValues"])) {
95 filterValues = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:2.0] forKey:@"inputRadius"];
97 NSMutableDictionary *optionsDict = [NSMutableDictionary dictionaryWithDictionary:filterValues];
98 if (![optionsDict objectForKey:@"inputCenter"]) {
99 [optionsDict setObject:[CIVector vectorWithX:0.0 Y:0.0] forKey:@"inputCenter"];
101 CGSConnectionID con = CGSMainConnectionID();
103 NSNumber *filterNumber;
105 if (filterNumber = [[self PRE__ivars] objectForKey:@"filter"]) {
106 filter = [filterNumber intValue];
107 CGSRemoveWindowFilter(con, [self windowNumber], filter);
109 if (noErr == CGSNewCIFilterByName(con, (CFStringRef)filterName, &filter)) {
110 CGSSetCIFilterValuesFromDictionary(con, filter, (CFDictionaryRef)optionsDict);
111 CGSAddWindowFilter(con, [self windowNumber], filter, kCGWindowFilterUnderlay);
112 [[self PRE__ivars] setObject:[NSNumber numberWithInt:filter] forKey:@"filter"];
122 @implementation WindowBlurSIMBL
125 [WindowBlurWindowHack poseAsClass:[NSWindow class]];