diff --git a/Application/MediaKeysApplication.h b/Application/MediaKeysApplication.h index a57b0e740..c19a43221 100644 --- a/Application/MediaKeysApplication.h +++ b/Application/MediaKeysApplication.h @@ -9,8 +9,11 @@ #import #import +@class SPMediaKeyTap; + @interface MediaKeysApplication : NSApplication { + SPMediaKeyTap *keyTap; } @end diff --git a/Application/MediaKeysApplication.m b/Application/MediaKeysApplication.m index a5cbc5c9b..9bf4a406f 100644 --- a/Application/MediaKeysApplication.m +++ b/Application/MediaKeysApplication.m @@ -8,44 +8,70 @@ #import "MediaKeysApplication.h" #import "AppController.h" +#import "SPMediaKeyTap.h" +#import "Logging.h" @implementation MediaKeysApplication -- (void)mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat ++(void)initialize; { - switch( key ) - { - case NX_KEYTYPE_PLAY: - if( state == 0 ) - [(AppController *)[self delegate] clickPlay]; //Play pressed and released - break; - - case NX_KEYTYPE_NEXT: - case NX_KEYTYPE_FAST: - if( state == 0 ) - [(AppController *)[self delegate] clickNext]; //Next pressed and released - break; - - case NX_KEYTYPE_PREVIOUS: - case NX_KEYTYPE_REWIND: - if( state == 0 ) - [(AppController *)[self delegate] clickPrev]; //Previous pressed and released - break; - } + if([self class] != [MediaKeysApplication class]) return; + + // Register defaults for the whitelist of apps that want to use media keys + [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: + [SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey, + nil]]; +} + +- (void)finishLaunching { + [super finishLaunching]; + + keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self]; + if([SPMediaKeyTap usesGlobalMediaKeyTap]) + [keyTap startWatchingMediaKeys]; + else + ALog(@"Media key monitoring disabled"); } - (void)sendEvent: (NSEvent*)event { - if( [event type] == NSSystemDefined && [event subtype] == 8 ) + BOOL shouldHandleMediaKeyEventLocally = ![SPMediaKeyTap usesGlobalMediaKeyTap]; + + if(shouldHandleMediaKeyEventLocally && [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); - - [self mediaKeyEvent: keyCode state: keyState repeat: keyRepeat]; + [self mediaKeyTap:nil receivedMediaKeyEvent:event]; } [super sendEvent: event]; } + +-(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event; +{ + NSAssert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys, @"Unexpected NSEvent in mediaKeyTap:receivedMediaKeyEvent:"); + + int keyCode = (([event data1] & 0xFFFF0000) >> 16); + int keyFlags = ([event data1] & 0x0000FFFF); + BOOL keyIsPressed = (((keyFlags & 0xFF00) >> 8)) == 0xA; + + if (!keyIsPressed) // pressed and released + { + switch( keyCode ) + { + case NX_KEYTYPE_PLAY: + [(AppController *)[self delegate] clickPlay]; + break; + + case NX_KEYTYPE_NEXT: + case NX_KEYTYPE_FAST: + [(AppController *)[self delegate] clickNext]; + break; + + case NX_KEYTYPE_PREVIOUS: + case NX_KEYTYPE_REWIND: + [(AppController *)[self delegate] clickPrev]; + break; + } + } +} + @end diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj index 479ae4e81..686716e88 100644 --- a/Cog.xcodeproj/project.pbxproj +++ b/Cog.xcodeproj/project.pbxproj @@ -142,6 +142,8 @@ 8360EF6D17F92E56005208A4 /* HighlyComplete.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8360EF0517F92B24005208A4 /* HighlyComplete.bundle */; }; 836D28A818086386005B7299 /* MiniModeMenuTitleTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 836D28A718086386005B7299 /* MiniModeMenuTitleTransformer.m */; }; 8375B36517FFEF130092A79F /* Opus.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8375B05717FFEA410092A79F /* Opus.bundle */; }; + 83790D501809F4980073CF51 /* NSObject+SPInvocationGrabbing.m in Sources */ = {isa = PBXBuildFile; fileRef = 83790D4D1809F4980073CF51 /* NSObject+SPInvocationGrabbing.m */; }; + 83790D511809F4980073CF51 /* SPMediaKeyTap.m in Sources */ = {isa = PBXBuildFile; fileRef = 83790D4F1809F4980073CF51 /* SPMediaKeyTap.m */; }; 838491211807F38A00E7332D /* NowPlayingBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8384911D1807F38A00E7332D /* NowPlayingBarView.m */; }; 838491221807F38A00E7332D /* NowPlayingBarController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8384911E1807F38A00E7332D /* NowPlayingBarController.xib */; }; 838491231807F38A00E7332D /* NowPlayingBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8384911F1807F38A00E7332D /* NowPlayingBarController.m */; }; @@ -772,6 +774,10 @@ 836D28A618086386005B7299 /* MiniModeMenuTitleTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MiniModeMenuTitleTransformer.h; path = Window/MiniModeMenuTitleTransformer.h; sourceTree = ""; }; 836D28A718086386005B7299 /* MiniModeMenuTitleTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MiniModeMenuTitleTransformer.m; path = Window/MiniModeMenuTitleTransformer.m; sourceTree = ""; }; 8375B05117FFEA400092A79F /* Opus.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Opus.xcodeproj; path = Plugins/Opus/Opus.xcodeproj; sourceTree = ""; }; + 83790D4C1809F4980073CF51 /* NSObject+SPInvocationGrabbing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+SPInvocationGrabbing.h"; sourceTree = ""; }; + 83790D4D1809F4980073CF51 /* NSObject+SPInvocationGrabbing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+SPInvocationGrabbing.m"; sourceTree = ""; }; + 83790D4E1809F4980073CF51 /* SPMediaKeyTap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPMediaKeyTap.h; sourceTree = ""; }; + 83790D4F1809F4980073CF51 /* SPMediaKeyTap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPMediaKeyTap.m; sourceTree = ""; }; 8384911D1807F38A00E7332D /* NowPlayingBarView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NowPlayingBarView.m; path = Window/NowPlayingBarView.m; sourceTree = ""; }; 8384911E1807F38A00E7332D /* NowPlayingBarController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = NowPlayingBarController.xib; path = Window/NowPlayingBarController.xib; sourceTree = ""; }; 8384911F1807F38A00E7332D /* NowPlayingBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NowPlayingBarController.m; path = Window/NowPlayingBarController.m; sourceTree = ""; }; @@ -961,6 +967,7 @@ 177EBF770B8BC2A70000BC8C /* ThirdParty */ = { isa = PBXGroup; children = ( + 83790D4A1809F4980073CF51 /* SPMediaKeyTap */, 173A439D0F3FD25500676A7B /* ToolTip */, 178BAB920CD4E1B700B33D47 /* GCWindowMenu */, 177EBF7D0B8BC2A70000BC8C /* AppleRemote */, @@ -1450,6 +1457,25 @@ name = Products; sourceTree = ""; }; + 83790D4A1809F4980073CF51 /* SPMediaKeyTap */ = { + isa = PBXGroup; + children = ( + 83790D4B1809F4980073CF51 /* SPInvocationGrabbing */, + 83790D4E1809F4980073CF51 /* SPMediaKeyTap.h */, + 83790D4F1809F4980073CF51 /* SPMediaKeyTap.m */, + ); + path = SPMediaKeyTap; + sourceTree = ""; + }; + 83790D4B1809F4980073CF51 /* SPInvocationGrabbing */ = { + isa = PBXGroup; + children = ( + 83790D4C1809F4980073CF51 /* NSObject+SPInvocationGrabbing.h */, + 83790D4D1809F4980073CF51 /* NSObject+SPInvocationGrabbing.m */, + ); + path = SPInvocationGrabbing; + sourceTree = ""; + }; 8384917A1808585C00E7332D /* Products */ = { isa = PBXGroup; children = ( @@ -2017,6 +2043,7 @@ 8E75757209F31D5A0080F1EE /* PlaylistController.m in Sources */, 8E75757309F31D5A0080F1EE /* PlaylistEntry.m in Sources */, 8E75757409F31D5A0080F1EE /* PlaylistView.m in Sources */, + 83790D511809F4980073CF51 /* SPMediaKeyTap.m in Sources */, 8E75757509F31D5A0080F1EE /* Shuffle.m in Sources */, 8E1296DB0A2BA9CE00443124 /* PlaylistHeaderView.m in Sources */, 8E07AB790AAC930B00A4B32F /* PreferencesController.m in Sources */, @@ -2032,6 +2059,7 @@ 1755E1F90BA0D2B600CA3560 /* PlaylistLoader.m in Sources */, 8E9A30160BA792DC0091081B /* NSFileHandle+CreateFile.m in Sources */, 179790E10C087AB7001D6996 /* OpenURLPanel.m in Sources */, + 83790D501809F4980073CF51 /* NSObject+SPInvocationGrabbing.m in Sources */, 1791FF900CB43A2C0070BC5C /* MediaKeysApplication.m in Sources */, 838491211807F38A00E7332D /* NowPlayingBarView.m in Sources */, 178BAB990CD4E1B700B33D47 /* GCOneShotEffectTimer.m in Sources */, diff --git a/English.lproj/Help/images/files.png b/English.lproj/Help/images/files.png new file mode 100644 index 000000000..c91ab2041 Binary files /dev/null and b/English.lproj/Help/images/files.png differ diff --git a/English.lproj/Help/images/info.png b/English.lproj/Help/images/info.png new file mode 100644 index 000000000..91f55752d Binary files /dev/null and b/English.lproj/Help/images/info.png differ diff --git a/English.lproj/Help/images/logo.png b/English.lproj/Help/images/logo.png index eb9f5f3fd..c1bfaad2e 100644 Binary files a/English.lproj/Help/images/logo.png and b/English.lproj/Help/images/logo.png differ diff --git a/English.lproj/Help/images/playback.png b/English.lproj/Help/images/playback.png new file mode 100644 index 000000000..55d546e0b Binary files /dev/null and b/English.lproj/Help/images/playback.png differ diff --git a/English.lproj/Help/images/repeat.png b/English.lproj/Help/images/repeat.png new file mode 100644 index 000000000..dee5f0015 Binary files /dev/null and b/English.lproj/Help/images/repeat.png differ diff --git a/English.lproj/Help/images/shuffle.png b/English.lproj/Help/images/shuffle.png new file mode 100644 index 000000000..c0be90518 Binary files /dev/null and b/English.lproj/Help/images/shuffle.png differ diff --git a/English.lproj/Help/index.html b/English.lproj/Help/index.html index 0010da497..404d4e4bb 100644 --- a/English.lproj/Help/index.html +++ b/English.lproj/Help/index.html @@ -13,9 +13,14 @@