]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/intf.m
macosx: added an option to disable the native fullscreen mode on Lion
[vlc] / modules / gui / macosx / intf.m
index 03b7cac05d1b916aac1611b7988b77fe61835a6c..64265cb3d547c5796a55c1a0cd8b4cfef073ebcf 100644 (file)
 #include <vlc_vout_window.h>
 #include <unistd.h> /* execl() */
 
+#import "CompatibilityFixes.h"
 #import "intf.h"
 #import "MainMenu.h"
-#import "MainWindow.h"
-#import "fspanel.h"
 #import "vout.h"
 #import "prefs.h"
 #import "playlist.h"
@@ -71,7 +70,7 @@ static void updateProgressPanel (void *, const char *, float);
 static bool checkProgressPanel (void *);
 static void destroyProgressPanel (void *);
 
-static void MsgCallback( msg_cb_data_t *, const msg_item_t * );
+static void MsgCallback( void *data, int type, const msg_item_t *item, const char *format, va_list ap );
 
 static int InputEvent( vlc_object_t *, const char *,
                       vlc_value_t, vlc_value_t, void * );
@@ -103,7 +102,7 @@ int OpenIntf ( vlc_object_t *p_this )
     memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
 
     /* subscribe to LibVLCCore's messages */
-    p_intf->p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, NULL );
+    p_intf->p_sys->p_sub = vlc_Subscribe( MsgCallback, NULL );
     p_intf->pf_run = Run;
     p_intf->b_should_run_on_first_thread = true;
 
@@ -132,7 +131,6 @@ int WindowOpen( vout_window_t *p_wnd, const vout_window_cfg_t *cfg )
         return VLC_EGENERIC;
     }
 
-    msg_Dbg( p_wnd, "looking for video view" );
     int i_x = cfg->x;
     int i_y = cfg->y;
     unsigned i_width = cfg->width;
@@ -145,6 +143,7 @@ int WindowOpen( vout_window_t *p_wnd, const vout_window_cfg_t *cfg )
         return VLC_EGENERIC;
     }
 
+    [[VLCMain sharedInstance] setNativeVideoSize:NSMakeSize( cfg->width, cfg->height )];
     [[VLCMain sharedInstance] setActiveVideoPlayback: YES];
     p_wnd->control = WindowControl;
     p_wnd->sys = (vout_window_sys_t *)VLCIntf;
@@ -158,7 +157,12 @@ static int WindowControl( vout_window_t *p_wnd, int i_query, va_list args )
     if( i_query == VOUT_WINDOW_SET_STATE )
         NSLog( @"WindowControl:VOUT_WINDOW_SET_STATE" );
     else if( i_query == VOUT_WINDOW_SET_SIZE )
+    {
         NSLog( @"WindowControl:VOUT_WINDOW_SET_SIZE" );
+        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 )];
+    }
     else if( i_query == VOUT_WINDOW_SET_FULLSCREEN )
         NSLog( @"WindowControl:VOUT_WINDOW_SET_FULLSCREEN" );
     else
@@ -215,19 +219,23 @@ static void Run( intf_thread_t *p_intf )
  * ready to be displayed. We store everything in a NSArray in our Cocoa part
  * of this file.
  *****************************************************************************/
-static void MsgCallback( msg_cb_data_t *data, const msg_item_t *item )
+static void MsgCallback( void *data, int type, const msg_item_t *item, const char *format, va_list ap )
 {
     int canc = vlc_savecancel();
+    char *str;
 
-    /* this may happen from time to time, let's bail out as info would be useless anyway */
-    if( !item->psz_module || !item->psz_msg )
+    if (vasprintf( &str, format, ap ) == -1)
+    {
+        vlc_restorecancel( canc );
         return;
+    }
 
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
-    [[VLCMain sharedInstance] processReceivedlibvlcMessage: item];
+    [[VLCMain sharedInstance] processReceivedlibvlcMessage: item ofType: type withStr: str];
     [o_pool release];
 
     vlc_restorecancel( canc );
+    free( str );
 }
 
 static int InputEvent( vlc_object_t *p_this, const char *psz_var,
@@ -246,6 +254,7 @@ static int InputEvent( vlc_object_t *p_this, const char *psz_var,
             break;
         case INPUT_EVENT_TITLE:
         case INPUT_EVENT_CHAPTER:
+            [[VLCMain sharedInstance] updateMainMenu];
             break;
         case INPUT_EVENT_CACHE:
             [[VLCMain sharedInstance] updateMainWindow];
@@ -256,7 +265,6 @@ static int InputEvent( vlc_object_t *p_this, const char *psz_var,
         case INPUT_EVENT_ES:
             break;
         case INPUT_EVENT_TELETEXT:
-            NSLog( @"teletext" );
             break;
         case INPUT_EVENT_AOUT:
             break;
@@ -264,14 +272,17 @@ static int InputEvent( vlc_object_t *p_this, const char *psz_var,
             break;
         case INPUT_EVENT_ITEM_META:
         case INPUT_EVENT_ITEM_INFO:
+            [[VLCMain sharedInstance] updateMainMenu];
             [[VLCMain sharedInstance] updateName];
             [[VLCMain sharedInstance] updateInfoandMetaPanel];
             break;
         case INPUT_EVENT_BOOKMARK:
             break;
         case INPUT_EVENT_RECORD:
+            [[VLCMain sharedInstance] updateRecordState: var_GetBool( p_this, "record" )];
             break;
         case INPUT_EVENT_PROGRAM:
+            [[VLCMain sharedInstance] updateMainMenu];
             break;
         case INPUT_EVENT_ITEM_EPG:
             break;
@@ -294,7 +305,8 @@ static int InputEvent( vlc_object_t *p_this, const char *psz_var,
             break;
 
         case INPUT_EVENT_ABORT:
-            //NSLog( @"input stopped by user" );
+            [[VLCMain sharedInstance] updateName];
+            [[VLCMain sharedInstance] updatePlaybackPosition];
             break;
 
         default:
@@ -340,7 +352,7 @@ static int VolumeUpdated( 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] updateVolume];
+    [[VLCMain sharedInstance] performSelectorOnMainThread:@selector(updateVolume) withObject:nil waitUntilDone:NO];
 
     [o_pool release];
     return VLC_SUCCESS;
@@ -357,12 +369,7 @@ static int ShowController( vlc_object_t *p_this, const char *psz_variable,
     intf_thread_t * p_intf = VLCIntf;
     if( p_intf && p_intf->p_sys )
     {
-        NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
-        if( [[[VLCCoreInteraction sharedInstance] voutView] isFullscreen] && config_GetInt( VLCIntf, "macosx-fspanel" ) )
-            [[[[VLCMain sharedInstance] controls] fspanel] fadeIn];
-        else
-            [[VLCMainWindow sharedInstance] makeKeyAndOrderFront: nil];
-        [o_pool release];
+//        [[[VLCMain sharedInstance] fspanel] makeKeyAndOrderFront: nil];
     }
     return VLC_SUCCESS;
 }
@@ -375,8 +382,12 @@ 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 && p_intf->p_sys )
-        NSLog( @"we should update fullscreen state" ); //FIXME
+    if (p_intf)
+    {
+        NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+        [[VLCMain sharedInstance] fullscreenChanged];
+        [o_pool release];
+    }
     return VLC_SUCCESS;
 }
 
@@ -503,8 +514,6 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     o_msg_lock = [[NSLock alloc] init];
     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];
 
     o_open = [[VLCOpen alloc] init];
     //o_embedded_list = [[VLCEmbeddedList alloc] init];
@@ -563,6 +572,9 @@ static VLCMain *_o_sharedMainInstance = nil;
     var_AddCallback(p_playlist, "volume", VolumeUpdated, self);
     var_AddCallback(p_playlist, "mute", VolumeUpdated, self);
 
+    if ([NSApp currentSystemPresentationOptions] == NSApplicationPresentationFullScreen)
+        var_SetBool( p_playlist, "fullscreen", YES );
+
     /* load our Core Dialogs nib */
     nib_coredialogs_loaded = [NSBundle loadNibNamed:@"CoreDialogs" owner: NSApp];
 
@@ -587,6 +599,7 @@ static VLCMain *_o_sharedMainInstance = nil;
     [o_remote setDelegate: _o_sharedMainInstance];
 
     /* yeah, we are done */
+    b_nativeFullscreenMode = config_GetInt( p_intf, "macosx-nativefullscreenmode" );
     nib_main_loaded = TRUE;
 }
 
@@ -608,6 +621,9 @@ static VLCMain *_o_sharedMainInstance = nil;
 
     [self _removeOldPreferences];
 
+    [o_mainwindow updateWindow];
+    [o_mainwindow updateTimeSlider];
+    [o_mainwindow updateVolumeSlider];
     [o_mainwindow makeKeyAndOrderFront: self];
 
     /* Handle sleep notification */
@@ -712,7 +728,7 @@ static VLCMain *_o_sharedMainInstance = nil;
     [o_mainwindow release];
 
     /* unsubscribe from libvlc's debug messages */
-    msg_Unsubscribe( p_intf->p_sys->p_sub );
+    vlc_Unsubscribe( p_intf->p_sys->p_sub );
 
     [o_msg_arr removeAllObjects];
     [o_msg_arr release];
@@ -743,10 +759,6 @@ static VLCMain *_o_sharedMainInstance = nil;
     [NSApp activateIgnoringOtherApps:YES];
     [o_remote stopListening: self];
     var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_STOP );
-
-    /* Close the window directly, because we do know that there
-     * won't be anymore video. It's currently waiting a bit. */
-    [[[o_coreinteraction voutView] window] orderOut:self];
 }
 
 #pragma mark -
@@ -1223,12 +1235,39 @@ unsigned int CocoaKeyToVLC( unichar i_key )
         }
     }
     module_config_free (p_config);
-    module_release (p_main);
     o_usedHotkeys = [[NSArray alloc] initWithArray: o_usedHotkeys copyItems: YES];
 }
 
 #pragma mark -
 #pragma mark Interface updaters
+- (void)fullscreenChanged
+{
+    playlist_t * p_playlist = pl_Get( VLCIntf );
+    BOOL b_fullscreen = var_GetBool( p_playlist, "fullscreen" );
+
+    if (OSX_LION && b_nativeFullscreenMode)
+    {
+        [o_mainwindow toggleFullScreen: self];
+        if(b_fullscreen)
+            [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen)];
+        else
+            [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
+    }
+    else
+    {
+        input_thread_t * p_input = pl_CurrentInput( VLCIntf );
+
+        if( p_input != NULL )
+        {
+            if(b_fullscreen)
+                [o_mainwindow performSelectorOnMainThread:@selector(enterFullscreen) withObject:nil waitUntilDone:NO];
+            else
+                [o_mainwindow performSelectorOnMainThread:@selector(leaveFullscreen) withObject:nil waitUntilDone:NO];
+            vlc_object_release( p_input );
+        }
+    }
+}
+
 - (void)PlaylistItemChanged
 {
     input_thread_t * p_input;
@@ -1240,10 +1279,16 @@ unsigned int CocoaKeyToVLC( unichar i_key )
         [o_mainmenu setRateControlsEnabled: YES];
         vlc_object_release( p_input );
     }
-    else[o_mainmenu setRateControlsEnabled: NO];
+    else
+        [o_mainmenu setRateControlsEnabled: NO];
 
     [o_playlist updateRowSelection];
     [o_mainwindow updateWindow];
+    [self updateMainMenu];
+}
+
+- (void)updateMainMenu
+{
     [o_mainmenu setupMenus];
     [o_mainmenu updatePlaybackRate];
 }
@@ -1253,6 +1298,11 @@ unsigned int CocoaKeyToVLC( unichar i_key )
     [o_mainwindow updateWindow];
 }
 
+- (void)showFullscreenController
+{
+    [o_mainwindow showFullscreenController];
+}
+
 - (void)updateDelays
 {
     [[VLCTrackSynchronization sharedInstance] performSelectorOnMainThread: @selector(updateValues) withObject: nil waitUntilDone:NO];
@@ -1266,6 +1316,15 @@ unsigned int CocoaKeyToVLC( unichar i_key )
 - (void)updatePlaybackPosition
 {
     [o_mainwindow updateTimeSlider];
+
+    input_thread_t * p_input;
+    p_input = pl_CurrentInput( p_intf );
+    if( p_input )
+    {
+        if( var_GetInteger( p_input, "state" ) == PLAYING_S )
+            UpdateSystemActivity( UsrActivity );
+        vlc_object_release( p_input );
+    }
 }
 
 - (void)updateVolume
@@ -1277,6 +1336,13 @@ unsigned int CocoaKeyToVLC( unichar i_key )
 {
     [self playbackStatusUpdated];
     [o_playlist playlistUpdated];
+    [o_mainwindow updateWindow];
+    [o_mainwindow updateName];
+}
+
+- (void)updateRecordState: (BOOL)b_value
+{
+    [o_mainmenu updateRecordState:b_value];
 }
 
 - (void)updateInfoandMetaPanel
@@ -1294,7 +1360,6 @@ unsigned int CocoaKeyToVLC( unichar i_key )
         int state = var_GetInteger( p_input, "state" );
         if( state == PLAYING_S )
         {
-            [[[self controls] fspanel] setPause];
             [[self mainMenu] setPause];
             [o_mainwindow setPause];
         }
@@ -1302,7 +1367,6 @@ unsigned int CocoaKeyToVLC( unichar i_key )
         {
             if (state == END_S)
                 [o_mainmenu setSubmenusEnabled: FALSE];
-            [[[self controls] fspanel] setPlay];
             [[self mainMenu] setPlay];
             [o_mainwindow setPlay];
         }
@@ -1440,6 +1504,11 @@ unsigned int CocoaKeyToVLC( unichar i_key )
     return videoView;
 }
 
+- (void)setNativeVideoSize:(NSSize)size
+{
+    [o_mainwindow setNativeVideoSize:size];
+}
+
 - (id)embeddedList
 {
     if( o_embedded_list )
@@ -1708,7 +1777,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
     }
 }
 
-- (void)processReceivedlibvlcMessage:(const msg_item_t *)item
+- (void)processReceivedlibvlcMessage:(const msg_item_t *) item ofType: (int)i_type withStr: (char *)str
 {
     NSColor *o_white = [NSColor whiteColor];
     NSColor *o_red = [NSColor redColor];
@@ -1721,8 +1790,6 @@ unsigned int CocoaKeyToVLC( unichar i_key )
     NSDictionary *o_attr;
     NSAttributedString *o_msg_color;
 
-    int i_type = item->i_type;
-
     [o_msg_lock lock];
 
     if( [o_msg_arr count] + 2 > 600 )
@@ -1736,7 +1803,7 @@ unsigned int CocoaKeyToVLC( unichar i_key )
     [o_msg_arr addObject: [o_msg_color autorelease]];
 
     o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type] forKey: NSForegroundColorAttributeName];
-    o_msg_color = [[NSAttributedString alloc] initWithString: [NSString stringWithFormat: @"%s\n", item->psz_msg] attributes: o_attr];
+    o_msg_color = [[NSAttributedString alloc] initWithString: [NSString stringWithFormat: @"%s\n", str] attributes: o_attr];
     [o_msg_arr addObject: [o_msg_color autorelease]];
 
     b_msg_arr_changed = YES;
@@ -1747,10 +1814,8 @@ unsigned int CocoaKeyToVLC( unichar i_key )
 
 - (IBAction)saveDebugLog:(id)sender
 {
-    NSOpenPanel * saveFolderPanel = [[NSSavePanel alloc] init];
+    NSSavePanel * saveFolderPanel = [[NSSavePanel alloc] init];
 
-    [saveFolderPanel setCanChooseDirectories: NO];
-    [saveFolderPanel setCanChooseFiles: YES];
     [saveFolderPanel setCanSelectHiddenExtension: NO];
     [saveFolderPanel setCanCreateDirectories: YES];
     [saveFolderPanel setAllowedFileTypes: [NSArray arrayWithObject:@"rtfd"]];