aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Invert.h7
-rw-r--r--Invert.m10
-rw-r--r--Makefile44
-rw-r--r--main.m30
5 files changed, 88 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..84c048a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/build/
diff --git a/Invert.h b/Invert.h
new file mode 100644
index 0000000..c84685e
--- /dev/null
+++ b/Invert.h
@@ -0,0 +1,7 @@
+#import <Cocoa/Cocoa.h>
+
+@interface Invert : NSObject
+
+- (void)toggleInvertColors:(NSEvent *)event;
+
+@end
diff --git a/Invert.m b/Invert.m
new file mode 100644
index 0000000..a41eb46
--- /dev/null
+++ b/Invert.m
@@ -0,0 +1,10 @@
+#import "Invert.h"
+
+@implementation Invert
+
+- (void)toggleInvertColors:(NSEvent *)event
+{
+ NSLog(@"Toggling");
+}
+
+@end
diff --git a/Makefile b/Makefile
index ef9d048..5baa173 100644
--- a/Makefile
+++ b/Makefile
@@ -1,2 +1,42 @@
-all:
- clang -x objective-c -framework CoreGraphics -o invert-catalina-invert main.m
+# SOURCES := $(shell find . -not -path './lib/*' -and \( -name '*.h' -or -name '*.m' \))
+SOURCES := $(shell ls *.{h,m})
+
+DDHOTKEY_OBJ := $(patsubst %.m,%.o,$(wildcard lib/DDHotKey/*.m))
+
+
+all: $(SOURCES) build/libddhotkey.a build/include/*.h
+ clang -x objective-c \
+ -framework Carbon \
+ -framework Cocoa \
+ -framework CoreGraphics \
+ -framework Foundation \
+ -fno-objc-arc \
+ -I./build/include \
+ -L./build \
+ -lddhotkey \
+ -o invert-catalina-invert \
+ $(SOURCES)
+
+build/include/*.h: lib/DDHotKey/*.h
+ cp $^ build/include/
+
+# build/libddhotkey.o: lib/DDHotKey/*.h lib/DDHotKey/*.m
+lib/DDHotKey/%.o: lib/DDHotKey/%.m
+ clang -x objective-c \
+ -w \
+ -framework Carbon \
+ -framework Cocoa \
+ -framework Foundation \
+ -fobjc-arc \
+ -c \
+ $^
+
+ mv *.o lib/DDHotKey/
+
+lib/DDHotKey/*.o: lib/DDHotKey/*.m
+
+build/libddhotkey.a: $(DDHOTKEY_OBJ)
+# build/libddhotkey.a: lib/DDHotKey/*.o
+ libtool -static \
+ -o $@ \
+ $^
diff --git a/main.m b/main.m
index 9ea3d37..8ffc3b2 100644
--- a/main.m
+++ b/main.m
@@ -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;
}