diff options
| author | Teddy Wing | 2021-03-07 01:44:50 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2021-03-07 01:44:50 +0100 | 
| commit | ee7e780efde86970e68e6ab4af6aa1b11d4ac88b (patch) | |
| tree | 7ec7bd79445df573eed9d77c181e2610432d0415 /main.m | |
| parent | 1b29751aca6376d7392356ed8e53048952150606 (diff) | |
| download | Re-Good-Catalina-Invert-Colours-ee7e780efde86970e68e6ab4af6aa1b11d4ac88b.tar.bz2 | |
Register a global hotkey
Build DDHotKey as a static library so we can compile it with ARC turned
on and our project with ARC turned off. Since DDHotKey is written with
ARC, if I include its headers directly, I'd need to enable ARC on my
project in order to compile it.
Initialise an `NSApplication` to give us an environment in which to
register the global hotkey.
A new class `Invert` will respond to the hotkey and respond accordingly.
Diffstat (limited to 'main.m')
| -rw-r--r-- | main.m | 30 | 
1 files changed, 28 insertions, 2 deletions
| @@ -1,8 +1,28 @@ +#import <Carbon/Carbon.h>  #import <CoreGraphics/CoreGraphics.h> +#import "Invert.h" +#import "DDHotKeyCenter.h" +  #define MAX_DISPLAYS 8  int main(int argc, const char * argv[]) { +    [NSApplication sharedApplication]; + +    Invert *invert = [[Invert alloc] init]; + +    DDHotKeyCenter *c = [DDHotKeyCenter sharedHotKeyCenter]; +    if ( +        ![c registerHotKeyWithKeyCode:kVK_ANSI_8 +            modifierFlags: +                (NSEventModifierFlagControl | NSEventModifierFlagOption | NSEventModifierFlagCommand) +            target:invert +            action:@selector(toggleInvertColors:) +            object:nil] +    ) { +        NSLog(@"Error registering hotkey"); +    } +      const CGGammaValue inverted_gamma[2] = {1, 0};      CGDirectDisplayID active_displays[MAX_DISPLAYS]; @@ -30,9 +50,15 @@ int main(int argc, const char * argv[]) {          }      } -    sleep(4); +    // for (;;) {} +    // sleep(4); +    // +    // CGDisplayRestoreColorSyncSettings(); + +    // TODO: trap? +    // [invert release]; -    CGDisplayRestoreColorSyncSettings(); +    [NSApp run];      return 0;  } | 
