summaryrefslogtreecommitdiffstats
path: root/osdep/macosx_events.m
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-06-03 00:52:40 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-06-03 22:35:47 +0200
commit72f2942dfa575a57d61fe023c845ba711ab78f55 (patch)
treed62395e98d5ee0ae58a5779bd8b472ee90aa9a80 /osdep/macosx_events.m
parentc39efb96d1109b7a5960cd17cc4c392c2b93b61b (diff)
downloadmpv-72f2942dfa575a57d61fe023c845ba711ab78f55.tar.bz2
mpv-72f2942dfa575a57d61fe023c845ba711ab78f55.tar.xz
osx: add Apple Remote support
After killing the non functional AR support in c8fd9e5 I got much complaints so this adds AR support back in (and it works). I am using the HIDRemote class by Felix Schwarz and that part of the code is under the BSD license. I slightly modified it replacing [NSApplication sharedApplication] with NSApp. The code of the class is quite complex (probably because it had to deal with all the edge cases with IOKit) but it works nicely as a black box. In a later commit I'll remove the deprecation warnings caused by HIDRemote's usage of Gestalt. Check out `etc/input.conf` for the default bindings. Apple Remote functionality is automatically compiled in when cocoa is enabled. It can be disabled at runtime with the `--no-ar` option.
Diffstat (limited to 'osdep/macosx_events.m')
-rw-r--r--osdep/macosx_events.m61
1 files changed, 59 insertions, 2 deletions
diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m
index 26853628b3..86d0ebaa3e 100644
--- a/osdep/macosx_events.m
+++ b/osdep/macosx_events.m
@@ -3,12 +3,12 @@
*
* This file is part of mpv.
*
- * mplayer2 is free software; you can redistribute it and/or modify
+ * mpv is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
- * mplayer2 is distributed in the hope that it will be useful,
+ * mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
@@ -92,6 +92,18 @@ static int convert_key(unsigned key, unsigned charcode)
return charcode;
}
+void cocoa_start_apple_remote(void)
+{
+ Application *app = mpv_shared_app();
+ [app.eventsResponder startAppleRemote];
+}
+
+void cocoa_stop_apple_remote(void)
+{
+ Application *app = mpv_shared_app();
+ [app.eventsResponder stopAppleRemote];
+}
+
void cocoa_check_events(void)
{
Application *app = mpv_shared_app();
@@ -106,6 +118,23 @@ void cocoa_put_key(int keycode)
}
@implementation EventsResponder
+- (void)startAppleRemote
+{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.remote = [[[HIDRemote alloc] init] autorelease];
+ if (self.remote) {
+ [self.remote setDelegate:self];
+ [self.remote startRemoteControl:kHIDRemoteModeExclusiveAuto];
+ }
+ });
+
+}
+- (void)stopAppleRemote
+{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self.remote stopRemoteControl];
+ });
+}
- (NSArray *) keyEquivalents
{
return @[@"h", @"q", @"Q", @"0", @"1", @"2"];
@@ -158,4 +187,32 @@ void cocoa_put_key(int keycode)
return nil;
}
+- (void)hidRemote:(HIDRemote *)remote
+ eventWithButton:(HIDRemoteButtonCode)buttonCode
+ isPressed:(BOOL)isPressed
+ fromHardwareWithAttributes:(NSMutableDictionary *)attributes
+{
+ if (!isPressed) return;
+
+ NSDictionary *keymap = @{
+ @(kHIDRemoteButtonCodePlay): @(MP_AR_PLAY),
+ @(kHIDRemoteButtonCodePlayHold): @(MP_AR_PLAY_HOLD),
+ @(kHIDRemoteButtonCodeCenter): @(MP_AR_CENTER),
+ @(kHIDRemoteButtonCodeCenterHold): @(MP_AR_CENTER_HOLD),
+ @(kHIDRemoteButtonCodeLeft): @(MP_AR_PREV),
+ @(kHIDRemoteButtonCodeLeftHold): @(MP_AR_PREV_HOLD),
+ @(kHIDRemoteButtonCodeRight): @(MP_AR_NEXT),
+ @(kHIDRemoteButtonCodeRightHold): @(MP_AR_NEXT_HOLD),
+ @(kHIDRemoteButtonCodeMenu): @(MP_AR_MENU),
+ @(kHIDRemoteButtonCodeMenuHold): @(MP_AR_MENU_HOLD),
+ @(kHIDRemoteButtonCodeUp): @(MP_AR_VUP),
+ @(kHIDRemoteButtonCodeUpHold): @(MP_AR_VUP_HOLD),
+ @(kHIDRemoteButtonCodeDown): @(MP_AR_VDOWN),
+ @(kHIDRemoteButtonCodeDownHold): @(MP_AR_VDOWN_HOLD),
+ };
+
+ int key = [keymap[@(buttonCode)] intValue];
+ if (key > 0)
+ cocoa_put_key(key);
+}
@end