]> 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 3b96807bccf4967b36bde48f784a9ac7eba4af4b..d177df7227257572388653ce95dd8f825455e9df 100644 (file)
@@ -314,7 +314,7 @@ static VLCMain *_o_sharedMainInstance = nil;
     p_intf = NULL;
 
     o_msg_lock = [[NSLock alloc] init];
-    o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
+    o_msg_arr = [[NSMutableArray arrayWithCapacity: 600] retain];
     /* subscribe to LibVLC's debug messages as early as possible (for us) */
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(libvlcMessageReceived:) name: @"VLCCoreMessageReceived" object: nil];
     
@@ -334,11 +334,9 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     i_lastShownVolume = -1;
 
-#ifndef __x86_64__
     o_remote = [[AppleRemote alloc] init];
     [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
     [o_remote setDelegate: _o_sharedMainInstance];
-#endif
 
     o_eyetv = [[VLCEyeTVController alloc] init];
 
@@ -525,8 +523,10 @@ static VLCMain *_o_sharedMainInstance = nil;
     nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
     
     /* subscribe to various interactive dialogues */
-    var_Create( p_intf, "dialog-fatal", VLC_VAR_ADDRESS );
-    var_AddCallback( p_intf, "dialog-fatal", DialogCallback, self );
+    var_Create( p_intf, "dialog-error", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "dialog-error", DialogCallback, self );
+    var_Create( p_intf, "dialog-critical", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "dialog-critical", DialogCallback, self );
     var_Create( p_intf, "dialog-login", VLC_VAR_ADDRESS );
     var_AddCallback( p_intf, "dialog-login", DialogCallback, self );
     var_Create( p_intf, "dialog-question", VLC_VAR_ADDRESS );
@@ -819,7 +819,8 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     /* unsubscribe from the interactive dialogues */
     dialog_Unregister( p_intf );
-    var_DelCallback( p_intf, "dialog-fatal", DialogCallback, self );
+    var_DelCallback( p_intf, "dialog-error", DialogCallback, self );
+    var_DelCallback( p_intf, "dialog-critical", DialogCallback, self );
     var_DelCallback( p_intf, "dialog-login", DialogCallback, self );
     var_DelCallback( p_intf, "dialog-question", DialogCallback, self );
     var_DelCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
@@ -1014,16 +1015,13 @@ static NSString * VLCToolbarMediaControl     = @"VLCToolbarMediaControl";
 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
 {
     if( !p_intf ) return;
-#ifndef __x86_64__
-    [o_remote startListening: self];
-#endif
+       if( config_GetInt( p_intf, "macosx-appleremote" ) == YES )
+               [o_remote startListening: self];
 }
 - (void)applicationDidResignActive:(NSNotification *)aNotification
 {
     if( !p_intf ) return;
-#ifndef __x86_64__
     [o_remote stopListening: self];
-#endif
 }
 
 /* Triggered when the computer goes to sleep */
@@ -1500,6 +1498,11 @@ static unsigned int VLCModifiersToCocoa( unsigned int i_key )
     return nil;
 }
 
+- (id)appleRemoteController
+{
+       return o_remote;
+}
+
 #pragma mark -
 #pragma mark Polling
 
@@ -1609,7 +1612,10 @@ static void manage_cleanup( void * args )
 - (void)manageVolumeSlider
 {
     audio_volume_t i_volume;
-    aout_VolumeGet( p_intf, &i_volume );
+    playlist_t * p_playlist = pl_Hold( p_intf );
+
+    aout_VolumeGet( p_playlist, &i_volume );
+    pl_Release( p_intf );
 
     if( i_volume != i_lastShownVolume )
     {
@@ -2854,50 +2860,83 @@ end:
 
 @implementation VLCApplication
 
-- (void)sendEvent: (NSEvent*)event
+- (void)awakeFromNib
 {
-    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);
+       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];
+}
 
-        if( keyCode == NX_KEYTYPE_PLAY && keyState == 0 )
-            var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver: self];
+    [super dealloc];
+}
 
-        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];
-            }
-        }
+- (void)appGotActiveOrInactive: (NSNotification *)o_notification
+{
+    if(( [[o_notification name] isEqualToString: @"NSApplicationWillResignActiveNotification"] && !b_activeInBackground ) || !b_mediaKeySupport)
+        b_active = NO;
+    else
+        b_active = YES;
+}
 
-        if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
+- (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification
+{
+    b_active = b_mediaKeySupport = config_GetInt( VLCIntf, "macosx-mediakeys" );
+    b_activeInBackground = config_GetInt( VLCIntf, "macosx-mediakeys-background" );
+}
+
+
+- (void)sendEvent: (NSEvent*)event
+{
+    if( b_active )
+       {
+        if( [event type] == NSSystemDefined && [event subtype] == 8 )
         {
-            if( keyState == 0 && keyRepeat == 0 )
+            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 )
             {
-                var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
+                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];
+                }
             }
-            else if( keyRepeat == 1 )
+            
+            if( keyCode == NX_KEYTYPE_REWIND && !b_justJumped )
             {
-                var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
-                b_justJumped = YES;
-                [self performSelector:@selector(resetJump)
-                           withObject: NULL
-                           afterDelay:0.25];
+                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];
 }