]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/MainWindow.m
macosx: allow the user to hide the sidebar (close #6088)
[vlc] / modules / gui / macosx / MainWindow.m
index a24bf57d2cb2bb392534045ab5bf26c36472c862..808018d8b96417c268dd85df960486027210a53d 100644 (file)
@@ -228,7 +228,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
         else
         {
             [o_effects_btn setImage: [NSImage imageNamed:@"effects-double-buttons_dark"]];
-            [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-double-buttons-pressed_dark"]];            
+            [o_effects_btn setAlternateImage: [NSImage imageNamed:@"effects-double-buttons-pressed_dark"]];
         }
         [o_fullscreen_btn setImage: [NSImage imageNamed:@"fullscreen-double-buttons_dark"]];
         [o_fullscreen_btn setAlternateImage: [NSImage imageNamed:@"fullscreen-double-buttons-pressed_dark"]];
@@ -463,6 +463,11 @@ static VLCMainWindow *_o_sharedInstance = nil;
         [o_sidebar_scrollview setBorderType: NSNoBorder];
     }
 
+    NSRect frame;
+    frame = [o_time_sld_fancygradient_view frame];
+    frame.size.width = 0;
+    [o_time_sld_fancygradient_view setFrame: frame];
+
     if (OSX_LION)
         [o_resize_view setImage: NULL];
 
@@ -495,7 +500,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (void)resetPreviousButton
 {
     if (([NSDate timeIntervalSinceReferenceDate] - last_bwd_event) >= 0.35) {
-        // seems like no further event occured, so let's switch the playback item
+        // seems like no further event occurred, so let's switch the playback item
         [[VLCCoreInteraction sharedInstance] previous];
         just_triggered_previous = NO;
     }
@@ -519,10 +524,10 @@ static VLCMainWindow *_o_sharedInstance = nil;
     }
     else
     {
-        if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
+        if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16 )
         {
-            // we just skipped 3 "continous" events, otherwise we are too fast
-            [[VLCCoreInteraction sharedInstance] backward];
+            // we just skipped 4 "continous" events, otherwise we are too fast
+            [[VLCCoreInteraction sharedInstance] backwardExtraShort];
             last_bwd_event = [NSDate timeIntervalSinceReferenceDate];
             [self performSelector:@selector(resetBackwardSkip)
                        withObject: NULL
@@ -534,7 +539,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (void)resetNextButton
 {
     if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) >= 0.35) {
-        // seems like no further event occured, so let's switch the playback item
+        // seems like no further event occurred, so let's switch the playback item
         [[VLCCoreInteraction sharedInstance] next];
         just_triggered_next = NO;
     }
@@ -558,10 +563,10 @@ static VLCMainWindow *_o_sharedInstance = nil;
     }
     else
     {
-        if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.12 )
+        if (([NSDate timeIntervalSinceReferenceDate] - last_fwd_event) > 0.16 )
         {
-            // we just skipped 3 "continous" events, otherwise we are too fast
-            [[VLCCoreInteraction sharedInstance] forward];
+            // we just skipped 4 "continous" events, otherwise we are too fast
+            [[VLCCoreInteraction sharedInstance] forwardExtraShort];
             last_fwd_event = [NSDate timeIntervalSinceReferenceDate];
             [self performSelector:@selector(resetForwardSkip)
                        withObject: NULL
@@ -585,7 +590,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (IBAction)togglePlaylist:(id)sender
 {
-    if ((([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) && !b_splitview_removed)
+    if ( ((([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) && !b_splitview_removed && ![[VLCMain sharedInstance] activeVideoPlayback]) || (b_nonembedded && [[VLCMain sharedInstance] activeVideoPlayback] && sender != nil) )
     {
         [self hideSplitView];
     }
@@ -593,7 +598,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     {
         if (b_splitview_removed)
         {
-            [self showSplitView];
+            if( !b_nonembedded ||( sender != nil && b_nonembedded))
+                [self showSplitView];
         }
 
         if (b_dropzone_active && ![[VLCMain sharedInstance] activeVideoPlayback])
@@ -677,7 +683,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
     bool b_value;
     playlist_t *p_playlist = pl_Get( VLCIntf );
     b_value = var_GetBool( p_playlist, "random" );
-       if(b_value) {
+
+    if(b_value) {
         [o_shuffle_btn setImage: o_shuffle_on_img];
         [o_shuffle_btn setAlternateImage: o_shuffle_on_pressed_img];
     }
@@ -745,10 +752,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
     else if (sender == o_volume_down_btn)
     {
         [[VLCCoreInteraction sharedInstance] mute];
-        [o_volume_sld setIntValue: 0];
-        BOOL b_mute = ![[VLCCoreInteraction sharedInstance] isMuted];
-        [o_volume_sld setEnabled: b_mute];
-        [o_volume_up_btn setEnabled: b_mute];
     }
     else
         [[VLCCoreInteraction sharedInstance] setVolume: AOUT_VOLUME_MAX];
@@ -778,16 +781,12 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
 {
-       SEL s_menuAction = [menuItem action];
-       if ((s_menuAction == @selector(performClose:)) || (s_menuAction == @selector(performMiniaturize:)) || (s_menuAction == @selector(performZoom:)))
-        return YES;
+    SEL s_menuAction = [menuItem action];
 
-       return [super validateMenuItem:menuItem];
-}
+    if ((s_menuAction == @selector(performClose:)) || (s_menuAction == @selector(performMiniaturize:)) || (s_menuAction == @selector(performZoom:)))
+            return YES;
 
-- (BOOL)isMainWindow
-{
-       return YES;
+    return [super validateMenuItem:menuItem];
 }
 
 - (void)setTitle:(NSString *)title
@@ -801,14 +800,21 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (void)performClose:(id)sender
 {
+    NSWindow *o_key_window = [NSApp keyWindow];
+
     if (b_dark_interface)
     {
-        [self orderOut: sender];
-        if ([[VLCMain sharedInstance] activeVideoPlayback] && !b_nonembedded)
+        [o_key_window orderOut: sender];
+        if ( [[VLCMain sharedInstance] activeVideoPlayback] && ( !b_nonembedded || o_key_window != self ))
             [[VLCCoreInteraction sharedInstance] stop];
     }
     else
-        [super performClose: sender];
+    {
+        if( b_nonembedded && o_key_window != self )
+            [o_nonembedded_window performClose: sender];
+        else
+            [super performClose: sender];
+    }
 }
 
 - (void)performMiniaturize:(id)sender
@@ -1091,13 +1097,19 @@ static VLCMainWindow *_o_sharedInstance = nil;
     playlist_t * p_playlist = pl_Get( VLCIntf );
 
     i_volume = aout_VolumeGet( p_playlist );
+    BOOL b_muted = [[VLCCoreInteraction sharedInstance] isMuted];
 
-    if( i_volume != i_lastShownVolume )
+    if( !b_muted )
     {
         i_lastShownVolume = i_volume;
         [o_volume_sld setIntValue: i_volume];
         [o_fspanel setVolumeLevel: i_volume];
     }
+    else
+        [o_volume_sld setIntValue: 0];
+
+    [o_volume_sld setEnabled: !b_muted];
+    [o_volume_up_btn setEnabled: !b_muted];
 }
 
 - (void)updateName
@@ -1240,13 +1252,20 @@ static VLCMainWindow *_o_sharedInstance = nil;
         NSRect oldFrame = [o_time_sld_fancygradient_view frame];
         if (f_value != oldFrame.size.width)
         {
-            [o_time_sld_fancygradient_view setHidden: NO];
+            if ([o_time_sld_fancygradient_view isHidden])
+                [o_time_sld_fancygradient_view setHidden: NO];
             [o_time_sld_fancygradient_view setFrame: NSMakeRect( oldFrame.origin.x, oldFrame.origin.y, f_value, oldFrame.size.height )];
-            [o_time_sld_fancygradient_view setNeedsDisplay:YES];
         }
     }
     else
     {
+        NSRect frame;
+        frame = [o_time_sld_fancygradient_view frame];
+        if (frame.size.width > 0)
+        {
+            frame.size.width = 0;
+            [o_time_sld_fancygradient_view setFrame: frame];
+        }
         [o_time_sld_fancygradient_view setHidden: YES];
     }
     [o_pool release];
@@ -1254,8 +1273,12 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 #pragma mark -
 #pragma mark Video Output handling
-
 - (id)videoView
+{
+    return o_video_view;
+}
+
+- (id)setupVideoView
 {
     vout_thread_t *p_vout = getVout();
     if (config_GetInt( VLCIntf, "embedded-video" ))
@@ -1322,13 +1345,16 @@ static VLCMainWindow *_o_sharedInstance = nil;
     else
         [self makeFirstResponder: nil];
 
-    if (!b_videoPlayback && b_fullscreen && !b_nativeFullscreenMode)
-        [[VLCCoreInteraction sharedInstance] toggleFullscreen];
+    if (!b_videoPlayback && b_fullscreen)
+    {
+        if (!b_nativeFullscreenMode || !OSX_LION)
+            [[VLCCoreInteraction sharedInstance] toggleFullscreen];
+    }
 }
 
 - (void)resizeWindow
 {
-    if ( b_fullscreen || (OSX_LION && [NSApp presentationOptions] == NSApplicationPresentationFullScreen && b_nativeFullscreenMode) )
+    if ( b_fullscreen || (OSX_LION && [NSApp presentationOptions] & NSApplicationPresentationFullScreen && b_nativeFullscreenMode) )
         return;
 
     NSPoint topleftbase = NSMakePoint(0, [self frame].size.height);
@@ -1524,7 +1550,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
             [o_nonembedded_window orderOut: self];
         else
             [super orderOut: self];
-        
+
         [self unlockFullscreenAnimation];
         return;
     }
@@ -1927,11 +1953,11 @@ static VLCMainWindow *_o_sharedInstance = nil;
         NSRect winrect;
         CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
         winrect = [self frame];
-        
+
         [o_titlebar_view setFrame: NSMakeRect( 0, winrect.size.height - f_titleBarHeight,
                                               winrect.size.width, f_titleBarHeight )];
         [[self contentView] addSubview: o_titlebar_view];
-        
+
         winrect.size.height = winrect.size.height + f_titleBarHeight;
         [self setFrame: winrect display:NO animate:NO];
         winrect = [o_split_view frame];
@@ -1946,14 +1972,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 #pragma mark -
 #pragma mark split view delegate
-- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
-{
-    if (dividerIndex == 0)
-        return 200.0;
-    else
-        return proposedMin;
-}
-
 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
 {
     if (dividerIndex == 0)
@@ -1967,41 +1985,37 @@ static VLCMainWindow *_o_sharedInstance = nil;
 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
 - (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item
 {
-       //Works the same way as the NSOutlineView data source: `nil` means a parent item
-       if(item==nil) {
-               return [o_sidebaritems count];
-       }
-       else {
-               return [[item children] count];
-       }
+    //Works the same way as the NSOutlineView data source: `nil` means a parent item
+    if(item==nil)
+        return [o_sidebaritems count];
+    else
+        return [[item children] count];
 }
 
 
 - (id)sourceList:(PXSourceList*)aSourceList child:(NSUInteger)index ofItem:(id)item
 {
     //Works the same way as the NSOutlineView data source: `nil` means a parent item
-       if(item==nil) {
-               return [o_sidebaritems objectAtIndex:index];
-       }
-       else {
-               return [[item children] objectAtIndex:index];
-       }
+    if(item==nil)
+        return [o_sidebaritems objectAtIndex:index];
+    else
+        return [[item children] objectAtIndex:index];
 }
 
 
 - (id)sourceList:(PXSourceList*)aSourceList objectValueForItem:(id)item
 {
-       return [item title];
+    return [item title];
 }
 
 - (void)sourceList:(PXSourceList*)aSourceList setObjectValue:(id)object forItem:(id)item
 {
-       [item setTitle:object];
+    [item setTitle:object];
 }
 
 - (BOOL)sourceList:(PXSourceList*)aSourceList isItemExpandable:(id)item
 {
-       return [item hasChildren];
+    return [item hasChildren];
 }
 
 
@@ -2010,7 +2024,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
     if ([[item identifier] isEqualToString: @"playlist"] || [[item identifier] isEqualToString: @"medialibrary"])
         return YES;
 
-       return [item hasBadge];
+    return [item hasBadge];
 }
 
 
@@ -2035,25 +2049,27 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
         return i_playlist_size;
     }
-       return [item badgeValue];
+
+    return [item badgeValue];
 }
 
 
 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasIcon:(id)item
 {
-       return [item hasIcon];
+    return [item hasIcon];
 }
 
 
 - (NSImage*)sourceList:(PXSourceList*)aSourceList iconForItem:(id)item
 {
-       return [item icon];
+    return [item icon];
 }
 
 - (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
 {
-       if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
-               if (item != nil)
+    if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask))
+    {
+        if (item != nil)
         {
             NSMenu * m;
             if ([item sdtype] > 0)
@@ -2069,8 +2085,9 @@ static VLCMainWindow *_o_sharedInstance = nil;
             }
             return [m autorelease];
         }
-       }
-       return nil;
+    }
+
+    return nil;
 }
 
 - (IBAction)sdmenuhandler:(id)sender
@@ -2102,10 +2119,12 @@ static VLCMainWindow *_o_sharedInstance = nil;
 - (void)sourceListSelectionDidChange:(NSNotification *)notification
 {
     playlist_t * p_playlist = pl_Get( VLCIntf );
-       NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
+
+    NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
     id item = [o_sidebar_view itemAtRow:[selectedIndexes firstIndex]];
 
-       //Set the label text to represent the new selection
+
+    //Set the label text to represent the new selection
     if ([item sdtype] > -1 && [[item identifier] length] > 0)
     {
         BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded( p_playlist, [[item identifier] UTF8String] );