X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Ffspanel.m;h=ee8311e08c6e2134066b6ad714f5c4febf536810;hb=6ee1e193fd896ab9a4729fde14f009d9ce629815;hp=607b3649f98369f33f43d8fd56769c12f0ae8f5d;hpb=496b1f5fc878edde8e21bb749c76495ca5cfa4ab;p=vlc diff --git a/modules/gui/macosx/fspanel.m b/modules/gui/macosx/fspanel.m index 607b3649f9..ee8311e08c 100644 --- a/modules/gui/macosx/fspanel.m +++ b/modules/gui/macosx/fspanel.m @@ -1,7 +1,7 @@ /***************************************************************************** * fspanel.m: MacOS X full screen panel ***************************************************************************** - * Copyright (C) 2006 the VideoLAN team + * Copyright (C) 2006-2007 the VideoLAN team * $Id$ * * Authors: JŽr™me Decoodt @@ -28,9 +28,10 @@ #import "intf.h" #import "controls.h" #import "vout.h" +#import "misc.h" #import "fspanel.h" -#define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after an user's action */ +#define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after a user's action */ /***************************************************************************** * VLCFSPanel @@ -42,25 +43,43 @@ backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { - id win=[super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag]; + id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag]; [win setOpaque:NO]; [win setHasShadow: NO]; [win setBackgroundColor:[NSColor clearColor]]; + /* let the window sit on top of everything else and start out completely transparent */ - [win setLevel:NSFloatingWindowLevel]; - [win setAlphaValue:0.0]; + [win setLevel:NSModalPanelWindowLevel]; + i_device = 0; + [win center]; + [self setNonActive:nil]; + return win; } - (void)awakeFromNib { [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]]; - BOOL isInside=(NSPointInRect([NSEvent mouseLocation],[self frame])); + BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame])); [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside]; if (isInside) - [self mouseEntered:NULL]; + [self mouseEntered:NULL]; if (!isInside) - [self mouseExited:NULL]; + [self mouseExited:NULL]; + + /* get a notification if VLC isn't the active app anymore */ + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector(setNonActive:) + name: NSApplicationDidResignActiveNotification + object: NSApp]; + + /* get a notification if VLC is the active app again */ + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector(setActive:) + name: NSApplicationDidBecomeActiveNotification + object: NSApp]; } /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */ @@ -74,14 +93,53 @@ return YES; } +#if GC_ENABLED +- (void)finalize +{ + /* dealloc isn't called on 10.5 in case that GC is enabled, so we need to provide the functionality here */ + [[NSNotificationCenter defaultCenter] removeObserver: self]; + [self setFadeTimer:nil]; + + [super finalize]; +} +#endif + -(void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver: self]; + if( hideAgainTimer ) [hideAgainTimer release]; [self setFadeTimer:nil]; [super dealloc]; } +-(void)center +{ + /* centre the panel in the lower third of the screen */ + NSPoint theCoordinate; + NSRect theScreensFrame; + NSRect theWindowsFrame; + NSScreen *screen; + + /* user-defined screen */ + screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device]; + + if (!screen) + { + /* invalid preferences or none specified, using main screen */ + screen = [NSScreen mainScreen]; + } + + theScreensFrame = [screen frame]; + + theWindowsFrame = [self frame]; + + theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x; + theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y; + [self setFrameTopLeftPoint: theCoordinate]; +} + - (void)setPlay { [[self contentView] setPlay]; @@ -112,6 +170,27 @@ [[self contentView] setVolumeLevel: f_volumeLevel]; } +- (void)setNonActive:(id)noData +{ + b_nonActive = YES; + [self orderOut: self]; + + /* here's fadeOut, just without visibly fading */ + b_displayed = NO; + [self setAlphaValue:0.0]; + [self setFadeTimer:nil]; + b_fadeQueued = NO; +} + +- (void)setActive:(id)noData +{ + if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] ) + { + b_nonActive = NO; + [self fadeIn]; + } +} + /* This routine is called repeatedly to fade in the window */ - (void)focus:(NSTimer *)timer { @@ -144,14 +223,13 @@ { b_keptVisible = NO; b_fadeQueued = NO; - [[self fadeTimer] release]; [self setFadeTimer: NULL]; [self fadeIn]; return; } if( [self alphaValue] > 0.0 ) - [self setAlphaValue:[self alphaValue]-0.1]; - if( [self alphaValue] <= 0.1 ) + [self setAlphaValue:[self alphaValue]-0.05]; + if( [self alphaValue] <= 0.05 ) { b_displayed = NO; [self setAlphaValue:0.0]; @@ -178,7 +256,13 @@ - (void)fadeIn { - if( [self alphaValue] < 1.0 ) + /* in case that the user don't want us to appear, just return here */ + if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive ) + return; + + [self orderFront: nil]; + + if( [self alphaValue] < 1.0 || b_displayed != YES ) { if (![self fadeTimer]) [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]]; @@ -190,10 +274,13 @@ - (void)fadeOut { + if( NSPointInRect([NSEvent mouseLocation],[self frame])) + return; + if( ( [self alphaValue] > 0.0 ) ) { if (![self fadeTimer]) - [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]]; + [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]]; else if ([[[self fadeTimer] userInfo] shortValue]==1) b_fadeQueued=YES; } @@ -232,6 +319,7 @@ i_timeToKeepVisibleInSec -= 1; if( i_timeToKeepVisibleInSec < 1 ) { + [NSCursor setHiddenUntilMouseMoves: YES]; [self fadeOut]; [timer invalidate]; [timer release]; @@ -272,9 +360,14 @@ return b_displayed; } -- (void)setVoutWasUpdated +- (void)setVoutWasUpdated: (int)i_newdevice; { b_voutWasUpdated = YES; + if( i_newdevice != i_device ) + { + i_device = i_newdevice; + [self center]; + } } @end @@ -316,9 +409,9 @@ fillColor = [[NSColor clearColor] retain]; NSRect s_rc = [self frame]; addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev ); - addButton( o_slow, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, slower ); + addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward ); addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play ); - addButton( o_fast, @"fs_forward" , @"fs_forward_highlight" , 313, 14, faster ); + addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward ); addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next ); addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction ); /* @@ -376,9 +469,9 @@ [o_fs_volumeSlider release]; [o_prev release]; [o_next release]; - [o_slow release]; + [o_bwd release]; [o_play release]; - [o_fast release]; + [o_fwd release]; [o_fullscreen release]; [o_streamTitle_txt release]; [o_streamPosition_txt release]; @@ -387,20 +480,14 @@ - (void)setPlay { - NSImage *image; - image = [NSImage imageNamed:@"fs_play"]; - [o_play setImage:image]; - image = [NSImage imageNamed:@"fs_play_highlight"]; - [o_play setAlternateImage:image]; + [o_play setImage:[NSImage imageNamed:@"fs_play"]]; + [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]]; } - (void)setPause { - NSImage *image; - image = [NSImage imageNamed:@"fs_pause"]; - [o_play setImage:image]; - image = [NSImage imageNamed:@"fs_pause_highlight"]; - [o_play setAlternateImage:image]; + [o_play setImage: [NSImage imageNamed:@"fs_pause"]]; + [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]]; } - (void)setStreamTitle:(NSString *)o_title @@ -416,8 +503,8 @@ - (void)setSeekable:(BOOL)b_seekable { - [o_slow setEnabled: b_seekable]; - [o_fast setEnabled: b_seekable]; + [o_bwd setEnabled: b_seekable]; + [o_fwd setEnabled: b_seekable]; [o_fs_timeSlider setEnabled: b_seekable]; } @@ -431,14 +518,14 @@ [[[VLCMain sharedInstance] getControls] play: sender]; } -- (IBAction)faster:(id)sender +- (IBAction)forward:(id)sender { - [[[VLCMain sharedInstance] getControls] faster: sender]; + [[[VLCMain sharedInstance] getControls] forward: sender]; } -- (IBAction)slower:(id)sender +- (IBAction)backward:(id)sender { - [[[VLCMain sharedInstance] getControls] slower: sender]; + [[[VLCMain sharedInstance] getControls] backward: sender]; } - (IBAction)prev:(id)sender @@ -479,7 +566,7 @@ - (void)drawRect:(NSRect)rect { - NSRect frame = [self frame]; + NSRect frame = [self frame]; NSRect image_rect; NSImage *img; addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 ); @@ -555,4 +642,5 @@ [self drawKnobInRect: knobRect]; } -@end \ No newline at end of file +@end +