[vlc-devel] commit: macosx: implement controll support for the Media Keys on Brushed Al Apple keyboards ( Felix Paul Kühne )
git version control
git at videolan.org
Fri Apr 10 15:53:13 CEST 2009
vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Fri Apr 10 15:53:07 2009 +0200| [408f769e5768bf1c8dbc840bef1c560a91de6d5f] | committer: Felix Paul Kühne
macosx: implement controll support for the Media Keys on Brushed Al Apple keyboards
I'll add an option to disable this feature later on
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=408f769e5768bf1c8dbc840bef1c560a91de6d5f
---
NEWS | 1 +
modules/gui/macosx/intf.h | 14 +++++++++
modules/gui/macosx/intf.m | 68 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 81 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 6be038a..4febfff 100644
--- a/NEWS
+++ b/NEWS
@@ -72,6 +72,7 @@ Linux/Windows interface:
* Better integration in GTK environments
Mac OS X Interface:
+ * Controllable by the Media Keys on modern Apple keyboards (brushed Aluminium)
* Reveal-in-Finder functionality for locally stored items.
* Easy addition of Subtitles through the Video menu
* Additional usability improvements
diff --git a/modules/gui/macosx/intf.h b/modules/gui/macosx/intf.h
index 1bbb4d7..81c71aa 100644
--- a/modules/gui/macosx/intf.h
+++ b/modules/gui/macosx/intf.h
@@ -424,3 +424,17 @@ static void MsgCallback( msg_cb_data_t *, msg_item_t *, unsigned );
@interface VLCMain (Internal)
- (void)handlePortMessage:(NSPortMessage *)o_msg;
@end
+
+/*****************************************************************************
+ * VLCApplication interface
+ *****************************************************************************/
+
+ at interface VLCApplication : NSApplication
+{
+ BOOL b_justJumped;
+}
+
+- (void)sendEvent: (NSEvent*)event;
+- (void)resetJump;
+
+ at end
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index a1503c9..e7d1b63 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -56,7 +56,8 @@
#import "simple_prefs.h"
#import "vlm.h"
-#import <AddressBook/AddressBook.h>
+#import <AddressBook/AddressBook.h> /* for crashlog send mechanism */
+#import <IOKit/hidsystem/ev_keymap.h> /* for the media key support */
/*****************************************************************************
* Local prototypes.
@@ -132,7 +133,7 @@ static void Run( intf_thread_t *p_intf )
/* Install a jmpbuffer to where we can go back before the NSApp exit
* see applicationWillTerminate: */
- [NSApplication sharedApplication];
+ [VLCApplication sharedApplication];
[[VLCMain sharedInstance] setIntf: p_intf];
[NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
@@ -2766,3 +2767,66 @@ end:
}
@end
+
+/*****************************************************************************
+ * VLCApplication interface
+ * exclusively used to implement media key support on Al Apple keyboards
+ * b_justJumped is required as the keyboard send its events faster than
+ * the user can actually jump through his media
+ *****************************************************************************/
+
+ at implementation VLCApplication
+
+- (void)sendEvent: (NSEvent*)event
+{
+ if( [event type] == NSSystemDefined && [event subtype] == 8 )
+ {
+ int keyCode = (([event data1] & 0xFFFF0000) >> 16);
+ int keyFlags = ([event data1] & 0x0000FFFF);
+ int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
+ int keyRepeat = (keyFlags & 0x1);
+
+ if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
+ var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
+
+ if( keyCode == NX_KEYTYPE_FAST && !b_justJumped )
+ {
+ if( keyState == 0 && keyRepeat == 0 )
+ {
+ var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
+ }
+ else if( keyRepeat == 1 )
+ {
+ var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
+ b_justJumped = YES;
+ [self performSelector:@selector(resetJump)
+ withObject: NULL
+ afterDelay:0.25];
+ }
+ }
+
+ if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
+ {
+ if( keyState == 0 && keyRepeat == 0 )
+ {
+ var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
+ }
+ else if( keyRepeat == 1 )
+ {
+ var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
+ b_justJumped = YES;
+ [self performSelector:@selector(resetJump)
+ withObject: NULL
+ afterDelay:0.25];
+ }
+ }
+ }
+ [super sendEvent: event];
+}
+
+- (void)resetJump
+{
+ b_justJumped = NO;
+}
+
+ at end
More information about the vlc-devel
mailing list