]> 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 97341c974d4dc506d0b64a972ed456d09ba696d2..fcb005ccc479f87fe0d26d85c49aa82b664efb21 100644 (file)
@@ -1,13 +1,14 @@
 /*****************************************************************************
  * 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>
  *          Christophe Massiot <massiot@via.ecp.fr>
  *          Derk-Jan Hartman <hartman at videolan.org>
  *          Felix Paul Kühne <fkuehne at videolan dot org>
+ *          David Fuhrmann <david dot fuhrmann at googlemail dot com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,8 +41,6 @@
 #include <vlc_url.h>
 #include <vlc_modules.h>
 #include <vlc_plugin.h>
-#include <vlc_aout_intf.h>
-#include <vlc_vout_window.h>
 #include <vlc_vout_display.h>
 #include <unistd.h> /* execl() */
 
 #import "simple_prefs.h"
 #import "CoreInteraction.h"
 #import "TrackSynchronization.h"
+#import "VLCVoutWindowController.h"
+#import "ExtensionsManager.h"
+
+#import "VideoEffects.h"
+#import "AudioEffects.h"
 
 #import <AddressBook/AddressBook.h>         /* for crashlog send mechanism */
 #import <Sparkle/Sparkle.h>                 /* we're the update delegate */
@@ -137,23 +141,49 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
         msg_Err(p_wnd, "Mac OS X interface not found");
         return VLC_EGENERIC;
     }
+    NSRect proposedVideoViewPosition = NSMakeRect(cfg->x, cfg->y, cfg->width, cfg->height);
+
+    VLCVoutWindowController *o_vout_controller = [[VLCMain sharedInstance] voutController];
+    SEL sel = @selector(setupVoutForWindow:withProposedVideoViewPosition:);
+    NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[o_vout_controller methodSignatureForSelector:sel]];
+    [inv setTarget:o_vout_controller];
+    [inv setSelector:sel];
+    [inv setArgument:&p_wnd atIndex:2]; // starting at 2!
+    [inv setArgument:&proposedVideoViewPosition atIndex:3];
+
+    [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
+                       waitUntilDone:YES];
 
-    int i_x = cfg->x;
-    int i_y = cfg->y;
-    unsigned i_width = cfg->width;
-    unsigned i_height = cfg->height;
-    p_wnd->handle.nsobject = [[VLCMain sharedInstance] getVideoViewAtPositionX: &i_x Y: &i_y withWidth: &i_width andHeight: &i_height];
+    VLCVoutView *videoView = nil;
+    [inv getReturnValue:&videoView];
 
-    if (!p_wnd->handle.nsobject) {
+    if (!videoView) {
         msg_Err(p_wnd, "got no video view from the interface");
         [o_pool release];
         return VLC_EGENERIC;
     }
 
-    [[VLCMain sharedInstance] setNativeVideoSize:NSMakeSize(cfg->width, cfg->height)];
+    msg_Dbg(VLCIntf, "returning videoview with proposed position x=%i, y=%i, width=%i, height=%i", cfg->x, cfg->y, cfg->width, cfg->height);
+    p_wnd->handle.nsobject = videoView;
+
+
+    // TODO: find a cleaner way for "start in fullscreen"
+    if (var_GetBool(pl_Get(VLCIntf), "fullscreen")) {
+        int i_full = 1;
+
+        SEL sel = @selector(setFullscreen:forWindow:);
+        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];
+        [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
+                           waitUntilDone:NO];
+    }
+
     [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
     p_wnd->control = WindowControl;
-    p_wnd->sys = (vout_window_sys_t *)VLCIntf;
+
     [o_pool release];
     return VLC_SUCCESS;
 }
@@ -164,21 +194,56 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
         case VOUT_WINDOW_SET_STATE:
         {
             unsigned i_state = va_arg(args, unsigned);
-            [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(setWindowLevel:) withObject:[NSNumber numberWithUnsignedInt:i_state] waitUntilDone:NO];
+
+            NSInteger i_cooca_level = NSNormalWindowLevel;
+            if (i_state & VOUT_WINDOW_STATE_ABOVE)
+                i_cooca_level = NSStatusWindowLevel;
+
+            SEL sel = @selector(setWindowLevel:forWindow:);
+            NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]];
+            [inv setTarget:[[VLCMain sharedInstance] voutController]];
+            [inv setSelector:sel];
+            [inv setArgument:&i_cooca_level atIndex:2]; // starting at 2!
+            [inv setArgument:&p_wnd atIndex:3];
+            [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
+                               waitUntilDone:NO];
+
             return VLC_SUCCESS;
         }
         case VOUT_WINDOW_SET_SIZE:
         {
+            NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+
             unsigned int i_width  = va_arg(args, unsigned int);
             unsigned int i_height = va_arg(args, unsigned int);
-            [[VLCMain sharedInstance] setNativeVideoSize:NSMakeSize(i_width, i_height)];
+
+            NSSize newSize = NSMakeSize(i_width, i_height);
+            SEL sel = @selector(setNativeVideoSize:forWindow:);
+            NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[[[VLCMain sharedInstance] voutController] methodSignatureForSelector:sel]];
+            [inv setTarget:[[VLCMain sharedInstance] voutController]];
+            [inv setSelector:sel];
+            [inv setArgument:&newSize atIndex:2]; // starting at 2!
+            [inv setArgument:&p_wnd atIndex:3];
+            [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
+                               waitUntilDone:NO];
+
+            [o_pool release];
             return VLC_SUCCESS;
         }
         case VOUT_WINDOW_SET_FULLSCREEN:
         {
             NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
             int i_full = va_arg(args, int);
-            [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(checkFullscreenChange:) withObject:[NSNumber numberWithInt: i_full] waitUntilDone:NO];
+
+            SEL sel = @selector(setFullscreen:forWindow:);
+            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];
+            [inv performSelectorOnMainThread:@selector(invoke) withObject:nil
+                               waitUntilDone:NO];
+
             [o_pool release];
             return VLC_SUCCESS;
         }
@@ -191,7 +256,8 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
 void WindowClose(vout_window_t *p_wnd)
 {
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
-    [[VLCMain sharedInstance] setActiveVideoPlayback:NO];
+
+    [[[VLCMain sharedInstance] voutController] performSelectorOnMainThread:@selector(removeVoutforDisplay:) withObject:[NSValue valueWithPointer:p_wnd] waitUntilDone:NO];
 
     [o_pool release];
 }
@@ -200,6 +266,7 @@ void WindowClose(vout_window_t *p_wnd)
  * Run: main loop
  *****************************************************************************/
 static NSLock * o_appLock = nil;    // controls access to f_appExit
+static NSLock * o_plItemChangedLock = nil;
 
 static void Run(intf_thread_t *p_intf)
 {
@@ -207,12 +274,14 @@ static void Run(intf_thread_t *p_intf)
     [VLCApplication sharedApplication];
 
     o_appLock = [[NSLock alloc] init];
+    o_plItemChangedLock = [[NSLock alloc] init];
 
     [[VLCMain sharedInstance] setIntf: p_intf];
     [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
 
     [NSApp run];
     [[VLCMain sharedInstance] applicationWillTerminate:nil];
+    [o_plItemChangedLock release];
     [o_appLock release];
     [o_pool release];
 
@@ -329,7 +398,14 @@ static int PLItemChanged(vlc_object_t *p_this, const char *psz_var,
                          vlc_value_t oldval, vlc_value_t new_val, void *param)
 {
     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
-    [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:NO];
+
+    /* Due to constraints within NSAttributedString's main loop runtime handling
+     * and other issues, we need to wait for -PlaylistItemChanged to finish and
+     * then -informInputChanged on this non-main thread. */
+    [o_plItemChangedLock lock];
+    [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(PlaylistItemChanged) withObject:nil waitUntilDone:YES];
+    [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(informInputChanged) withObject:nil waitUntilDone:YES];
+    [o_plItemChangedLock unlock];
 
     [o_pool release];
     return VLC_SUCCESS;
@@ -385,22 +461,6 @@ static int ShowController(vlc_object_t *p_this, const char *psz_variable,
     return VLC_SUCCESS;
 }
 
-/*****************************************************************************
- * FullscreenChanged: Callback triggered by the fullscreen-change playlist
- * variable, to let the intf update the controller.
- *****************************************************************************/
-static int FullscreenChanged(vlc_object_t *p_this, const char *psz_variable,
-                     vlc_value_t old_val, vlc_value_t new_val, void *param)
-{
-    intf_thread_t * p_intf = VLCIntf;
-    if (p_intf) {
-        NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
-        [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(fullscreenChanged) withObject:nil waitUntilDone:NO];
-        [o_pool release];
-    }
-    return VLC_SUCCESS;
-}
-
 /*****************************************************************************
  * DialogCallback: Callback triggered by the "dialog-*" variables
  * to let the intf display error and interaction dialogs
@@ -445,7 +505,10 @@ void updateProgressPanel (void *priv, const char *text, float value)
 void destroyProgressPanel (void *priv)
 {
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
-    [[[VLCMain sharedInstance] coreDialogProvider] destroyProgressPanel];
+
+    if ([[NSApplication sharedApplication] isRunning])
+        [[[VLCMain sharedInstance] coreDialogProvider] performSelectorOnMainThread:@selector(destroyProgressPanel) withObject:nil waitUntilDone:YES];
+
     [o_pool release];
 }
 
@@ -477,21 +540,43 @@ vout_thread_t *getVout(void)
     return p_vout;
 }
 
+vout_thread_t *getVoutForActiveWindow(void)
+{
+    vout_thread_t *p_vout = nil;
+
+    id currentWindow = [NSApp keyWindow];
+    if ([currentWindow respondsToSelector:@selector(videoView)]) {
+        VLCVoutView *videoView = [currentWindow videoView];
+        if (videoView) {
+            p_vout = [videoView voutThread];
+        }
+    }
+
+    if (!p_vout)
+        p_vout = getVout();
+
+    return p_vout;
+}
+
 audio_output_t *getAout(void)
 {
-    input_thread_t *p_input = getInput();
-    if (!p_input)
+    intf_thread_t *p_intf = VLCIntf;
+    if (!p_intf)
         return NULL;
-    audio_output_t *p_aout = input_GetAout(p_input);
-    vlc_object_release(p_input);
-    return p_aout;
+    return playlist_GetAout(pl_Get(p_intf));
 }
 
 #pragma mark -
 #pragma mark Private
 
 @interface VLCMain ()
-- (void)_removeOldPreferences;
+- (void)removeOldPreferences;
+@end
+
+@interface VLCMain (Internal)
+- (void)handlePortMessage:(NSPortMessage *)o_msg;
+- (void)resetMediaKeyJump;
+- (void)coreChangedMediaKeySupportSetting: (NSNotification *)o_notification;
 @end
 
 /*****************************************************************************
@@ -499,6 +584,9 @@ audio_output_t *getAout(void)
  *****************************************************************************/
 @implementation VLCMain
 
+@synthesize voutController=o_vout_controller;
+@synthesize nativeFullscreenMode=b_nativeFullscreenMode;
+
 #pragma mark -
 #pragma mark Initialization
 
@@ -518,7 +606,7 @@ static VLCMain *_o_sharedMainInstance = nil;
         _o_sharedMainInstance = [super init];
 
     p_intf = NULL;
-    p_current_input = NULL;
+    p_current_input = p_input_changed = NULL;
 
     o_msg_lock = [[NSLock alloc] init];
     o_msg_arr = [[NSMutableArray arrayWithCapacity: 600] retain];
@@ -541,6 +629,8 @@ static VLCMain *_o_sharedMainInstance = nil;
     NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"LiveUpdateTheMessagesPanel"];
     [defaults registerDefaults:appDefaults];
 
+    o_vout_controller = [[VLCVoutWindowController alloc] init];
+
     return _o_sharedMainInstance;
 }
 
@@ -573,11 +663,9 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     val.b_bool = false;
 
-    var_AddCallback(p_playlist, "fullscreen", FullscreenChanged, self);
     var_AddCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
     var_AddCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
     //    var_AddCallback(p_playlist, "item-change", PLItemChanged, self);
-    var_AddCallback(p_playlist, "item-current", PLItemChanged, self);
     var_AddCallback(p_playlist, "activity", PLItemChanged, self);
     var_AddCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
     var_AddCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
@@ -624,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.
@@ -667,7 +749,7 @@ static VLCMain *_o_sharedMainInstance = nil;
     }
     [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(coreChangedMediaKeySupportSetting:) name: @"VLCMediaKeySupportSettingChanged" object: nil];
 
-    [self _removeOldPreferences];
+    [self removeOldPreferences];
 
     /* Handle sleep notification */
     [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
@@ -735,6 +817,10 @@ static VLCMain *_o_sharedMainInstance = nil;
         [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
     }
 
+    /* save current video and audio profiles */
+    [[VLCVideoEffects sharedInstance] saveCurrentProfile];
+    [[VLCAudioEffects sharedInstance] saveCurrentProfile];
+
     /* Save some interface state in configuration, at module quit */
     config_PutInt(p_intf, "random", var_GetBool(p_playlist, "random"));
     config_PutInt(p_intf, "loop", var_GetBool(p_playlist, "loop"));
@@ -750,7 +836,6 @@ static VLCMain *_o_sharedMainInstance = nil;
     var_DelCallback(p_intf, "dialog-question", DialogCallback, self);
     var_DelCallback(p_intf, "dialog-progress-bar", DialogCallback, self);
     //var_DelCallback(p_playlist, "item-change", PLItemChanged, self);
-    var_DelCallback(p_playlist, "item-current", PLItemChanged, self);
     var_DelCallback(p_playlist, "activity", PLItemChanged, self);
     var_DelCallback(p_playlist, "leaf-to-parent", PlaylistUpdated, self);
     var_DelCallback(p_playlist, "playlist-item-append", PlaylistUpdated, self);
@@ -760,7 +845,6 @@ static VLCMain *_o_sharedMainInstance = nil;
     var_DelCallback(p_playlist, "loop", PlaybackModeUpdated, self);
     var_DelCallback(p_playlist, "volume", VolumeUpdated, self);
     var_DelCallback(p_playlist, "mute", VolumeUpdated, self);
-    var_DelCallback(p_playlist, "fullscreen", FullscreenChanged, self);
     var_DelCallback(p_intf->p_libvlc, "intf-toggle-fscontrol", ShowController, self);
     var_DelCallback(p_intf->p_libvlc, "intf-show", ShowController, self);
 
@@ -773,6 +857,10 @@ static VLCMain *_o_sharedMainInstance = nil;
     /* remove global observer watching for vout device changes correctly */
     [[NSNotificationCenter defaultCenter] removeObserver: self];
 
+    // release before o_info!
+    [o_vout_controller release];
+    o_vout_controller = nil;
+
     /* release some other objects here, because it isn't sure whether dealloc
      * will be called later on */
     if (o_sprefs)
@@ -809,6 +897,7 @@ static VLCMain *_o_sharedMainInstance = nil;
     /* write cached user defaults to disk */
     [[NSUserDefaults standardUserDefaults] synchronize];
 
+
     [o_mainmenu release];
 
     libvlc_Quit(p_intf->p_libvlc);
@@ -843,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)
@@ -964,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) {
@@ -991,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"))
@@ -1098,8 +1185,6 @@ static VLCMain *_o_sharedMainInstance = nil;
                 case NSBackspaceCharacter:
                 case NSUpArrowFunctionKey:
                 case NSDownArrowFunctionKey:
-                case NSRightArrowFunctionKey:
-                case NSLeftArrowFunctionKey:
                 case NSEnterCharacter:
                 case NSCarriageReturnCharacter:
                     return NO;
@@ -1107,7 +1192,7 @@ static VLCMain *_o_sharedMainInstance = nil;
         }
 
         if (key == 0x0020) { // space key
-            [[VLCCoreInteraction sharedInstance] play];
+            [[VLCCoreInteraction sharedInstance] playOrPause];
             return YES;
         }
 
@@ -1168,51 +1253,12 @@ static VLCMain *_o_sharedMainInstance = nil;
 
 #pragma mark -
 #pragma mark Interface updaters
-- (void)fullscreenChanged
-{
-    playlist_t * p_playlist = pl_Get(VLCIntf);
-    BOOL b_fullscreen = var_GetBool(p_playlist, "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 {
-        if (b_fullscreen) {
-            input_thread_t * p_input = pl_CurrentInput(VLCIntf);
-            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_mainwindow performSelectorOnMainThread:@selector(enterFullscreen) withObject:nil waitUntilDone:NO];
-            }
-            if (p_input)
-                vlc_object_release(p_input);
-        } else {
-            // leaving fullscreen is always allowed
-            [o_mainwindow performSelectorOnMainThread:@selector(leaveFullscreen) withObject:nil waitUntilDone:NO];
-        }
-    }
-}
-
-- (void)checkFullscreenChange:(NSNumber *)o_full
-{
-    BOOL b_full = [o_full boolValue];
-    if (p_intf && !var_GetBool(pl_Get(p_intf), "fullscreen") != !b_full) {
-        var_SetBool(pl_Get(p_intf), "fullscreen", b_full);
-    }
-}
 
 - (void)PlaylistItemChanged
 {
     if (p_current_input && (p_current_input->b_dead || !vlc_object_alive(p_current_input))) {
         var_DelCallback(p_current_input, "intf-event", InputEvent, [VLCMain sharedInstance]);
-        vlc_object_release(p_current_input);
+        p_input_changed = p_current_input;
         p_current_input = NULL;
 
         [o_mainmenu setRateControlsEnabled: NO];
@@ -1226,6 +1272,7 @@ static VLCMain *_o_sharedMainInstance = nil;
             [o_mainmenu setRateControlsEnabled: YES];
             if ([self activeVideoPlayback] && [[o_mainwindow videoView] isHidden])
                 [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject: nil waitUntilDone:NO];
+            p_input_changed = vlc_object_hold(p_current_input);
         }
     }
 
@@ -1235,10 +1282,20 @@ static VLCMain *_o_sharedMainInstance = nil;
     [self updateMainMenu];
 }
 
+- (void)informInputChanged
+{
+    if (p_input_changed) {
+        [[ExtensionsManager getInstance:p_intf] inputChanged:p_input_changed];
+        vlc_object_release(p_input_changed);
+        p_input_changed = NULL;
+    }
+}
+
 - (void)updateMainMenu
 {
     [o_mainmenu setupMenus];
     [o_mainmenu updatePlaybackRate];
+    [[VLCCoreInteraction sharedInstance] resetAtoB];
 }
 
 - (void)updateMainWindow
@@ -1269,6 +1326,7 @@ static VLCMain *_o_sharedMainInstance = nil;
 - (void)updatePlaybackPosition
 {
     [o_mainwindow updateTimeSlider];
+    [[VLCCoreInteraction sharedInstance] updateAtoB];
 }
 
 - (void)updateVolume
@@ -1302,11 +1360,30 @@ 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);
+                IOPMAssertionRelease(systemSleepAssertionID);
+            }
+
             IOReturn success;
             /* work-around a bug in 10.7.4 and 10.7.5, so check for 10.7.x < 10.7.4, 10.8 and 10.6 */
             if ((NSAppKitVersionNumber >= 1115.2 && NSAppKitVersionNumber < 1138.45) || OSX_MOUNTAIN_LION || OSX_SNOW_LEOPARD) {
-                CFStringRef reasonForActivity= CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
+                CFStringRef reasonForActivity = CFStringCreateWithCString(kCFAllocatorDefault, _("VLC media playback"), kCFStringEncodingUTF8);
                 if ([self activeVideoPlayback])
                     success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &systemSleepAssertionID);
                 else
@@ -1334,8 +1411,10 @@ static VLCMain *_o_sharedMainInstance = nil;
             [o_mainwindow setPlay];
 
             /* allow the system to sleep again */
-            msg_Dbg(VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID);
-            IOPMAssertionRelease(systemSleepAssertionID);
+            if (systemSleepAssertionID > 0) {
+                msg_Dbg(VLCIntf, "releasing sleep blocker (%i)" , systemSleepAssertionID);
+                IOPMAssertionRelease(systemSleepAssertionID);
+            }
         }
         vlc_object_release(p_input);
     }
@@ -1378,16 +1457,7 @@ static VLCMain *_o_sharedMainInstance = nil;
 #pragma mark -
 #pragma mark Window updater
 
-- (void)setWindowLevel:(NSNumber*)state
-{
-    if (var_InheritBool(p_intf, "video-wallpaper") || [[[[VLCMainWindow sharedInstance] videoView] window] level] < NSNormalWindowLevel)
-        return;
 
-    if ([state unsignedIntValue] & VOUT_WINDOW_STATE_ABOVE)
-        [[[[VLCMainWindow sharedInstance] videoView] window] setLevel: NSStatusWindowLevel];
-    else
-        [[[[VLCMainWindow sharedInstance] videoView] window] setLevel: NSNormalWindowLevel];
-}
 
 - (void)setActiveVideoPlayback:(BOOL)b_value
 {
@@ -1396,11 +1466,9 @@ static VLCMain *_o_sharedMainInstance = nil;
         [o_mainwindow performSelectorOnMainThread:@selector(setVideoplayEnabled) withObject:nil waitUntilDone:YES];
         [o_mainwindow performSelectorOnMainThread:@selector(togglePlaylist:) withObject:nil waitUntilDone:NO];
     }
-}
 
-- (void)setNativeVideoSize:(NSSize)size
-{
-    [o_mainwindow setNativeVideoSize:size];
+    // update sleep blockers
+    [self performSelectorOnMainThread:@selector(playbackStatusUpdated) withObject:nil waitUntilDone:NO];
 }
 
 #pragma mark -
@@ -1499,23 +1567,6 @@ static VLCMain *_o_sharedMainInstance = nil;
     return o_wizard;
 }
 
-- (id)getVideoViewAtPositionX: (int *)pi_x Y: (int *)pi_y withWidth: (unsigned int*)pi_width andHeight: (unsigned int*)pi_height
-{
-    [o_mainwindow performSelectorOnMainThread:@selector(setupVideoView) withObject:nil waitUntilDone:YES];
-    id videoView = [o_mainwindow videoView];
-    NSRect videoRect = [videoView frame];
-    int i_x = (int)videoRect.origin.x;
-    int i_y = (int)videoRect.origin.y;
-    unsigned int i_width = (int)videoRect.size.width;
-    unsigned int i_height = (int)videoRect.size.height;
-    pi_x = &i_x;
-    pi_y = &i_y;
-    pi_width = &i_width;
-    pi_height = &i_height;
-    msg_Dbg(VLCIntf, "returning videoview with x=%i, y=%i, width=%i, height=%i", i_x, i_y, i_width, i_height);
-    return videoView;
-}
-
 - (id)coreDialogProvider
 {
     if (o_coredialogs)
@@ -1687,14 +1738,14 @@ static VLCMain *_o_sharedMainInstance = nil;
     if (latestLog) {
         [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
     } else {
-        NSBeginInformationalAlertSheet(_NS("No CrashLog found"), _NS("Continue"), nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Couldn't find any trace of a previous crash."));
+        NSBeginInformationalAlertSheet(_NS("No CrashLog found"), _NS("Continue"), nil, nil, o_msgs_panel, self, NULL, NULL, nil, @"%@", _NS("Couldn't find any trace of a previous crash."));
     }
 }
 
 #pragma mark -
 #pragma mark Remove old prefs
 
-- (void)_removeOldPreferences
+- (void)removeOldPreferences
 {
     static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
     static const int kCurrentPreferencesVersion = 2;