]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/intf.m
macosx: move fullscreen logic to VLCVoutController and remove now unneeded helper...
[vlc] / modules / gui / macosx / intf.m
index bc4547d45df9a636164143b423ddd9846b889b48..fcb005ccc479f87fe0d26d85c49aa82b664efb21 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * intf.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2002-2012 VLC authors and VideoLAN
+ * Copyright (C) 2002-2013 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
@@ -172,8 +172,8 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
         int i_full = 1;
 
         SEL sel = @selector(setFullscreen:forWindow:);
-        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[VLCMain sharedInstance] methodSignatureForSelector:sel]];
-        [inv setTarget:[VLCMain sharedInstance]];
+        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]];
+        [inv setTarget:[[VLCMain sharedInstance] voutController]];
         [inv setSelector:sel];
         [inv setArgument:&i_full atIndex:2];
         [inv setArgument:&p_wnd atIndex:3];
@@ -236,8 +236,8 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
             int i_full = va_arg(args, int);
 
             SEL sel = @selector(setFullscreen:forWindow:);
-            NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[VLCMain sharedInstance] methodSignatureForSelector:sel]];
-            [inv setTarget:[VLCMain sharedInstance]];
+            NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]];
+            [inv setTarget:[[VLCMain sharedInstance] voutController]];
             [inv setSelector:sel];
             [inv setArgument:&i_full atIndex:2]; // starting at 2!
             [inv setArgument:&p_wnd atIndex:3];
@@ -404,7 +404,7 @@ static int PLItemChanged(vlc_object_t *p_this, const char *psz_var,
      * then -informInputChanged on this non-main thread. */
     [o_plItemChangedLock lock];
     [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:YES];
-    [[VLCMain sharedInstance] informInputChanged];
+    [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(informInputChanged) withObject:nil waitUntilDone:YES];
     [o_plItemChangedLock unlock];
 
     [o_pool release];
@@ -712,12 +712,6 @@ static VLCMain *_o_sharedMainInstance = nil;
         b_nativeFullscreenMode = var_InheritBool(p_intf, "macosx-nativefullscreenmode");
 #endif
 
-    /* recover stored audio device, if set
-     * in case it was unplugged in the meantime, auhal will fall back on the default */
-    int i_value = config_GetInt(p_intf, "macosx-audio-device");
-    if (i_value > 0)
-        var_SetInteger(pl_Get(VLCIntf), "audio-device", i_value);
-
     if (config_GetInt(VLCIntf, "macosx-icon-change")) {
         /* After day 354 of the year, the usual VLC cone is replaced by another cone
          * wearing a Father Xmas hat.
@@ -938,7 +932,7 @@ static VLCMain *_o_sharedMainInstance = nil;
         int keyRepeat = (keyFlags & 0x1);
 
         if (keyCode == NX_KEYTYPE_PLAY && keyState == 0)
-            [[VLCCoreInteraction sharedInstance] play];
+            [[VLCCoreInteraction sharedInstance] playOrPause];
 
         if ((keyCode == NX_KEYTYPE_FAST || keyCode == NX_KEYTYPE_NEXT) && !b_mediakeyJustJumped) {
             if (keyState == 0 && keyRepeat == 0)
@@ -1059,12 +1053,10 @@ static VLCMain *_o_sharedMainInstance = nil;
                 [[VLCCoreInteraction sharedInstance] backward];
                 break;
             case kRemoteButtonVolume_Plus_Hold:
-                if (p_intf)
-                    var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_UP);
+                [[VLCCoreInteraction sharedInstance] volumeUp];
                 break;
             case kRemoteButtonVolume_Minus_Hold:
-                if (p_intf)
-                    var_SetInteger(p_intf->p_libvlc, "key-action", ACTIONID_VOL_DOWN);
+                [[VLCCoreInteraction sharedInstance] volumeDown];
                 break;
         }
         if (b_remote_button_hold) {
@@ -1086,13 +1078,13 @@ static VLCMain *_o_sharedMainInstance = nil;
             [[VLCCoreInteraction sharedInstance] toggleFullscreen];
             break;
         case k2009RemoteButtonPlay:
-            [[VLCCoreInteraction sharedInstance] play];
+            [[VLCCoreInteraction sharedInstance] playOrPause];
             break;
         case kRemoteButtonPlay:
             if (count >= 2)
                 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
             else
-                [[VLCCoreInteraction sharedInstance] play];
+                [[VLCCoreInteraction sharedInstance] playOrPause];
             break;
         case kRemoteButtonVolume_Plus:
             if (config_GetInt(VLCIntf, "macosx-appleremote-sysvol"))
@@ -1200,7 +1192,7 @@ static VLCMain *_o_sharedMainInstance = nil;
         }
 
         if (key == 0x0020) { // space key
-            [[VLCCoreInteraction sharedInstance] play];
+            [[VLCCoreInteraction sharedInstance] playOrPause];
             return YES;
         }
 
@@ -1261,45 +1253,6 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 #pragma mark -
 #pragma mark Interface updaters
-- (void)setFullscreen:(int)i_full forWindow:(vout_window_t *)p_wnd
-{
-    if (!p_intf || (!b_nativeFullscreenMode && !p_wnd))
-        return;
-    playlist_t * p_playlist = pl_Get(p_intf);
-    BOOL b_fullscreen = i_full;
-
-    if (!var_GetBool(p_playlist, "fullscreen") != !b_fullscreen)
-        var_SetBool(p_playlist, "fullscreen", b_fullscreen);
-
-    if (b_nativeFullscreenMode) {
-        // this is called twice in certain situations, so only toogle if we really need to
-        if ((b_fullscreen && !([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen)) ||
-            (!b_fullscreen &&  ([NSApp currentSystemPresentationOptions] & NSApplicationPresentationFullScreen)))
-            [o_mainwindow toggleFullScreen: self];
-
-        if (b_fullscreen)
-            [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
-        else
-            [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
-    } else {
-        assert(p_wnd);
-
-        if (b_fullscreen) {
-            input_thread_t * p_input = pl_CurrentInput(p_intf);
-            if (p_input != NULL && [self activeVideoPlayback]) {
-                // activate app, as method can also be triggered from outside the app (prevents nasty window layout)
-                [NSApp activateIgnoringOtherApps:YES];
-                [o_vout_controller updateWindow:p_wnd withSelector:@selector(enterFullscreen)];
-
-            }
-            if (p_input)
-                vlc_object_release(p_input);
-        } else {
-            // leaving fullscreen is always allowed
-            [o_vout_controller updateWindow:p_wnd withSelector:@selector(leaveFullscreen)];
-        }
-    }
-}
 
 - (void)PlaylistItemChanged
 {
@@ -1407,6 +1360,20 @@ static VLCMain *_o_sharedMainInstance = nil;
     if (p_input) {
         int state = var_GetInteger(p_input, "state");
         if (state == PLAYING_S) {
+            /* Declare user activity.
+               This wakes the display if it is off, and postpones display sleep according to the users system preferences
+               Available from 10.7.3 */
+#ifdef MAC_OS_X_VERSION_10_7
+            if ([self activeVideoPlayback] && IOPMAssertionDeclareUserActivity)
+            {
+                CFStringRef reasonForActivity = CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
+                IOPMAssertionDeclareUserActivity(reasonForActivity,
+                                                 kIOPMUserActiveLocal,
+                                                 &userActivityAssertionID);
+                CFRelease(reasonForActivity);
+            }
+#endif
+
             /* prevent the system from sleeping */
             if (systemSleepAssertionID > 0) {
                 msg_Dbg(VLCIntf, "releasing old sleep blocker (%i)" , systemSleepAssertionID);