Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add media keys support on 10.5+ #3

Merged
merged 1 commit into from
Mar 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Source/SPMediaKeyTap"]
path = Source/SPMediaKeyTap
url = git@github.com:leolobato/SPMediaKeyTap.git
1 change: 1 addition & 0 deletions Source/SPMediaKeyTap
Submodule SPMediaKeyTap added at 979bd8
4 changes: 3 additions & 1 deletion Source/WindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
@class OutputDeviceHandler;
@class MainPlayerToolbarController;
@class AppleRemoteController;
@class SPMediaKeyTap;

extern const NSString *nProfileSwitched;
extern const NSString *dProfile;

@class SUUpdater;

@interface WindowController : NSObject {
@interface WindowController : NSObject <NSApplicationDelegate> {
// controller
IBOutlet PlayListController *mPlaylistController;
IBOutlet InfoAreaController *mInfoAreaController;
Expand Down Expand Up @@ -92,6 +93,7 @@ extern const NSString *dProfile;

MainPlayerToolbarController *_mainPlayerToolbarController;
AppleRemoteController *_appleRemoteController;
SPMediaKeyTap *_mediaKeyTap;
}

+ (id) instance;
Expand Down
64 changes: 61 additions & 3 deletions Source/WindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#import "OutputDeviceHandler.h"
#import "AppleRemoteController.h"

#import "SPMediaKeyTap.h"

WindowController *globalWindowController = nil;

const NSString *nProfileSwitched = @"nProfileSwitched";
Expand Down Expand Up @@ -68,10 +70,17 @@ @implementation WindowController
+ (void) initialize {
NSString *userDefaultsPath = [[NSBundle mainBundle] pathForResource:@"at.justp.theremin.userDefaults" ofType:@"plist"];
if ([userDefaultsPath length] > 0) {
NSDictionary *userDefaults = [NSDictionary dictionaryWithContentsOfFile:userDefaultsPath];
if (userDefaults != nil) {
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaults];
NSMutableDictionary *userDefaults = [NSMutableDictionary dictionaryWithContentsOfFile:userDefaultsPath];
if (!userDefaults) {
userDefaults = [[[NSMutableDictionary alloc] init] autorelease];
}

// SPMediaKeyTap
// Register defaults for the whitelist of apps that want to use media keys
[userDefaults setObject:[SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers]
forKey:kMediaKeyUsingBundleIdentifiersDefaultsKey];

[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaults];
}
}

Expand Down Expand Up @@ -246,13 +255,62 @@ - (void) dealloc {

[_outputDeviceHandler release];
[_appleRemoteController release];
[_mediaKeyTap release];

[_licenseController release];


[super dealloc];
}

#pragma mark NSApplicationDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
_mediaKeyTap = [[SPMediaKeyTap alloc] initWithDelegate:self];

if ([SPMediaKeyTap usesGlobalMediaKeyTap]) {
[_mediaKeyTap startWatchingMediaKeys];
} else {
NSLog(@"Media key monitoring not supported");
}
}

#pragma mark - SPMediaKeyTapDelegate

-(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event; {
NSAssert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys, @"Unexpected NSEvent in mediaKeyTap:receivedMediaKeyEvent:");
// here be dragons...
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
int keyFlags = ([event data1] & 0x0000FFFF);
BOOL keyIsPressed = (((keyFlags & 0xFF00) >> 8)) == 0xA;
int keyRepeat = (keyFlags & 0x1);

if (keyIsPressed) {
NSString *debugString = [NSString stringWithFormat:@"%@", keyRepeat?@", repeated.":@"."];
switch (keyCode) {
case NX_KEYTYPE_PLAY:
debugString = [@"Play/pause pressed" stringByAppendingString:debugString];
[self togglePlayPause:keyTap];
break;

case NX_KEYTYPE_FAST:
debugString = [@"Ffwd pressed" stringByAppendingString:debugString];
[self nextSong:keyTap];
break;

case NX_KEYTYPE_REWIND:
debugString = [@"Rewind pressed" stringByAppendingString:debugString];
[self previousSong:keyTap];
break;
default:
debugString = [NSString stringWithFormat:@"Key %d pressed%@", keyCode, debugString];
break;
// More cases defined in hidsystem/ev_keymap.h
}
NSLog(@"%@", debugString);
}
}

#pragma mark -
#pragma mark Profiles

Expand Down
25 changes: 25 additions & 0 deletions Theremin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
428B50B116FA613B00415CBA /* NSObject+SPInvocationGrabbing.m in Sources */ = {isa = PBXBuildFile; fileRef = 428B50A316FA613B00415CBA /* NSObject+SPInvocationGrabbing.m */; };
428B50B216FA613B00415CBA /* SPMediaKeyTap.m in Sources */ = {isa = PBXBuildFile; fileRef = 428B50A516FA613B00415CBA /* SPMediaKeyTap.m */; };
428B50B816FA66F300415CBA /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 428B50B716FA66F300415CBA /* Carbon.framework */; };
43156D3E0FBEFC1200EF3ECA /* lastfm_red.gif in Resources */ = {isa = PBXBuildFile; fileRef = 43156D3D0FBEFC1200EF3ECA /* lastfm_red.gif */; };
43156DC20FBF020C00EF3ECA /* empty.png in Resources */ = {isa = PBXBuildFile; fileRef = 43156DC10FBF020C00EF3ECA /* empty.png */; };
43156E050FBF097E00EF3ECA /* CoverArtAsker.m in Sources */ = {isa = PBXBuildFile; fileRef = 43156E040FBF097E00EF3ECA /* CoverArtAsker.m */; };
Expand Down Expand Up @@ -197,6 +200,11 @@
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
428B50A216FA613B00415CBA /* NSObject+SPInvocationGrabbing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSObject+SPInvocationGrabbing.h"; path = "SPInvocationGrabbing/NSObject+SPInvocationGrabbing.h"; sourceTree = "<group>"; };
428B50A316FA613B00415CBA /* NSObject+SPInvocationGrabbing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSObject+SPInvocationGrabbing.m"; path = "SPInvocationGrabbing/NSObject+SPInvocationGrabbing.m"; sourceTree = "<group>"; };
428B50A416FA613B00415CBA /* SPMediaKeyTap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPMediaKeyTap.h; sourceTree = "<group>"; };
428B50A516FA613B00415CBA /* SPMediaKeyTap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPMediaKeyTap.m; sourceTree = "<group>"; };
428B50B716FA66F300415CBA /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
43156D3D0FBEFC1200EF3ECA /* lastfm_red.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = lastfm_red.gif; path = Resources/lastfm_red.gif; sourceTree = "<group>"; };
43156DC10FBF020C00EF3ECA /* empty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = empty.png; path = ../empty.png; sourceTree = "<group>"; };
43156E030FBF097E00EF3ECA /* CoverArtAsker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoverArtAsker.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -469,6 +477,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
428B50B816FA66F300415CBA /* Carbon.framework in Frameworks */,
48121D231620C9BC00C6626B /* libsqlite3.dylib in Frameworks */,
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
437BDB270B74F42E001C1057 /* Security.framework in Frameworks */,
Expand All @@ -485,6 +494,7 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
428B508E16FA613B00415CBA /* SPMediaKeyTap */,
43CA16D50FC1E42800E14FE7 /* OutputDevices */,
431CCBAE0FBB5F640042E376 /* CoverArt */,
436D30ED0FB72AA30063DC8D /* Growl */,
Expand Down Expand Up @@ -519,6 +529,7 @@
1058C7A2FEA54F0111CA2CBB /* System Frameworks */ = {
isa = PBXGroup;
children = (
428B50B716FA66F300415CBA /* Carbon.framework */,
48121D221620C9B900C6626B /* libsqlite3.dylib */,
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
437BDB260B74F42E001C1057 /* Security.framework */,
Expand Down Expand Up @@ -574,6 +585,18 @@
name = Frameworks;
sourceTree = "<group>";
};
428B508E16FA613B00415CBA /* SPMediaKeyTap */ = {
isa = PBXGroup;
children = (
428B50A216FA613B00415CBA /* NSObject+SPInvocationGrabbing.h */,
428B50A316FA613B00415CBA /* NSObject+SPInvocationGrabbing.m */,
428B50A416FA613B00415CBA /* SPMediaKeyTap.h */,
428B50A516FA613B00415CBA /* SPMediaKeyTap.m */,
);
name = SPMediaKeyTap;
path = Source/SPMediaKeyTap;
sourceTree = "<group>";
};
431CCBAE0FBB5F640042E376 /* CoverArt */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1281,6 +1304,8 @@
43BD36711052E628001E30F0 /* libmpd-strfsong.c in Sources */,
43BD36731052E628001E30F0 /* libmpd.c in Sources */,
43BD36741052E628001E30F0 /* libmpdclient.c in Sources */,
428B50B116FA613B00415CBA /* NSObject+SPInvocationGrabbing.m in Sources */,
428B50B216FA613B00415CBA /* SPMediaKeyTap.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down