1 /*****************************************************************************
2 * fspanel.m: MacOS X full screen panel
3 *****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Jérôme Decoodt <djc at videolan dot org>
8 * Felix Paul Kühne <fkuehne at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #import "CoreInteraction.h"
30 #import "MainWindow.h"
34 @interface VLCFSPanel ()
38 /*****************************************************************************
40 *****************************************************************************/
41 @implementation VLCFSPanel
42 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
43 - (id)initWithContentRect:(NSRect)contentRect
44 styleMask:(NSUInteger)aStyle
45 backing:(NSBackingStoreType)bufferingType
48 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
50 [win setHasShadow: NO];
51 [win setBackgroundColor:[NSColor clearColor]];
52 if (NSAppKitVersionNumber >= 1115.2)
53 [win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
55 /* let the window sit on top of everything else and start out completely transparent */
56 [win setLevel:NSModalPanelWindowLevel];
59 hideAgainTimer = fadeTimer = nil;
60 [self setNonActive:nil];
66 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
67 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
68 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
70 [self mouseEntered:NULL];
72 [self mouseExited:NULL];
74 /* get a notification if VLC isn't the active app anymore */
75 [[NSNotificationCenter defaultCenter]
77 selector: @selector(setNonActive:)
78 name: NSApplicationDidResignActiveNotification
81 /* get a notification if VLC is the active app again */
82 [[NSNotificationCenter defaultCenter]
84 selector: @selector(setActive:)
85 name: NSApplicationDidBecomeActiveNotification
89 /* make sure that we don't become key, since we can't handle hotkeys */
90 - (BOOL)canBecomeKeyWindow
95 - (BOOL)mouseDownCanMoveWindow
102 [[NSNotificationCenter defaultCenter] removeObserver: self];
106 [hideAgainTimer invalidate];
107 [hideAgainTimer release];
109 [self setFadeTimer:nil];
115 /* centre the panel in the lower third of the screen */
116 NSPoint theCoordinate;
117 NSRect theScreensFrame;
118 NSRect theWindowsFrame;
121 /* user-defined screen */
122 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
126 /* invalid preferences or none specified, using main screen */
127 screen = [NSScreen mainScreen];
130 theScreensFrame = [screen frame];
132 theWindowsFrame = [self frame];
134 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
135 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
136 [self setFrameTopLeftPoint: theCoordinate];
141 [[self contentView] setPlay];
146 [[self contentView] setPause];
149 - (void)setStreamTitle:(NSString *)o_title
151 [[self contentView] setStreamTitle: o_title];
154 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
156 [[self contentView] setStreamPos:f_pos andTime: o_time];
159 - (void)setSeekable:(BOOL) b_seekable
161 [[self contentView] setSeekable: b_seekable];
164 - (void)setVolumeLevel: (float)f_volumeLevel
166 [[self contentView] setVolumeLevel: f_volumeLevel];
169 - (void)setNonActive:(id)noData
172 [self orderOut: self];
174 /* here's fadeOut, just without visibly fading */
176 [self setAlphaValue:0.0];
177 [self setFadeTimer:nil];
181 - (void)setActive:(id)noData
184 [[VLCMain sharedInstance] showFullscreenController];
187 /* This routine is called repeatedly to fade in the window */
188 - (void)focus:(NSTimer *)timer
190 /* we need to push ourselves to front if the vout window was closed since our last display */
191 if( b_voutWasUpdated )
193 [self orderFront: self];
194 b_voutWasUpdated = NO;
197 if( [self alphaValue] < 1.0 )
198 [self setAlphaValue:[self alphaValue]+0.1];
199 if( [self alphaValue] >= 1.0 )
202 [self setAlphaValue: 1.0];
203 [self setFadeTimer:nil];
207 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
212 /* This routine is called repeatedly to hide the window */
213 - (void)unfocus:(NSTimer *)timer
219 [self setFadeTimer: NULL];
223 if( [self alphaValue] > 0.0 )
224 [self setAlphaValue:[self alphaValue]-0.05];
225 if( [self alphaValue] <= 0.05 )
228 [self setAlphaValue:0.0];
229 [self setFadeTimer:nil];
234 [NSTimer scheduledTimerWithTimeInterval:0.1
236 selector:@selector(focus:)
243 - (void)mouseExited:(NSEvent *)theEvent
245 /* give up our focus, so the vout may show us again without letting the user clicking it */
246 vout_thread_t *p_vout = getVout();
249 if (var_GetBool( p_vout, "fullscreen" ))
250 [[[[VLCMainWindow sharedInstance] videoView] window] makeKeyWindow];
251 vlc_object_release( p_vout );
257 [NSCursor setHiddenUntilMouseMoves: YES];
262 /* in case that the user don't want us to appear, make sure we hide the mouse */
264 if( !config_GetInt( VLCIntf, "macosx-fspanel" ) )
266 float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.;
267 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
274 [self orderFront: nil];
276 if( [self alphaValue] < 1.0 || b_displayed != YES )
278 if (![self fadeTimer])
279 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
280 else if ([[[self fadeTimer] userInfo] shortValue]==0)
288 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
291 if( ( [self alphaValue] > 0.0 ) )
293 if (![self fadeTimer])
294 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
295 else if ([[[self fadeTimer] userInfo] shortValue]==1)
300 /* triggers a timer to autoHide us again after some seconds of no activity */
303 /* this will tell the timer to start over again or to start at all */
306 /* get us a valid timer */
307 if(! b_alreadyCounting )
309 i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
312 [hideAgainTimer invalidate];
313 [hideAgainTimer autorelease];
315 /* released in -autoHide and -dealloc */
316 hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
318 selector: @selector(keepVisible:)
320 repeats: YES] retain];
321 b_alreadyCounting = YES;
325 - (void)keepVisible:(NSTimer *)timer
327 /* if the user triggered an action, start over again */
331 /* count down until we hide ourselfes again and do so if necessary */
332 if( --i_timeToKeepVisibleInSec < 1 )
336 [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
337 b_alreadyCounting = NO;
341 /* A getter and setter for our main timer that handles window fading */
342 - (NSTimer *)fadeTimer
347 - (void)setFadeTimer:(NSTimer *)timer
350 [fadeTimer invalidate];
351 [fadeTimer autorelease];
355 - (void)mouseDown:(NSEvent *)theEvent
357 mouseClic = [theEvent locationInWindow];
360 - (void)mouseDragged:(NSEvent *)theEvent
362 NSPoint point = [NSEvent mouseLocation];
363 point.x -= mouseClic.x;
364 point.y -= mouseClic.y;
365 [self setFrameOrigin:point];
373 - (void)setVoutWasUpdated: (int)i_newdevice;
375 b_voutWasUpdated = YES;
376 if( i_newdevice != i_device )
378 i_device = i_newdevice;
384 /*****************************************************************************
386 *****************************************************************************/
387 @implementation VLCFSPanelView
389 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
390 s_rc.origin.x = _x; \
391 s_rc.origin.y = _y; \
392 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
393 [o_button setButtonType: NSMomentaryChangeButton]; \
394 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
395 [o_button setBordered: NO]; \
396 [o_button setFont:[NSFont systemFontOfSize:0]]; \
397 [o_button setImage:[NSImage imageNamed:imageOff]]; \
398 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
399 [o_button sizeToFit]; \
400 [o_button setTarget: self]; \
401 [o_button setAction: @selector(action:)]; \
402 [self addSubview:o_button];
404 #define addTextfield( class, o_text, align, font, color, size ) \
405 o_text = [[class alloc] initWithFrame: s_rc]; \
406 [o_text setDrawsBackground: NO]; \
407 [o_text setBordered: NO]; \
408 [o_text setEditable: NO]; \
409 [o_text setSelectable: NO]; \
410 [o_text setStringValue: _NS("(no item is being played)")]; \
411 [o_text setAlignment: align]; \
412 [o_text setTextColor: [NSColor color]]; \
413 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
414 [self addSubview:o_text];
416 - (id)initWithFrame:(NSRect)frameRect
418 id view = [super initWithFrame:frameRect];
419 fillColor = [[NSColor clearColor] retain];
420 NSRect s_rc = [self frame];
421 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
422 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
423 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
424 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
425 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
426 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, toggleFullscreen );
428 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
435 s_rc.size.width = 518;
436 s_rc.size.height = 9;
437 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
438 [o_fs_timeSlider setMinValue:0];
439 [o_fs_timeSlider setMaxValue:10000];
440 [o_fs_timeSlider setFloatValue: 0];
441 [o_fs_timeSlider setContinuous: YES];
442 [o_fs_timeSlider setTarget: self];
443 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
444 [self addSubview: o_fs_timeSlider];
449 s_rc.origin.y = 17.5;
450 s_rc.size.width = 95;
451 s_rc.size.height = 10;
452 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
453 [o_fs_volumeSlider setMinValue:0];
454 [o_fs_volumeSlider setMaxValue:32];
455 [o_fs_volumeSlider setFloatValue: 0];
456 [o_fs_volumeSlider setContinuous: YES];
457 [o_fs_volumeSlider setTarget: self];
458 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
459 [self addSubview: o_fs_volumeSlider];
461 /* time counter and stream title output fields */
465 s_rc.size.width = 352;
466 s_rc.size.height = 14;
467 addTextfield( NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
470 s_rc.size.width = 55;
471 addTextfield( VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
478 [o_fs_timeSlider release];
479 [o_fs_volumeSlider release];
485 [o_fullscreen release];
486 [o_streamTitle_txt release];
487 [o_streamPosition_txt release];
493 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
494 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
499 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
500 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
503 - (void)setStreamTitle:(NSString *)o_title
505 [o_streamTitle_txt setStringValue: o_title];
508 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
510 [o_streamPosition_txt setStringValue: o_time];
511 [o_fs_timeSlider setFloatValue: f_pos];
514 - (void)setSeekable:(BOOL)b_seekable
516 [o_bwd setEnabled: b_seekable];
517 [o_fwd setEnabled: b_seekable];
518 [o_fs_timeSlider setEnabled: b_seekable];
521 - (void)setVolumeLevel: (float)f_volumeLevel
523 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
526 - (IBAction)play:(id)sender
528 [[VLCCoreInteraction sharedInstance] play];
531 - (IBAction)forward:(id)sender
533 [[VLCCoreInteraction sharedInstance] forward];
536 - (IBAction)backward:(id)sender
538 [[VLCCoreInteraction sharedInstance] backward];
541 - (IBAction)prev:(id)sender
543 [[VLCCoreInteraction sharedInstance] previous];
546 - (IBAction)next:(id)sender
548 [[VLCCoreInteraction sharedInstance] next];
551 - (IBAction)toggleFullscreen:(id)sender
553 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
556 - (IBAction)fsTimeSliderUpdate:(id)sender
558 input_thread_t * p_input;
559 p_input = pl_CurrentInput( VLCIntf );
560 if( p_input != NULL )
564 pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
565 var_Set( p_input, "position", pos );
566 vlc_object_release( p_input );
568 [[VLCMain sharedInstance] updatePlaybackPosition];
571 - (IBAction)fsVolumeSliderUpdate:(id)sender
573 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
576 #define addImage(image, _x, _y, mode, _width) \
577 img = [NSImage imageNamed:image]; \
578 image_rect.size = [img size]; \
579 image_rect.origin.x = 0; \
580 image_rect.origin.y = 0; \
581 frame.origin.x = _x; \
582 frame.origin.y = _y; \
583 frame.size = [img size]; \
584 if( _width ) frame.size.width = _width; \
585 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
587 - (void)drawRect:(NSRect)rect
589 NSRect frame = [self frame];
592 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
593 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
594 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
595 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
596 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
601 /*****************************************************************************
603 *****************************************************************************/
604 @implementation VLCFSTimeSlider
605 - (void)drawKnobInRect:(NSRect)knobRect
608 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
609 image_rect.size = [img size];
610 image_rect.origin.x = 0;
611 image_rect.origin.y = 0;
612 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
613 knobRect.size.width = image_rect.size.width;
614 knobRect.size.height = image_rect.size.height;
615 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
618 - (void)drawRect:(NSRect)rect
620 /* Draw default to make sure the slider behaves correctly */
621 [[NSGraphicsContext currentContext] saveGraphicsState];
622 NSRectClip(NSZeroRect);
623 [super drawRect:rect];
624 [[NSGraphicsContext currentContext] restoreGraphicsState];
626 NSRect knobRect = [[self cell] knobRectFlipped:NO];
627 knobRect.origin.y+=7.5;
628 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
629 [self drawKnobInRect: knobRect];
634 /*****************************************************************************
636 *****************************************************************************/
637 @implementation VLCFSVolumeSlider
638 - (void)drawKnobInRect:(NSRect) knobRect
641 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
642 image_rect.size = [img size];
643 image_rect.origin.x = 0;
644 image_rect.origin.y = 0;
645 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
646 knobRect.size.width = image_rect.size.width;
647 knobRect.size.height = image_rect.size.height;
648 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
651 - (void)drawRect:(NSRect)rect
653 /* Draw default to make sure the slider behaves correctly */
654 [[NSGraphicsContext currentContext] saveGraphicsState];
655 NSRectClip(NSZeroRect);
656 [super drawRect:rect];
657 [[NSGraphicsContext currentContext] restoreGraphicsState];
659 NSRect knobRect = [[self cell] knobRectFlipped:NO];
660 knobRect.origin.y+=6;
661 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
662 [self drawKnobInRect: knobRect];