]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/intf.m
macosx: forward-port recent preferences and media keys enhancements
[vlc] / modules / gui / macosx / intf.m
index 534965b22ef4e1849cecf0c7e4beafd0fe130360..d177df7227257572388653ce95dd8f825455e9df 100644 (file)
@@ -2862,8 +2862,11 @@ end:
 
 - (void)awakeFromNib
 {
-       b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
+       b_active = b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
+    b_activeInBackground = config_GetInt( VLCIntf, "macosx-mediakeys-background" );
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name: @"VLCMediaKeySupportSettingChanged" object: nil];
+    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(appGotActiveOrInactive:) name: @"NSApplicationDidBecomeActiveNotification" object: nil];
+    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(appGotActiveOrInactive:) name: @"NSApplicationWillResignActiveNotification" object: nil];
 }
 
 - (void)dealloc
@@ -2872,58 +2875,68 @@ end:
     [super dealloc];
 }
 
+- (void)appGotActiveOrInactive: (NSNotification *)o_notification
+{
+    if(( [[o_notification name] isEqualToString: @"NSApplicationWillResignActiveNotification"] && !b_activeInBackground ) || !b_mediaKeySupport)
+        b_active = NO;
+    else
+        b_active = YES;
+}
+
 - (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
 {
-       b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
+    b_active = b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
+    b_activeInBackground = config_GetInt( VLCIntf, "macosx-mediakeys-background" );
 }
 
+
 - (void)sendEvent: (NSEvent*)event
 {
-       if( b_mediaKeySupport )
+    if( b_active )
        {
-               if( [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);
-
-                       if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
-                               var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
-
-                       if( keyCode == NX_KEYTYPE_FAST && !b_justJumped )
-                       {
-                               if( keyState == 0 && keyRepeat == 0 )
-                               {
-                                               var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
-                               }
-                               else if( keyRepeat == 1 )
-                               {
-                                       var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
-                                       b_justJumped = YES;
-                                       [self performSelector:@selector(resetJump)
-                                                          withObject: NULL
-                                                          afterDelay:0.25];
-                               }
-                       }
-
-                       if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
-                       {
-                               if( keyState == 0 && keyRepeat == 0 )
-                               {
-                                       var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
-                               }
-                               else if( keyRepeat == 1 )
-                               {
-                                       var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
-                                       b_justJumped = YES;
-                                       [self performSelector:@selector(resetJump)
-                                                          withObject: NULL
-                                                          afterDelay:0.25];
-                               }
-                       }
-               }
-       }
+        if( [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);
+            
+            if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
+                var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
+            
+            if( keyCode == NX_KEYTYPE_FAST && !b_justJumped )
+            {
+                if( keyState == 0 && keyRepeat == 0 )
+                {
+                    var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
+                }
+                else if( keyRepeat == 1 )
+                {
+                    var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
+                    b_justJumped = YES;
+                    [self performSelector:@selector(resetJump)
+                               withObject: NULL
+                               afterDelay:0.25];
+                }
+            }
+            
+            if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
+            {
+                if( keyState == 0 && keyRepeat == 0 )
+                {
+                    var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
+                }
+                else if( keyRepeat == 1 )
+                {
+                    var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
+                    b_justJumped = YES;
+                    [self performSelector:@selector(resetJump)
+                               withObject: NULL
+                               afterDelay:0.25];
+                }
+            }
+        }
+    }
        [super sendEvent: event];
 }