aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-10-07 05:21:21 +0200
committerTeddy Wing2018-10-07 06:00:38 +0200
commit8865b27d5436d6dcf6359c6f3eb9b3f9c17ad43a (patch)
tree88931110470b060280859632864b17ea371fadb5
parent55cde050a168a09c2691081da38064821d492f66 (diff)
downloadDomeKey-8865b27d5436d6dcf6359c6f3eb9b3f9c17ad43a.tar.bz2
Try listening to media keys
Use Peter Maurer's mechanism for getting media key events. Code taken from a Rogue Amoeba article. My hope was that this would allow us to intercept Bluetooth headphone key presses. It didn't. I'll likely be reverting this code.
-rw-r--r--DomeKey/DKApplication.h2
-rw-r--r--DomeKey/DKApplication.m38
-rw-r--r--DomeKey/main.m3
3 files changed, 42 insertions, 1 deletions
diff --git a/DomeKey/DKApplication.h b/DomeKey/DKApplication.h
index 6a92266..70ccd3a 100644
--- a/DomeKey/DKApplication.h
+++ b/DomeKey/DKApplication.h
@@ -10,4 +10,6 @@
@interface DKApplication : NSApplication
+- (void)mediaKeyEvent:(int)key state:(BOOL)state repeat:(BOOL)repeat;
+
@end
diff --git a/DomeKey/DKApplication.m b/DomeKey/DKApplication.m
index 9449d06..4098ca7 100644
--- a/DomeKey/DKApplication.m
+++ b/DomeKey/DKApplication.m
@@ -10,4 +10,42 @@
@implementation DKApplication
+// https://weblog.rogueamoeba.com/2007/09/29/
+- (void)sendEvent:(NSEvent *)theEvent
+{
+ if ([theEvent type] == NSSystemDefined && [theEvent subtype] == 8) {
+ int key_code = (([theEvent data1] & 0xFFFF0000) >> 16);
+ int key_flags = ([theEvent data1] & 0x0000FFFF);
+ int key_state = (((key_flags & 0xFF00) >> 8)) == 0xA;
+ int key_repeat = (key_flags & 0x1);
+
+ [self mediaKeyEvent:key_code state:key_state repeat:key_repeat];
+ }
+
+ [super sendEvent:theEvent];
+}
+
+// https://weblog.rogueamoeba.com/2007/09/29/
+- (void)mediaKeyEvent:(int)key state:(BOOL)state repeat:(BOOL)repeat
+{
+ BOOL pressed_and_released = !state;
+
+ if (pressed_and_released) {
+ switch (key) {
+ case NX_KEYTYPE_PLAY:
+ NSLog(@"Play");
+
+ break;
+ case NX_KEYTYPE_FAST:
+ NSLog(@"Fast");
+
+ break;
+ case NX_KEYTYPE_REWIND:
+ NSLog(@"Rewind");
+
+ break;
+ }
+ }
+}
+
@end
diff --git a/DomeKey/main.m b/DomeKey/main.m
index aa2c66f..825e600 100644
--- a/DomeKey/main.m
+++ b/DomeKey/main.m
@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
+#import "DKApplication.h"
#import "AppDelegate.h"
#import "Mappings.h"
#import "dome_key_map.h"
@@ -18,7 +19,7 @@ int main(int argc, const char * argv[]) {
return [Mappings dispatchReload];
} else if (config->args.daemon) {
@autoreleasepool {
- [NSApplication sharedApplication];
+ [DKApplication sharedApplication];
AppDelegate *app = [[AppDelegate alloc] init];
[NSApp setDelegate:app];