]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/vout.m
macosx: Close embedded if fullscreen ended.
[vlc] / modules / gui / macosx / vout.m
index bc7900e9ba4af45ceddbd17678ff61a14a723029..aca5b877862e6543f32e949fa2d988e048807b14 100644 (file)
@@ -10,7 +10,7 @@
  *          Derk-Jan Hartman <hartman at videolan dot org>
  *          Eric Petit <titer@m0k.org>
  *          Benjamin Pracht <bigben at videolan dot org>
- *          Felix Kühne <fkuehne at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * 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
@@ -58,7 +58,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
     var_Set( p_vout->p_libvlc, "video-device", new_val );
 
-    val.b_bool = VLC_TRUE;
+    val.b_bool = true;
     var_Set( p_vout, "intf-change", val );
     return VLC_SUCCESS;
 }
@@ -194,7 +194,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
                                             VLC_VAR_HASCHOICE );
-        text.psz_string = _("Video Device");
+        text.psz_string = _("Fullscreen Video Device");
         var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
 
         NSEnumerator * o_enumerator = [o_screens objectEnumerator];
@@ -228,7 +228,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         var_AddCallback( p_real_vout, "video-device", DeviceCallback,
                          NULL );
 
-        val2.b_bool = VLC_TRUE;
+        val2.b_bool = true;
         var_Set( p_real_vout, "intf-change", val2 );
     }
 
@@ -407,11 +407,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if( !p_real_vout ) return;
     if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
     {
-        val.b_bool = VLC_FALSE;
+        val.b_bool = false;
     }
     else
     {
-        val.b_bool = VLC_TRUE;
+        val.b_bool = true;
     }
     var_Set( p_real_vout, "video-on-top", val );
 }
@@ -573,7 +573,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if( p_vout && [o_event type] == NSLeftMouseUp )
     {
         vlc_value_t b_val;
-        b_val.b_bool = VLC_TRUE;
+        b_val.b_bool = true;
         var_Set( p_vout, "mouse-clicked", b_val );
 
         var_Get( p_vout, "mouse-button-down", &val );
@@ -663,7 +663,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
             }
             var_Set( p_vout, "mouse-y", val );
 
-            val.b_bool = VLC_TRUE;
+            val.b_bool = true;
             var_Set( p_vout, "mouse-moved", val );
         }
         if( [self isFullscreen] )
@@ -722,7 +722,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-
+    var_Create( p_vout, "embedded-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
     /* We only wait for NSApp to initialise if we're not embedded (as in the
      * case of the Mozilla plugin).  We can tell whether we're embedded or not
@@ -770,12 +770,22 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (void)enterFullscreen
 {
+    if( var_GetBool( p_real_vout, "video-on-top" ) )
+    {
+        [o_window setLevel: NSNormalWindowLevel];
+    }
+
     [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
 }
 
 - (void)leaveFullscreen
 {
+    if( var_GetBool( p_real_vout, "video-on-top" ) )
+    {
+        [o_window setLevel: NSStatusWindowLevel];
+    }
+
     [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
     [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
 }
@@ -809,7 +819,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         [o_window setLevel: NSStatusWindowLevel];
     }
 
-
     [o_window setAcceptsMouseMovedEvents: TRUE];
     return b_return;
 }
@@ -851,9 +860,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 - (void)manage
 {
     [super manage];
+    unsigned int i_mouse_hide_timeout =
+        var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
     if( p_vout->b_fullscreen )
     {
-        if( mdate() - i_time_mouse_last_moved > 3000000 )
+        if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout )
         {
             [self hideMouse: YES];
         }
@@ -872,11 +883,19 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 @implementation VLCEmbeddedVoutView
 
+- (void)awakeFromNib
+{
+    o_embeddedwindow = [self window];
+}
+
 - (id)initWithFrame: (NSRect)frameRect
 {
-    [super initWithFrame: frameRect];
-    b_used = NO;
-    [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
+    if(self = [super initWithFrame: frameRect])
+    {
+        b_used = NO;
+        [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
+        o_embeddedwindow = nil; /* Filled later on in -awakeFromNib */
+    }
     return self;
 }
 
@@ -884,6 +903,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
                  frame: (NSRect *)s_arg_frame showWindow: (BOOL)b_show_window
 {
     BOOL b_return;
+
+    [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
+
     b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
     if( b_return )
     {
@@ -899,46 +921,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         [view setFrameSize: [self frame].size];
     }
-    return b_return;
-}
-
-- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
-                     frame: (NSRect *) s_arg_frame
-
-{
-    return [self setVout: p_arg_vout subView: view frame:s_arg_frame showWindow: YES];
-}
-
-- (void)setUsed: (BOOL)b_new_used
-{
-    b_used = b_new_used;
-}
-
-- (BOOL)isUsed
-{
-    return b_used;
-}
-
-- (void)closeVout
-{
-    [super closeVout];
-    [o_window setAcceptsMouseMovedEvents: NO];
-    [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
-}
-
-
-@end
-
-@implementation VLCDetachedEmbeddedVoutView
-- (void)awakeFromNib
-{
-    o_embeddedwindow = [self window];
-}
-
-- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
-                     frame: (NSRect *) s_arg_frame
-{
-    BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame showWindow: NO];
 
     /* o_window needs to point to our o_embeddedwindow, super might have set it
      * to the fullscreen window that o_embeddedwindow setups during fullscreen */
@@ -952,6 +934,8 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         [self updateTitle];
 
+        [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
+
         /* Make the window the front and key window before animating */
         if ([o_window isVisible] && (![o_window isFullscreen]))
             [o_window makeKeyAndOrderFront: self];
@@ -966,19 +950,37 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         [o_window unlockFullscreenAnimation];
 
     }
+
     return b_return;
 }
 
-- (void)closeVout
+- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
+                     frame: (NSRect *) s_arg_frame
+
 {
-    playlist_t * p_playlist = pl_Yield( VLCIntf );
+    return [self setVout: p_arg_vout subView: view frame:s_arg_frame showWindow: YES];
+}
 
-    if(!playlist_IsPlaying( p_playlist ))
-        [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES];
-    vlc_object_release( p_playlist );
+- (void)setUsed: (BOOL)b_new_used
+{
+    b_used = b_new_used;
+}
+
+- (BOOL)isUsed
+{
+    return b_used;
+}
+
+- (void)closeVout
+{
+    /* Don't close the window yet, wait a bit to see if a new input is poping up */
+    /* FIXME: Probably fade the window In and Out */
+    /* FIXME: fix core */
+    [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:1.5];
 
     [super closeVout];
+    [o_window setAcceptsMouseMovedEvents: NO];
+    [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
 }
 
 - (void)enterFullscreen
@@ -1006,7 +1008,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     o_view  = view;
     s_frame = frame;
 
-    [self performSelectorOnMainThread: @selector(initReal:)
+    [self performSelectorOnMainThread: @selector(initMainThread:)
         withObject: NULL waitUntilDone: YES];
 
     if( !b_init_ok )
@@ -1017,15 +1019,15 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return self;
 }
 
-- (id)initReal: (id) sender
+- (id)initMainThread: (id) sender
 {
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
     NSArray *o_screens = [NSScreen screens];
     NSScreen *o_screen;
-    vlc_bool_t b_menubar_screen = VLC_FALSE;
+    bool b_menubar_screen = false;
     int i_device;
 
-    b_init_ok = VLC_FALSE;
+    b_init_ok = false;
 
     p_real_vout = [VLCVoutView getRealVout: p_vout];
     i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
@@ -1039,7 +1041,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         o_screen = [NSScreen mainScreen];
 
     if( [o_screen isMainScreen] )
-        b_menubar_screen = VLC_TRUE;
+        b_menubar_screen = true;
 
     if( p_vout->b_fullscreen )
     {
@@ -1067,7 +1069,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         {
             SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
         }
-        if( b_black == VLC_TRUE )
+        if( b_black == true )
         {
             CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
             CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
@@ -1133,7 +1135,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     [o_pool release];
 
-    b_init_ok = VLC_TRUE;
+    b_init_ok = true;
     return self;
 }
 
@@ -1146,13 +1148,13 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 {
     /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
        Command-Q */
-    [self performSelectorOnMainThread: @selector(closeReal:)
+    [self performSelectorOnMainThread: @selector(closeMainThread:)
         withObject: NULL waitUntilDone: NO];
 }
 
-- (id)closeReal:(id)sender
+- (id)closeMainThread:(id)sender
 {
-    if( b_black == VLC_TRUE )
+    if( b_black == true )
     {
         CGDisplayFadeReservationToken token;
         CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
@@ -1170,7 +1172,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     SetSystemUIMode( kUIModeNormal, 0);
     [super close];
     /* this does only work in embedded mode */
-    if( b_embedded == VLC_TRUE )
+    if( b_embedded == true )
         [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
 
     return NULL;
@@ -1196,8 +1198,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (BOOL)windowShouldClose:(id)sender
 {
-    playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
+    playlist_t * p_playlist = pl_Yield( p_vout );
     if( p_playlist == NULL )
     {
         return NO;