16696a101c22e745e60125a8e60fda896ca57c5d
[~jspiros/WindowBlur.git] / WindowBlurWindowHack.m
1 //
2 //  WindowBlurWindowHack.m
3 //  WindowBlur
4 //
5 //  Created by Joseph Spiros on 5/12/09.
6 //  Copyright 2009 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "WindowBlurSIMBL.h"
10 #import "WindowBlurWindowHack.h"
11 #import "CGSInternal.h"
12
13 static NSMutableDictionary *instanceIDToIvars = nil;
14 static BOOL needToSwizzleDealloc = YES;
15
16 @implementation WindowBlurWindowHack
17
18 - (id)PRE__instanceID
19 {
20     return [NSValue valueWithPointer:self];
21 }
22
23 - (NSMutableDictionary *)PRE__ivars
24 {
25     NSMutableDictionary *ivars;
26     
27     if (needToSwizzleDealloc)
28     {
29         MethodSwizzle([NSWindow class], 
30                       @selector(dealloc), 
31                       @selector(PRE__deallocSwizzler));
32         needToSwizzleDealloc = NO;
33     }
34         
35     if (instanceIDToIvars == nil)
36     {
37         instanceIDToIvars = [[NSMutableDictionary alloc] init];
38     }
39     
40     ivars = [instanceIDToIvars objectForKey:[self PRE__instanceID]];
41     if (ivars == nil)
42     {
43         ivars = [NSMutableDictionary dictionary];
44         [instanceIDToIvars setObject:ivars forKey:[self PRE__instanceID]];
45     }
46     
47     return ivars;
48 }
49
50 - (void)PRE__deallocSwizzler
51 {
52     [instanceIDToIvars removeObjectForKey:[self PRE__instanceID]];
53     if ([instanceIDToIvars count] == 0)
54     {
55         [instanceIDToIvars release];
56         instanceIDToIvars = nil;
57     }
58     
59     [self PRE__deallocSwizzler];
60 }
61
62 - (void)update {
63         if ([[[self PRE__ivars] objectForKey:@"blurred"] boolValue] != YES) {
64 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
65                 if (floor(NSAppKitVersionNumber) > 824) {
66                         NSLog(@"AppKit Check Confirmed");
67                         CGSConnectionID con = CGSMainConnectionID();
68                         if (con) {
69                                 NSLog(@"CGSConnection Confirmed");
70                                 int blurFilter;
71                                 if (noErr == CGSNewCIFilterByName(con, (CFStringRef)@"CIGaussianBlur", &blurFilter)) {
72                                         NSLog(@"Should work!");
73                                         NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:2.0] forKey:@"inputRadius"];
74                                         CGSSetCIFilterValuesFromDictionary(con, blurFilter, (CFDictionaryRef)optionsDict);
75                                         CGSAddWindowFilter(con, [self windowNumber], blurFilter, kCGWindowFilterUnderlay);
76                                         [[self PRE__ivars] setObject:[NSNumber numberWithBool:YES] forKey:@"blurred"];
77                                 }
78                         }                       
79                 }
80 #endif
81         }
82 }
83
84 @end