Commit 55f33b61 authored by Eric Petit's avatar Eric Petit

Adds support for Apple's remote (only handles Play/Pause at the moment).

AppleRemote.[mh] is MIT licensed code from Martin Kahr:
http://www.martinkahr.com/source-code
parent ee5179d0
...@@ -348,6 +348,8 @@ VLC-release.app: vlc ...@@ -348,6 +348,8 @@ VLC-release.app: vlc
mkdir -p $(top_builddir)/tmp/modules/audio_output mkdir -p $(top_builddir)/tmp/modules/audio_output
mkdir -p $(top_builddir)/tmp/modules/gui/macosx mkdir -p $(top_builddir)/tmp/modules/gui/macosx
for i in \ for i in \
AppleRemote.h \
AppleRemote.m \
about.h \ about.h \
about.m \ about.m \
applescript.h \ applescript.h \
...@@ -486,6 +488,8 @@ VLC.app: vlc ...@@ -486,6 +488,8 @@ VLC.app: vlc
mkdir -p $(top_builddir)/tmp/modules/audio_output mkdir -p $(top_builddir)/tmp/modules/audio_output
mkdir -p $(top_builddir)/tmp/modules/gui/macosx mkdir -p $(top_builddir)/tmp/modules/gui/macosx
for i in \ for i in \
AppleRemote.h \
AppleRemote.m \
about.h \ about.h \
about.m \ about.m \
applescript.h \ applescript.h \
......
//
// AppleRemote.h
// AppleRemote
//
// Created by Martin Kahr on 11.03.06.
// Copyright 2006 martinkahr.com. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import <mach/mach.h>
#import <mach/mach_error.h>
#import <IOKit/IOKitLib.h>
#import <IOKit/IOCFPlugIn.h>
#import <IOKit/hid/IOHIDLib.h>
#import <IOKit/hid/IOHIDKeys.h>
enum AppleRemoteEventIdentifier
{
kRemoteButtonVolume_Plus=0,
kRemoteButtonVolume_Minus,
kRemoteButtonMenu,
kRemoteButtonPlay,
kRemoteButtonRight,
kRemoteButtonLeft,
kRemoteButtonRight_Hold,
kRemoteButtonLeft_Hold,
kRemoteButtonMenu_Hold,
kRemoteButtonPlay_Sleep,
kRemoteControl_Switched
};
typedef enum AppleRemoteEventIdentifier AppleRemoteEventIdentifier;
/* Encapsulates usage of the apple remote control
This class is implemented as a singleton as there is exactly one remote per machine (until now)
The class is not thread safe
*/
@interface AppleRemote : NSObject {
IOHIDDeviceInterface** hidDeviceInterface;
IOHIDQueueInterface** queue;
NSMutableArray* allCookies;
NSMutableDictionary* cookieToButtonMapping;
BOOL openInExclusiveMode;
int remoteId;
IBOutlet id delegate;
}
- (void) setRemoteId: (int) aValue;
- (int) remoteId;
- (BOOL) isRemoteAvailable;
- (BOOL) isListeningToRemote;
- (void) setListeningToRemote: (BOOL) value;
- (BOOL) isOpenInExclusiveMode;
- (void) setOpenInExclusiveMode: (BOOL) value;
- (void) setDelegate: (id) delegate;
- (id) delegate;
- (IBAction) startListening: (id) sender;
- (IBAction) stopListening: (id) sender;
@end
@interface AppleRemote (Singleton)
+ (AppleRemote*) sharedRemote;
@end
/* Method definitions for the delegate of the AppleRemote class
*/
@interface NSObject(NSAppleRemoteDelegate)
- (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown;
@end
@interface AppleRemote (PrivateMethods)
- (NSDictionary*) cookieToButtonMapping;
- (IOHIDQueueInterface**) queue;
- (IOHIDDeviceInterface**) hidDeviceInterface;
- (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues;
@end
@interface AppleRemote (IOKitMethods)
- (io_object_t) findAppleRemoteDevice;
- (IOHIDDeviceInterface**) createInterfaceForDevice: (io_object_t) hidDevice;
- (BOOL) initializeCookies;
- (BOOL) openDevice;
@end
\ No newline at end of file
This diff is collapsed.
SOURCES_macosx = \ SOURCES_macosx = \
AppleRemote.h \
AppleRemote.m \
about.h \ about.h \
about.m \ about.m \
applescript.h \ applescript.h \
......
...@@ -86,6 +86,7 @@ struct intf_sys_t ...@@ -86,6 +86,7 @@ struct intf_sys_t
/***************************************************************************** /*****************************************************************************
* VLCMain interface * VLCMain interface
*****************************************************************************/ *****************************************************************************/
@class AppleRemote;
@interface VLCMain : NSObject @interface VLCMain : NSObject
{ {
intf_thread_t *p_intf; /* The main intf object */ intf_thread_t *p_intf; /* The main intf object */
...@@ -275,6 +276,8 @@ struct intf_sys_t ...@@ -275,6 +276,8 @@ struct intf_sys_t
NSSize o_size_with_playlist; NSSize o_size_with_playlist;
int i_lastShownVolume; int i_lastShownVolume;
AppleRemote * o_remote;
} }
+ (VLCMain *)sharedInstance; + (VLCMain *)sharedInstance;
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "interaction.h" #include "interaction.h"
#include "embeddedwindow.h" #include "embeddedwindow.h"
#include "update.h" #include "update.h"
#include "AppleRemote.h"
/***************************************************************************** /*****************************************************************************
* Local prototypes. * Local prototypes.
...@@ -343,6 +344,10 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -343,6 +344,10 @@ static VLCMain *_o_sharedMainInstance = nil;
o_update = [[VLCUpdate alloc] init]; o_update = [[VLCUpdate alloc] init];
i_lastShownVolume = -1; i_lastShownVolume = -1;
o_remote = [[AppleRemote alloc] init];
[o_remote setDelegate: _o_sharedMainInstance];
return _o_sharedMainInstance; return _o_sharedMainInstance;
} }
...@@ -684,6 +689,33 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -684,6 +689,33 @@ static VLCMain *_o_sharedMainInstance = nil;
return( o_str ); return( o_str );
} }
/* Listen to the remote in exclusive mode, only when VLC is the active
application */
- (void)applicationDidBecomeActive:(NSNotification *)aNotification
{
[o_remote startListening: self];
}
- (void)applicationDidResignActive:(NSNotification *)aNotification
{
[o_remote stopListening: self];
}
/* Apple Remote callback */
- (void)appleRemoteButton:(AppleRemoteEventIdentifier)buttonIdentifier
pressedDown:(BOOL)pressedDown
{
switch( buttonIdentifier )
{
case kRemoteButtonPlay:
[o_controls play: self];
break;
default:
/* Add here whatever you want other buttons to do */
break;
}
}
- (char *)delocalizeString:(NSString *)id - (char *)delocalizeString:(NSString *)id
{ {
NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment