由于某种原因,涉及使用私有 API CGSAddWindowFilter() 的旧技巧似乎不再适用于 Mavericks。我尝试了一些在 OS X 中屏幕颜色反转如何工作中描述的代码?下面的代码会导致以下窗口。
#import "AppDelegate.h"
//Declarations to avoid compiler warnings (because of private APIs):
typedef void * CGSConnection;
typedef void * CGSWindowID;
extern OSStatus CGSNewConnection(const void **attributes, CGSConnection * id);
typedef void *CGSWindowFilterRef;
extern CGError CGSNewCIFilterByName(CGSConnection cid, CFStringRef filterName, CGSWindowFilterRef *outFilter);
extern CGError CGSAddWindowFilter(CGSConnection cid, CGSWindowID wid, CGSWindowFilterRef filter, int flags);
extern CGError CGSSetCIFilterValuesFromDictionary(CGSConnection cid, CGSWindowFilterRef filter, CFDictionaryRef filterValues);
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self.window setOpaque:NO];
[self.window setAlphaValue:1.0];
[self.window setBackgroundColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.1]];
self.window.level = NSDockWindowLevel;
CGSConnection thisConnection;
CGSWindowFilterRef compositingFilter;
int compositingType = 1; // under the window
/* Make a new connection to CoreGraphics */
CGSNewConnection(NULL, &thisConnection);
/* Create a CoreImage filter and set it up */
CGSNewCIFilterByName(thisConnection, CFSTR("CIColorInvert"), &compositingFilter);
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:3.0] forKey:@"inputRadius"];
CGSSetCIFilterValuesFromDictionary(thisConnection, compositingFilter, (__bridge CFDictionaryRef)options);
/* Now apply the filter to the window */
CGSAddWindowFilter(thisConnection, (CGSWindowID)[self.window windowNumber], compositingFilter, compositingType);
}
@end
任何人都知道像在 OSX 10.8 中那样将过滤器应用到背景的技巧吗?
我需要这个才能让MenuBarFilter在 Mavericks 中再次工作。