-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathTRCIFilterWindow.m
141 lines (116 loc) · 3.03 KB
/
TRCIFilterWindow.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
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// TRCIEffectOverlay.m
// Tranquility
//
// Assumed by Lorenzo Swank on 2014 FEB 05 and
// updated for Mac OS 10.9.
//
// Orginally Created by Nicholas Jitkoff on 5/8/07 as Nocturne.
// Licensed under the Apache 2.0 license and distributed as such
// on https://code.google.com/p/blacktree-nocturne
//
#import "TRCIFilterWindow.h"
CGSConnection cid;
void DXSetWindowTag(int wid, CGSWindowTag tag, int state)
{
CGSConnection cid;
cid = _CGSDefaultConnection();
CGSWindowTag tags[2];
tags[0] = tags[1] = 0;
OSStatus retVal = CGSGetWindowTags(cid, wid, tags, 32);
if (!retVal)
{
tags[0] = tag;
if (state)
{
retVal = CGSSetWindowTags(cid, wid, tags, 32);
if (retVal)
{
NSLog(@"CGSSetWindowTags returned %d", retVal);
}
}
else
{
retVal = CGSClearWindowTags(cid, wid, tags, 32);
if (retVal)
{
NSLog(@"CGSClearWindowTags returned %d", retVal);
}
}
}
}
void DXSetWindowIgnoresMouse(int wid, int state)
{
DXSetWindowTag(wid, CGSTagTransparent, state);
}
#define NSRectToCGRect(r) CGRectMake(r.origin.x, r.origin.y, r.size.width, r.size.height)
CGRect TRCGRectFromScreenFrame(NSRect rect)
{
CGRect screenBounds = CGDisplayBounds(kCGDirectMainDisplay);
CGRect cgrect = NSRectToCGRect(rect);
cgrect.origin.y += screenBounds.size.height;
cgrect.origin.y -= rect.size.height;
return cgrect;
}
CGSConnection cid;
@implementation TRCIFilterWindow
+ (void)initialize
{
cid = _CGSDefaultConnection();
}
- (id)init
{
self = [self initWithContentRect:[[NSScreen mainScreen] frame]
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
if (self != nil)
{
[self setHidesOnDeactivate:NO];
[self setCanHide:NO];
[self setIgnoresMouseEvents:YES];
[self setLevel:CGWindowLevelForKey(kCGCursorWindowLevelKey)];
[self setOpaque:NO];
[self setBackgroundColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.0]];
wid = [self windowNumber];
}
return self;
}
- (void)dealloc
{
[self setFilter:nil];
[super dealloc];
}
- (void)setFilter:(NSString*)filterName
{
if (fid)
{
CGSRemoveWindowFilter(cid, wid, fid);
CGSReleaseCIFilter(cid, fid);
}
if (filterName)
{
CGError error = CGSNewCIFilterByName(cid, (CFStringRef)filterName, &fid);
if (noErr == error)
{
error = CGSAddWindowFilter(cid, wid, fid, 0x00003001);
if (error)
{
NSLog(@"addfilter err %d", error);
}
}
if (error)
{
NSLog(@"setfilter err %d", error);
}
}
}
- (void)setFilterValues:(NSDictionary*)filterValues
{
if (!fid)
{
return;
}
CGSSetCIFilterValuesFromDictionary(cid, fid, (CFDictionaryRef)filterValues);
}
@end