Created
November 10, 2015 04:54
-
-
Save ccgus/91c9e7cad695ccdd0626 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Carbon/Carbon.h> | |
static OSStatus handleAppFrontSwitched(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData); | |
EventHandlerRef MySkankyGlobalFrontAppSwitchedHandlerRef; | |
@implementation JSTWhatever | |
+ (void)load { | |
EventTypeSpec spec = { kEventClassApplication, kEventAppFrontSwitched }; | |
OSStatus err = InstallApplicationEventHandler(NewEventHandlerUPP(handleAppFrontSwitched), 1, &spec, nil, &MySkankyGlobalFrontAppSwitchedHandlerRef); | |
if (err) { | |
NSLog(@"Error looking for front app."); | |
} | |
} | |
@end | |
static OSStatus handleAppFrontSwitched(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData) { | |
if ((GetCurrentKeyModifiers() & shiftKey) != 0) { | |
return 0; | |
} | |
NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; | |
NSDictionary *activeAppDict = [workspace activeApplication]; | |
ProcessSerialNumber psn; | |
psn.highLongOfPSN = [[activeAppDict objectForKey:@"NSApplicationProcessSerialNumberHigh"] intValue]; | |
psn.lowLongOfPSN = [[activeAppDict objectForKey:@"NSApplicationProcessSerialNumberLow"] intValue]; | |
SetFrontProcess( &psn ); | |
// this .. causes a bit o' recursion for some reason. | |
//ProcessSerialNumber xpsn = { 0, kCurrentProcess }; | |
//SetFrontProcess( & xpsn ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment