[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:06:45 CEST 2011


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon Jul 11 16:06:27 2011 +0200| [e822e3f9d81d440838c248a265df12eb83c10907] | 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.

Fixes #5025

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

 modules/gui/macosx/intf.m         |   39 ++++++++++++++++++++++++++++++------
 modules/gui/macosx/simple_prefs.m |    7 +++--
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index b472e3b..3a17fd5 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -439,14 +439,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];
 
@@ -2030,7 +2032,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 a26f9fa..29aedfb 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -793,9 +793,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];
         b_intfSettingChanged = NO;
     }
 
@@ -1151,6 +1148,10 @@ static inline void save_module_list( intf_thread_t * p_intf, id object, const ch
         [o_hotkeys_listbox reloadData];
         b_hotkeyChanged = YES;
     }
+
+    [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
+                                                        object: nil
+                                                      userInfo: nil];
 }
 
 - (void)showHotkeySettings



More information about the vlc-commits mailing list