1 /*****************************************************************************
2 * fspanel.m: MacOS X full screen panel
3 *****************************************************************************
4 * Copyright (C) 2006-2012 VLC authors and VideoLAN
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"
33 #import "CompatibilityFixes.h"
34 #import <vlc_aout_intf.h>
36 @interface VLCFSPanel ()
40 /*****************************************************************************
42 *****************************************************************************/
43 @implementation VLCFSPanel
44 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
45 - (id)initWithContentRect:(NSRect)contentRect
46 styleMask:(NSUInteger)aStyle
47 backing:(NSBackingStoreType)bufferingType
50 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
52 [win setHasShadow: NO];
53 [win setBackgroundColor:[NSColor clearColor]];
55 [win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
57 /* let the window sit on top of everything else and start out completely transparent */
58 [win setLevel:NSModalPanelWindowLevel];
60 hideAgainTimer = fadeTimer = nil;
61 [self setNonActive:nil];
67 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
68 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
69 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
71 [self mouseEntered:NULL];
73 [self mouseExited:NULL];
77 /* get a notification if VLC isn't the active app anymore */
78 [[NSNotificationCenter defaultCenter]
80 selector: @selector(setNonActive:)
81 name: NSApplicationDidResignActiveNotification
84 /* get a notification if VLC is the active app again */
85 [[NSNotificationCenter defaultCenter]
87 selector: @selector(setActive:)
88 name: NSApplicationDidBecomeActiveNotification
92 /* make sure that we don't become key, since we can't handle hotkeys */
93 - (BOOL)canBecomeKeyWindow
98 - (BOOL)mouseDownCanMoveWindow
105 [[NSNotificationCenter defaultCenter] removeObserver: self];
109 [hideAgainTimer invalidate];
110 [hideAgainTimer release];
112 [self setFadeTimer:nil];
118 /* centre the panel in the lower third of the screen */
119 NSPoint theCoordinate;
120 NSRect theScreensFrame;
121 NSRect theWindowsFrame;
124 /* user-defined screen */
125 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
129 /* invalid preferences or none specified, using main screen */
130 screen = [NSScreen mainScreen];
133 theScreensFrame = [screen frame];
134 theWindowsFrame = [self frame];
136 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
137 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
138 [self setFrameTopLeftPoint: theCoordinate];
143 [[self contentView] setPlay];
148 [[self contentView] setPause];
151 - (void)setStreamTitle:(NSString *)o_title
153 [[self contentView] setStreamTitle: o_title];
156 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
158 [[self contentView] setStreamPos:f_pos andTime: o_time];
161 - (void)setSeekable:(BOOL) b_seekable
163 [[self contentView] setSeekable: b_seekable];
166 - (void)setVolumeLevel: (int)i_volumeLevel
168 [[self contentView] setVolumeLevel: i_volumeLevel];
171 - (void)setNonActive:(id)noData
174 [self orderOut: self];
176 /* here's fadeOut, just without visibly fading */
178 [self setAlphaValue:0.0];
179 [self setFadeTimer:nil];
183 - (void)setActive:(id)noData
186 [[VLCMain sharedInstance] showFullscreenController];
189 /* This routine is called repeatedly to fade in the window */
190 - (void)focus:(NSTimer *)timer
192 /* we need to push ourselves to front if the vout window was closed since our last display */
193 if( b_voutWasUpdated )
195 [self orderFront: self];
196 b_voutWasUpdated = NO;
199 if( [self alphaValue] < 1.0 )
200 [self setAlphaValue:[self alphaValue]+0.1];
201 if( [self alphaValue] >= 1.0 )
204 [self setAlphaValue: 1.0];
205 [self setFadeTimer:nil];
209 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
214 /* This routine is called repeatedly to hide the window */
215 - (void)unfocus:(NSTimer *)timer
221 [self setFadeTimer: NULL];
225 if( [self alphaValue] > 0.0 )
226 [self setAlphaValue:[self alphaValue]-0.05];
227 if( [self alphaValue] <= 0.05 )
230 [self setAlphaValue:0.0];
231 [self setFadeTimer:nil];
236 [NSTimer scheduledTimerWithTimeInterval:0.1
238 selector:@selector(focus:)
245 - (void)mouseExited:(NSEvent *)theEvent
247 /* give up our focus, so the vout may show us again without letting the user clicking it */
248 vout_thread_t *p_vout = getVout();
251 if (var_GetBool( p_vout, "fullscreen" ))
252 [[[[VLCMainWindow sharedInstance] videoView] window] makeKeyWindow];
253 vlc_object_release( p_vout );
259 [NSCursor setHiddenUntilMouseMoves: YES];
264 /* in case that the user don't want us to appear, make sure we hide the mouse */
266 if( !config_GetInt( VLCIntf, "macosx-fspanel" ) )
268 float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.;
269 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
276 [self orderFront: nil];
278 if( [self alphaValue] < 1.0 || b_displayed != YES )
280 if (![self fadeTimer])
281 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
282 else if ([[[self fadeTimer] userInfo] shortValue]==0)
290 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
293 if( ( [self alphaValue] > 0.0 ) )
295 if (![self fadeTimer])
296 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
297 else if ([[[self fadeTimer] userInfo] shortValue]==1)
302 /* triggers a timer to autoHide us again after some seconds of no activity */
305 /* this will tell the timer to start over again or to start at all */
308 /* get us a valid timer */
309 if(! b_alreadyCounting )
311 i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
314 [hideAgainTimer invalidate];
315 [hideAgainTimer autorelease];
317 /* released in -autoHide and -dealloc */
318 hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
320 selector: @selector(keepVisible:)
322 repeats: YES] retain];
323 b_alreadyCounting = YES;
327 - (void)keepVisible:(NSTimer *)timer
329 /* if the user triggered an action, start over again */
333 /* count down until we hide ourselfes again and do so if necessary */
334 if( --i_timeToKeepVisibleInSec < 1 )
338 [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
339 b_alreadyCounting = NO;
343 /* A getter and setter for our main timer that handles window fading */
344 - (NSTimer *)fadeTimer
349 - (void)setFadeTimer:(NSTimer *)timer
352 [fadeTimer invalidate];
353 [fadeTimer autorelease];
357 - (void)mouseDown:(NSEvent *)theEvent
359 mouseClic = [theEvent locationInWindow];
362 - (void)mouseDragged:(NSEvent *)theEvent
364 NSPoint point = [NSEvent mouseLocation];
365 point.x -= mouseClic.x;
366 point.y -= mouseClic.y;
367 [self setFrameOrigin:point];
375 - (void)setVoutWasUpdated: (int)i_newdevice;
377 b_voutWasUpdated = YES;
378 if( i_newdevice != i_device )
380 i_device = i_newdevice;
386 /*****************************************************************************
388 *****************************************************************************/
389 @implementation VLCFSPanelView
391 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
392 s_rc.origin.x = _x; \
393 s_rc.origin.y = _y; \
394 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
395 [o_button setButtonType: NSMomentaryChangeButton]; \
396 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
397 [o_button setBordered: NO]; \
398 [o_button setFont:[NSFont systemFontOfSize:0]]; \
399 [o_button setImage:[NSImage imageNamed:imageOff]]; \
400 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
401 [o_button sizeToFit]; \
402 [o_button setTarget: self]; \
403 [o_button setAction: @selector(action:)]; \
404 [self addSubview:o_button];
406 #define addTextfield( class, o_text, align, font, color ) \
407 o_text = [[class alloc] initWithFrame: s_rc]; \
408 [o_text setDrawsBackground: NO]; \
409 [o_text setBordered: NO]; \
410 [o_text setEditable: NO]; \
411 [o_text setSelectable: NO]; \
412 [o_text setStringValue: _NS("(no item is being played)")]; \
413 [o_text setAlignment: align]; \
414 [o_text setTextColor: [NSColor color]]; \
415 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize]]]; \
416 [self addSubview:o_text];
418 - (id)initWithFrame:(NSRect)frameRect
420 id view = [super initWithFrame:frameRect];
421 fillColor = [[NSColor clearColor] retain];
422 NSRect s_rc = [self frame];
423 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
424 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
425 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
426 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
427 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
428 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, toggleFullscreen );
430 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
437 s_rc.size.width = 518;
438 s_rc.size.height = 9;
439 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
440 [o_fs_timeSlider setMinValue:0];
441 [o_fs_timeSlider setMaxValue:10000];
442 [o_fs_timeSlider setFloatValue: 0];
443 [o_fs_timeSlider setContinuous: YES];
444 [o_fs_timeSlider setTarget: self];
445 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
446 [self addSubview: o_fs_timeSlider];
452 s_rc.size.width = 95;
453 s_rc.size.height = 10;
454 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
455 [o_fs_volumeSlider setMinValue:0];
456 [o_fs_volumeSlider setMaxValue:AOUT_VOLUME_MAX];
457 [o_fs_volumeSlider setIntValue:AOUT_VOLUME_DEFAULT];
458 [o_fs_volumeSlider setContinuous: YES];
459 [o_fs_volumeSlider setTarget: self];
460 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
461 [self addSubview: o_fs_volumeSlider];
463 /* time counter and stream title output fields */
467 s_rc.size.width = 352;
468 s_rc.size.height = 14;
469 addTextfield( NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor );
472 s_rc.size.width = 65;
473 addTextfield( VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor );
475 o_background_img = [[NSImage imageNamed:@"fs_background"] retain];
476 o_vol_sld_img = [[NSImage imageNamed:@"fs_volume_slider_bar"] retain];
477 o_vol_mute_img = [[NSImage imageNamed:@"fs_volume_mute"] retain];
478 o_vol_max_img = [[NSImage imageNamed:@"fs_volume_max"] retain];
479 o_time_sld_img = [[NSImage imageNamed:@"fs_time_slider"] retain];
486 [o_background_img release];
487 [o_vol_sld_img release];
488 [o_vol_mute_img release];
489 [o_vol_max_img release];
490 [o_time_sld_img release];
491 [o_fs_timeSlider release];
492 [o_fs_volumeSlider release];
498 [o_fullscreen release];
499 [o_streamTitle_txt release];
500 [o_streamPosition_txt release];
506 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
507 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
512 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
513 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
516 - (void)setStreamTitle:(NSString *)o_title
518 [o_streamTitle_txt setStringValue: o_title];
521 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
523 [o_streamPosition_txt setStringValue: o_time];
524 [o_fs_timeSlider setFloatValue: f_pos];
527 - (void)setSeekable:(BOOL)b_seekable
529 [o_bwd setEnabled: b_seekable];
530 [o_fwd setEnabled: b_seekable];
531 [o_fs_timeSlider setEnabled: b_seekable];
534 - (void)setVolumeLevel: (int)i_volumeLevel
536 [o_fs_volumeSlider setIntValue: i_volumeLevel];
539 - (IBAction)play:(id)sender
541 [[VLCCoreInteraction sharedInstance] play];
544 - (IBAction)forward:(id)sender
546 [[VLCCoreInteraction sharedInstance] forward];
549 - (IBAction)backward:(id)sender
551 [[VLCCoreInteraction sharedInstance] backward];
554 - (IBAction)prev:(id)sender
556 [[VLCCoreInteraction sharedInstance] previous];
559 - (IBAction)next:(id)sender
561 [[VLCCoreInteraction sharedInstance] next];
564 - (IBAction)toggleFullscreen:(id)sender
566 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
569 - (IBAction)fsTimeSliderUpdate:(id)sender
571 input_thread_t * p_input;
572 p_input = pl_CurrentInput( VLCIntf );
573 if( p_input != NULL )
577 pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
578 var_Set( p_input, "position", pos );
579 vlc_object_release( p_input );
581 [[VLCMain sharedInstance] updatePlaybackPosition];
584 - (IBAction)fsVolumeSliderUpdate:(id)sender
586 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
589 #define addImage(image, _x, _y, mode) \
590 image_size = [image size]; \
591 image_rect.size = image_size; \
592 image_rect.origin.x = 0; \
593 image_rect.origin.y = 0; \
594 frame.origin.x = _x; \
595 frame.origin.y = _y; \
596 frame.size = image_size; \
597 [image drawInRect:frame fromRect:image_rect operation:mode fraction:1];
599 - (void)drawRect:(NSRect)rect
601 NSRect frame = [self frame];
605 addImage( o_background_img, 0, 0, NSCompositeCopy );
606 addImage( o_vol_sld_img, 26, 23, NSCompositeSourceOver );
607 addImage( o_vol_mute_img, 16, 18, NSCompositeSourceOver );
608 addImage( o_vol_max_img, 124, 18, NSCompositeSourceOver );
609 addImage( o_time_sld_img, 15, 53, NSCompositeSourceOver );
614 /*****************************************************************************
616 *****************************************************************************/
617 @implementation VLCFSTimeSlider
618 - (void)drawKnobInRect:(NSRect)knobRect
621 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
622 image_rect.size = [img size];
623 image_rect.origin.x = 0;
624 image_rect.origin.y = 0;
625 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
626 knobRect.size.width = image_rect.size.width;
627 knobRect.size.height = image_rect.size.height;
628 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
631 - (void)drawRect:(NSRect)rect
633 /* Draw default to make sure the slider behaves correctly */
634 [[NSGraphicsContext currentContext] saveGraphicsState];
635 NSRectClip(NSZeroRect);
636 [super drawRect:rect];
637 [[NSGraphicsContext currentContext] restoreGraphicsState];
639 NSRect knobRect = [[self cell] knobRectFlipped:NO];
640 knobRect.origin.y+=7.5;
641 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
642 [self drawKnobInRect: knobRect];
647 /*****************************************************************************
649 *****************************************************************************/
650 @implementation VLCFSVolumeSlider
651 - (void)drawKnobInRect:(NSRect) knobRect
654 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
655 image_rect.size = [img size];
656 image_rect.origin.x = 0;
657 image_rect.origin.y = 0;
658 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
659 knobRect.size.width = image_rect.size.width;
660 knobRect.size.height = image_rect.size.height;
661 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
664 - (void)drawRect:(NSRect)rect
666 /* Draw default to make sure the slider behaves correctly */
667 [[NSGraphicsContext currentContext] saveGraphicsState];
668 NSRectClip(NSZeroRect);
669 [super drawRect:rect];
670 [[NSGraphicsContext currentContext] restoreGraphicsState];
672 NSRect knobRect = [[self cell] knobRectFlipped:NO];
673 knobRect.origin.y+=6;
674 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
675 [self drawKnobInRect: knobRect];