[vlc-commits] macosx: make sure that we don' t block media keys for iTunes in case the user doesn' t want to use them within VLC

Felix Paul Kühne git at videolan.org
Mon Jul 11 16:01:26 CEST 2011


vlc/vlc-1.1 | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon Jul 11 16:01:21 2011 +0200| [99fbdecc596055536b61739414d98d819d7643a4] | committer: Felix Paul Kühne

macosx: make sure that we don't block media keys for iTunes in case the user doesn't want to use them within VLC

Changing this option requires a relaunch now, which is automatically offered when needed.

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=99fbdecc596055536b61739414d98d819d7643a4
---

 NEWS                               |    1 +
 modules/gui/macosx/SPMediaKeyTap.m |    6 ++--
 modules/gui/macosx/intf.m          |   42 ++++++++++++++++++++++++++++++------
 modules/gui/macosx/simple_prefs.m  |    7 +++--
 4 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/NEWS b/NEWS
index 6debe5d..9e609d2 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Mac OS X:
  * Update Auhal audio output to the latest API
  * Fix images disappearing issue on the interface
  * Reduced installation size by up to 30 MB
+ * Resolved conflict between iTunes and VLC wrt Media Key handling
 
 Mozilla/ActiveX webplugin:
  * Fullscreen mode is fixed on Win32
diff --git a/modules/gui/macosx/SPMediaKeyTap.m b/modules/gui/macosx/SPMediaKeyTap.m
index 5f6063a..fe6ff24 100644
--- a/modules/gui/macosx/SPMediaKeyTap.m
+++ b/modules/gui/macosx/SPMediaKeyTap.m
@@ -34,7 +34,7 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
 #pragma mark Setup and teardown
 -(id)initWithDelegate:(id)delegate;
 {
-	_delegate = delegate;
+    _delegate = delegate;
 	[self startWatchingAppSwitching];
 	singleton = self;
 	_mediaKeyAppList = [NSMutableArray new];
@@ -42,7 +42,7 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
 }
 -(void)dealloc;
 {
-	[self stopWatchingMediaKeys];
+    [self stopWatchingMediaKeys];
 	[self stopWatchingAppSwitching];
 	[_mediaKeyAppList release];
 	[super dealloc];
@@ -68,7 +68,7 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
 }
 
 -(void)startWatchingMediaKeys;{
-	[self setShouldInterceptMediaKeyEvents:YES];
+    [self setShouldInterceptMediaKeyEvents:YES];
 	
 	// Add an event tap to intercept the system defined media key events
 	_eventPort = CGEventTapCreate(kCGSessionEventTap,
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 8abc6be..535e9b9 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -574,14 +574,16 @@ static VLCMain *_o_sharedMainInstance = nil;
     if( !p_intf ) return;
 
     /* init media key support */
-    o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
     b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
-    [o_mediaKeyController startWatchingMediaKeys];
-    [o_mediaKeyController setShouldInterceptMediaKeyEvents:b_mediaKeySupport];
+    if( b_mediaKeySupport )
+    {
+        o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
+        [o_mediaKeyController startWatchingMediaKeys];
+        [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
+                                                                 [SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey,
+                                                                 nil]];
+    }
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name: @"VLCMediaKeySupportSettingChanged" object: nil];
-    [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
-                                                             [SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey,
-                                                             nil]];
 
     [self _removeOldPreferences];
 
@@ -838,6 +840,9 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     /* release some other objects here, because it isn't sure whether dealloc
      * will be called later on */
+    if( o_mediaKeyController )
+        [o_mediaKeyController release];
+
     if( nib_about_loaded )
         [o_about release];
 
@@ -2843,7 +2848,30 @@ end:
 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
 {
     b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
-    [o_mediaKeyController setShouldInterceptMediaKeyEvents:b_mediaKeySupport];
+    if (b_mediaKeySupport) {
+        if (!o_mediaKeyController)
+            o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
+        [o_mediaKeyController startWatchingMediaKeys];
+    }
+    else if (!b_mediaKeySupport && o_mediaKeyController)
+    {
+        int returnedValue = NSRunInformationalAlertPanel(_NS("Relaunch required"),
+                                               _NS("To make sure that VLC no longer listens to your media key events, it needs to be restarted."),
+                                               _NS("Relaunch VLC"), _NS("Ignore"), nil, nil);
+        if( returnedValue == NSOKButton )
+        {
+            /* Relaunch now */
+            const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
+
+            /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
+            if(fork() != 0)
+            {
+                exit(0);
+                return;
+            }
+            execl(path, path, NULL);
+        }
+    }
 }
 
 @end
diff --git a/modules/gui/macosx/simple_prefs.m b/modules/gui/macosx/simple_prefs.m
index 72f43a8..f87b807 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -844,9 +844,6 @@ static inline void save_module_list( intf_thread_t * p_intf, id object, const ch
 			[[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
 		else
 			[[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
-        [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
-                                                            object: nil
-                                                          userInfo: nil];
 
         /* okay, let's save our changes to vlcrc */
         i = config_SaveConfigFile( p_intf, "main" );
@@ -1092,6 +1089,10 @@ static inline void save_module_list( intf_thread_t * p_intf, id object, const ch
         }
         b_hotkeyChanged = NO;
     }
+
+    [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
+                                                        object: nil
+                                                      userInfo: nil];
 }
 
 - (void)showSettingsForCategory: (id)o_new_category_view



More information about the vlc-commits mailing list