]> git.sesse.net Git - vlc/commitdiff
macosx: robustify media key trap handling
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Tue, 11 Nov 2014 11:11:02 +0000 (12:11 +0100)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Tue, 11 Nov 2014 11:21:35 +0000 (12:21 +0100)
Only start and stop media key support when needed (ressource-intensive).

modules/gui/macosx/intf.h
modules/gui/macosx/intf.m
modules/gui/macosx/simple_prefs.m

index 98cda4e16e5fa1392ae7d859548b767258e100a3..db5baccdbcb119f3a1a78c00049b4bb5447eb48f 100644 (file)
@@ -105,6 +105,7 @@ static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
     BOOL b_mediaKeySupport;
     BOOL b_mediakeyJustJumped;
     SPMediaKeyTap * o_mediaKeyController;
+    BOOL b_mediaKeyTrapEnabled;
 
     NSArray *o_usedHotkeys;
 
index 11dba36568e342b8905caf2bd7d555b4779e4b7a..2f85aefa84d194205756c78b1d21033426054cea 100644 (file)
@@ -1842,18 +1842,23 @@ static const int kCurrentPreferencesVersion = 3;
 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
 {
     b_mediaKeySupport = var_InheritBool(VLCIntf, "macosx-mediakeys");
-    if (b_mediaKeySupport) {
-        if (!o_mediaKeyController)
-            o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
+    if (b_mediaKeySupport && !o_mediaKeyController)
+        o_mediaKeyController = [[SPMediaKeyTap alloc] initWithDelegate:self];
 
-        if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot]->i_children > 0 ||
-            p_current_input)
+    if (b_mediaKeySupport && ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot]->i_children > 0 ||
+                              p_current_input)) {
+        if (!b_mediaKeyTrapEnabled) {
+            b_mediaKeyTrapEnabled = YES;
+            msg_Dbg(p_intf, "Enable media key support");
             [o_mediaKeyController startWatchingMediaKeys];
-        else
+        }
+    } else {
+        if (b_mediaKeyTrapEnabled) {
+            b_mediaKeyTrapEnabled = NO;
+            msg_Dbg(p_intf, "Disable media key support");
             [o_mediaKeyController stopWatchingMediaKeys];
+        }
     }
-    else if (!b_mediaKeySupport && o_mediaKeyController)
-        [o_mediaKeyController stopWatchingMediaKeys];
 }
 
 @end
index 3b89472a6a07261977193af351aefc4e83b432ad..d51e1fd7396e0b4f83d22be55b94287638e942d4 100644 (file)
@@ -1451,10 +1451,6 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
         [o_hotkeys_listbox reloadData];
         b_hotkeyChanged = YES;
     }
-
-    [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
-                                                        object: nil
-                                                      userInfo: nil];
 }
 
 - (void)showHotkeySettings