1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2008 the VideoLAN team
7 * Authors: Colin Delacroix <colin@zoy.org>
8 * Florian G. Pflug <fgp@phlo.org>
9 * Jon Lech Johansen <jon-vl@nanocrew.net>
10 * Derk-Jan Hartman <hartman at videolan dot org>
11 * Eric Petit <titer@m0k.org>
12 * Benjamin Pracht <bigben at videolan dot org>
13 * Felix Paul Kühne <fkuehne at videolan dot org>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
28 *****************************************************************************/
30 /*****************************************************************************
32 *****************************************************************************/
33 #include <errno.h> /* ENOMEM */
34 #include <stdlib.h> /* free() */
37 /* BeginFullScreen, EndFullScreen */
38 #include <QuickTime/QuickTime.h>
46 #import "embeddedwindow.h"
48 /*****************************************************************************
49 * DeviceCallback: Callback triggered when the video-device variable is changed
50 *****************************************************************************/
51 int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
52 vlc_value_t old_val, vlc_value_t new_val, void *param )
55 vout_thread_t *p_vout = (vout_thread_t *)p_this;
57 msg_Dbg( p_vout, "set %d", new_val.i_int );
58 var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
59 var_Set( p_vout->p_libvlc, "video-device", new_val );
62 var_Set( p_vout, "intf-change", val );
67 /*****************************************************************************
68 * VLCEmbeddedList implementation
69 *****************************************************************************/
70 @implementation VLCEmbeddedList
75 o_embedded_array = [NSMutableArray array];
83 for( i = 0; i < [o_embedded_array count]; i++ )
85 id o_vout_view = [o_embedded_array objectAtIndex: i];
86 if( ![o_vout_view isUsed] )
88 [o_vout_view setUsed: YES];
95 - (void)releaseEmbeddedVout: (id)o_vout_view
97 if( [o_embedded_array containsObject: o_vout_view] )
99 [o_vout_view setUsed: NO];
103 msg_Warn( VLCIntf, "cannot find Video Output");
107 - (void)addEmbeddedVout: (id)o_vout_view
109 if( ![o_embedded_array containsObject: o_vout_view] )
111 [o_embedded_array addObject: o_vout_view];
115 - (BOOL)windowContainsEmbedded: (id)o_window
117 /* if( ![[o_window className] isEqualToString: @"VLCVoutWindow"] )
119 NSLog( @"We were not given a VLCVoutWindow" );
121 return ([self getViewForWindow: o_window] == nil ? NO : YES );
124 - (id)getViewForWindow: (id)o_window
126 id o_enumerator = [o_embedded_array objectEnumerator];
127 id o_current_embedded;
129 while( (o_current_embedded = [o_enumerator nextObject]) )
131 if( [o_current_embedded getWindow] == o_window )
133 return o_current_embedded;
141 /*****************************************************************************
142 * VLCVoutView implementation
143 *****************************************************************************/
144 @implementation VLCVoutView
146 - (id)initWithFrame: (NSRect)frameRect
148 [super initWithFrame: frameRect];
151 s_frame = &frameRect;
158 - (BOOL)setVout: (vout_thread_t *) vout
159 subView: (NSView *) view
160 frame: (NSRect *) frame
163 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
164 NSArray *o_screens = [NSScreen screens];
170 if( [o_screens count] <= 0 )
172 msg_Err( p_vout, "no OSX screens available" );
176 p_real_vout = [VLCVoutView getRealVout: p_vout];
178 /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */
179 if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 )
181 i_device = var_GetInteger( p_vout, "macosx-vdev" );
185 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
188 /* Setup the menuitem for the multiple displays. */
189 if( var_Type( p_real_vout, "video-device" ) == 0 )
192 vlc_value_t val2, text;
195 var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
197 text.psz_string = _("Fullscreen Video Device");
198 var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
200 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
203 text.psz_string = _("Default");
204 var_Change( p_real_vout, "video-device",
205 VLC_VAR_ADDCHOICE, &val2, &text );
206 var_Set( p_real_vout, "video-device", val2 );
208 while( (o_screen = [o_enumerator nextObject]) != NULL )
211 NSRect s_rect = [o_screen frame];
213 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
214 "%s %d (%dx%d)", _("Screen"), i,
215 (int)s_rect.size.width, (int)s_rect.size.height );
217 text.psz_string = psz_temp;
218 val2.i_int = (int)[o_screen displayID];
219 var_Change( p_real_vout, "video-device",
220 VLC_VAR_ADDCHOICE, &val2, &text );
221 if( (int)[o_screen displayID] == i_device )
223 var_Set( p_real_vout, "video-device", val2 );
228 var_AddCallback( p_real_vout, "video-device", DeviceCallback,
232 var_Set( p_real_vout, "intf-change", val2 );
235 /* Add the view. It's automatically resized to fit the window */
236 [self addSubview: o_view];
237 [self setAutoresizesSubviews: YES];
243 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize
245 [super resizeSubviewsWithOldSize: oldBoundsSize];
246 [o_view setFrameSize: [self frame].size];
249 - (void)drawRect:(NSRect)rect
251 /* When there is no subview we draw a black background */
253 [[NSColor blackColor] set];
260 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut];
262 /* Make sure we don't see a white flash */
263 [[self window] disableScreenUpdatesUntilFlush];
264 [o_view removeFromSuperview];
274 NSString * o_title = nil;
275 NSMutableString * o_mrl = nil;
276 input_thread_t * p_input;
283 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
285 if( p_input == NULL )
290 char *psz_nowPlaying = input_item_GetNowPlaying ( input_GetItem( p_input ) );
291 char *psz_name = input_item_GetName( input_GetItem( p_input ) );
292 char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
293 if( psz_nowPlaying != NULL )
294 o_title = [NSString stringWithUTF8String: psz_nowPlaying];
295 else if( psz_name != NULL )
296 o_title = [NSString stringWithUTF8String: psz_name];
298 if( psz_uri != NULL )
299 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
301 FREENULL( psz_nowPlaying );
302 FREENULL( psz_name );
310 /* FIXME once psz_access is exported, we could check if we are
311 * reading from a file in a smarter way. */
313 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
314 if( prefix_range.location != NSNotFound )
315 [o_mrl deleteCharactersInRange: prefix_range];
317 if( [o_mrl characterAtIndex:0] == '/' )
319 /* it's a local file */
320 [o_window setRepresentedFilename: o_mrl];
324 /* it's from the network or somewhere else,
325 * we clear the previous path */
326 [o_window setRepresentedFilename: @""];
328 [o_window setTitle: o_title];
332 [o_window setTitle: [NSString stringWithUTF8String: VOUT_TITLE]];
334 vlc_object_release( p_input );
338 - (void)setOnTop:(BOOL)b_on_top
342 [o_window setLevel: NSStatusWindowLevel];
346 [o_window setLevel: NSNormalWindowLevel];
350 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
353 int i_corrected_height, i_corrected_width;
355 NSPoint topleftscreen;
357 if ( !p_vout->b_fullscreen )
362 topleftbase.y = [o_window frame].size.height;
363 topleftscreen = [o_window convertBaseToScreen: topleftbase];
365 if( p_vout->render.i_height * p_vout->render.i_aspect >
366 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
368 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
370 newsize.width = (int) ( i_corrected_width * factor );
371 newsize.height = (int) ( p_vout->render.i_height * factor );
375 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
376 p_vout->render.i_aspect;
377 newsize.width = (int) ( p_vout->render.i_width * factor );
378 newsize.height = (int) ( i_corrected_height * factor );
381 /* In fullscreen mode we need to use a view that is different from
382 * ourselves, with the VLCEmbeddedWindow */
383 if([o_window isKindOfClass:[VLCEmbeddedWindow class]])
384 mainView = [o_window mainView];
388 /* Calculate the window's new size */
389 new_frame.size.width = [o_window frame].size.width -
390 [mainView frame].size.width + newsize.width;
391 new_frame.size.height = [o_window frame].size.height -
392 [mainView frame].size.height + newsize.height;
394 new_frame.origin.x = topleftscreen.x;
395 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
397 [o_window setFrame: new_frame display: animate animate: animate];
399 p_vout->i_changes |= VOUT_SIZE_CHANGE;
403 - (void)toggleFloatOnTop
407 if( !p_real_vout ) return;
408 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
416 var_Set( p_real_vout, "video-on-top", val );
419 - (void)toggleFullscreen
422 if( !p_real_vout ) return;
423 var_Get( p_real_vout, "fullscreen", &val );
424 val.b_bool = !val.b_bool;
425 var_Set( p_real_vout, "fullscreen", val );
431 if( !p_real_vout ) return NO;
432 var_Get( p_real_vout, "fullscreen", &val );
433 return( val.b_bool );
438 vout_Control( p_real_vout, VOUT_SNAPSHOT );
443 /* Disable Screensaver, when we're playing something, but allow it on pause */
444 if( !VLCIntf || !VLCIntf->p_sys || !VLCIntf->p_sys->i_play_status )
447 if( VLCIntf->p_sys->i_play_status == PLAYING_S )
448 UpdateSystemActivity( UsrActivity );
456 - (void)scrollWheel:(NSEvent *)theEvent
458 VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
459 [o_controls scrollWheel: theEvent];
462 - (void)keyDown:(NSEvent *)o_event
466 unsigned int i_pressed_modifiers = 0;
469 i_pressed_modifiers = [o_event modifierFlags];
471 if( i_pressed_modifiers & NSShiftKeyMask )
472 val.i_int |= KEY_MODIFIER_SHIFT;
473 if( i_pressed_modifiers & NSControlKeyMask )
474 val.i_int |= KEY_MODIFIER_CTRL;
475 if( i_pressed_modifiers & NSAlternateKeyMask )
476 val.i_int |= KEY_MODIFIER_ALT;
477 if( i_pressed_modifiers & NSCommandKeyMask )
478 val.i_int |= KEY_MODIFIER_COMMAND;
480 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
484 /* Escape should always get you out of fullscreen */
485 if( key == (unichar) 0x1b )
487 if( p_real_vout && [self isFullscreen] )
489 [self toggleFullscreen];
492 else if ( key == ' ' )
495 val.i_int = config_GetInt( p_vout, "key-play-pause" );
496 var_Set( p_vout->p_libvlc, "key-pressed", val );
500 val.i_int |= CocoaKeyToVLC( key );
501 var_Set( p_vout->p_libvlc, "key-pressed", val );
506 [super keyDown: o_event];
510 - (void)mouseDown:(NSEvent *)o_event
516 if( ( [o_event type] == NSLeftMouseDown ) &&
517 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
519 if( [o_event clickCount] <= 1 )
521 /* single clicking */
522 var_Get( p_vout, "mouse-button-down", &val );
524 var_Set( p_vout, "mouse-button-down", val );
528 /* multiple clicking */
529 [self toggleFullscreen];
532 else if( ( [o_event type] == NSRightMouseDown ) ||
533 ( ( [o_event type] == NSLeftMouseDown ) &&
534 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
536 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
537 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
541 [super mouseDown: o_event];
544 - (void)otherMouseDown:(NSEvent *)o_event
548 if( p_vout && [o_event type] == NSOtherMouseDown )
550 var_Get( p_vout, "mouse-button-down", &val );
552 var_Set( p_vout, "mouse-button-down", val );
555 [super mouseDown: o_event];
558 - (void)rightMouseDown:(NSEvent *)o_event
560 if( p_vout && [o_event type] == NSRightMouseDown )
562 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
563 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
566 [super mouseDown: o_event];
569 - (void)mouseUp:(NSEvent *)o_event
573 if( p_vout && [o_event type] == NSLeftMouseUp )
577 var_Set( p_vout, "mouse-clicked", b_val );
579 var_Get( p_vout, "mouse-button-down", &val );
581 var_Set( p_vout, "mouse-button-down", val );
584 [super mouseUp: o_event];
587 - (void)otherMouseUp:(NSEvent *)o_event
591 if( p_vout && [o_event type] == NSOtherMouseUp )
593 var_Get( p_vout, "mouse-button-down", &val );
595 var_Set( p_vout, "mouse-button-down", val );
598 [super mouseUp: o_event];
601 - (void)rightMouseUp:(NSEvent *)o_event
603 if( p_vout && [o_event type] == NSRightMouseUp )
605 /* FIXME: this isn't the appropriate place, but we can't receive
606 * NSRightMouseDown some how */
607 msg_Dbg( p_vout, "received NSRightMouseUp" );
608 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
611 [super mouseUp: o_event];
614 - (void)mouseDragged:(NSEvent *)o_event
616 [self mouseMoved: o_event];
619 - (void)otherMouseDragged:(NSEvent *)o_event
621 [self mouseMoved: o_event];
624 - (void)rightMouseDragged:(NSEvent *)o_event
626 [self mouseMoved: o_event];
629 - (void)mouseMoved:(NSEvent *)o_event
637 s_rect = [o_view bounds];
638 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
639 b_inside = [o_view mouse: ml inRect: s_rect];
644 unsigned int i_width, i_height, i_x, i_y;
646 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
647 (unsigned int)s_rect.size.height,
648 &i_x, &i_y, &i_width, &i_height );
650 val.i_int = ( ((int)ml.x) - i_x ) *
651 p_vout->render.i_width / i_width;
652 var_Set( p_vout, "mouse-x", val );
654 if( [[o_view className] isEqualToString: @"VLCGLView"] )
656 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
657 p_vout->render.i_height / i_height;
661 val.i_int = ( ((int)ml.y) - i_y ) *
662 p_vout->render.i_height / i_height;
664 var_Set( p_vout, "mouse-y", val );
667 var_Set( p_vout, "mouse-moved", val );
669 if( [self isFullscreen] )
670 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
673 [super mouseMoved: o_event];
676 - (BOOL)acceptsFirstResponder
681 - (BOOL)becomeFirstResponder
686 - (BOOL)resignFirstResponder
688 /* We need to stay the first responder or we'll miss some
693 /* Class methods used by the different vout modules */
695 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
697 /* p_real_vout: the vout we have to use to check for video-on-top
698 and a few other things. If we are the QuickTime output, it's us.
699 It we are the OpenGL provider, it is our parent. */
700 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
702 return (vout_thread_t *) p_vout->p_parent;
711 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
712 frame: (NSRect *)s_frame
714 vlc_value_t value_drawable;
718 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
720 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
721 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
722 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
723 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
724 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
725 var_Create( p_vout, "embedded-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
727 /* We only wait for NSApp to initialise if we're not embedded (as in the
728 * case of the Mozilla plugin). We can tell whether we're embedded or not
729 * by examining the "drawable" value: if it's zero, we're running in the
730 * main Mac intf; if it's non-zero, we're embedded. */
731 if( value_drawable.i_int == 0 )
733 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
734 for( i_timeout = 20 ; i_timeout-- ; )
738 msleep( INTF_IDLE_SLEEP );
744 /* No MacOS X intf, unable to communicate with MT */
745 msg_Err( p_vout, "no MacOS X interface present" );
750 if ( VLCIntf && !(p_vout->b_fullscreen) &&
751 !(var_GetBool( p_vout, "macosx-background" )) &&
752 var_GetBool( p_vout, "embedded-video") )
754 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
760 /* No embedded vout is available */
761 if( o_return == nil )
764 bzero( &null_rect, sizeof( NSRect ) );
765 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
767 [o_return setVout: p_vout subView: view frame: s_frame];
771 - (void)enterFullscreen
773 if( var_GetBool( p_real_vout, "video-on-top" ) )
775 [o_window setLevel: NSNormalWindowLevel];
778 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
779 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
782 - (void)leaveFullscreen
784 if( var_GetBool( p_real_vout, "video-on-top" ) )
786 [o_window setLevel: NSStatusWindowLevel];
789 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
790 [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
795 /*****************************************************************************
796 * VLCDetachedVoutView implementation
797 *****************************************************************************/
798 @implementation VLCDetachedVoutView
800 - (id)initWithFrame: (NSRect)frameRect
802 [super initWithFrame: frameRect];
803 i_time_mouse_last_moved = 0;
807 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
808 frame: (NSRect *) s_arg_frame
810 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
811 i_time_mouse_last_moved = mdate();
812 o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self
815 [view setFrame: [self frame]];
817 if( var_GetBool( p_real_vout, "video-on-top" ) )
819 [o_window setLevel: NSStatusWindowLevel];
823 [o_window setAcceptsMouseMovedEvents: TRUE];
829 [o_window closeWindow];
830 [o_window setAcceptsMouseMovedEvents: NO];
831 i_time_mouse_last_moved = 0;
835 - (void)mouseMoved:(NSEvent *)o_event
837 i_time_mouse_last_moved = mdate();
838 [super mouseMoved: o_event];
841 - (void)hideMouse:(BOOL)b_hide
845 NSView *o_contents = [o_window contentView];
847 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
848 ml = [o_contents convertPoint:ml fromView:nil];
849 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
851 if( b_hide && b_inside )
853 [NSCursor setHiddenUntilMouseMoves: YES];
857 [NSCursor setHiddenUntilMouseMoves: NO];
864 unsigned int i_mouse_hide_timeout =
865 var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
866 if( p_vout->b_fullscreen )
868 if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout )
870 [self hideMouse: YES];
875 [self hideMouse: NO];
881 /*****************************************************************************
882 * VLCEmbeddedVoutView implementation
883 *****************************************************************************/
885 @implementation VLCEmbeddedVoutView
887 - (id)initWithFrame: (NSRect)frameRect
889 [super initWithFrame: frameRect];
891 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
895 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
896 frame: (NSRect *)s_arg_frame showWindow: (BOOL)b_show_window
899 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
902 o_window = [self window];
904 [o_window makeKeyAndOrderFront: self];
905 [o_window setAcceptsMouseMovedEvents: TRUE];
907 if( var_GetBool( p_real_vout, "video-on-top" ) )
909 [o_window setLevel: NSStatusWindowLevel];
912 [view setFrameSize: [self frame].size];
917 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
918 frame: (NSRect *) s_arg_frame
921 return [self setVout: p_arg_vout subView: view frame:s_arg_frame showWindow: YES];
924 - (void)setUsed: (BOOL)b_new_used
937 [o_window setAcceptsMouseMovedEvents: NO];
938 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
944 @implementation VLCDetachedEmbeddedVoutView
947 o_embeddedwindow = [self window];
950 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
951 frame: (NSRect *) s_arg_frame
953 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame showWindow: NO];
955 /* o_window needs to point to our o_embeddedwindow, super might have set it
956 * to the fullscreen window that o_embeddedwindow setups during fullscreen */
957 o_window = o_embeddedwindow;
961 [o_window lockFullscreenAnimation];
963 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
967 /* Make the window the front and key window before animating */
968 if ([o_window isVisible] && (![o_window isFullscreen]))
969 [o_window makeKeyAndOrderFront: self];
971 [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
973 [o_window setAspectRatio:NSMakeSize([o_window frame].size.width, [o_window frame].size.height)];
975 /* Make sure our window is visible, if we are not in fullscreen */
976 if (![o_window isFullscreen])
977 [o_window makeKeyAndOrderFront: self];
978 [o_window unlockFullscreenAnimation];
986 playlist_t * p_playlist = pl_Yield( VLCIntf );
988 if(!playlist_IsPlaying( p_playlist ))
989 [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES];
991 vlc_object_release( p_playlist );
996 - (void)enterFullscreen
998 /* We are in a VLCEmbeddedWindow */
999 [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
1002 - (void)leaveFullscreen
1004 /* We are in a VLCEmbeddedWindow */
1005 [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
1009 /*****************************************************************************
1010 * VLCVoutWindow implementation
1011 *****************************************************************************/
1012 @implementation VLCVoutWindow
1014 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
1015 frame: (NSRect *) frame
1021 [self performSelectorOnMainThread: @selector(initReal:)
1022 withObject: NULL waitUntilDone: YES];
1032 - (id)initReal: (id) sender
1034 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1035 NSArray *o_screens = [NSScreen screens];
1037 bool b_menubar_screen = false;
1042 p_real_vout = [VLCVoutView getRealVout: p_vout];
1043 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
1045 b_embedded = var_GetBool( p_vout, "embedded-video" );
1047 /* Find out on which screen to open the window */
1048 o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1051 o_screen = [NSScreen mainScreen];
1053 if( [o_screen isMainScreen] )
1054 b_menubar_screen = true;
1056 if( p_vout->b_fullscreen )
1058 CGDisplayFadeReservationToken token;
1059 NSRect screen_rect = [o_screen frame];
1060 screen_rect.origin.x = screen_rect.origin.y = 0;
1062 b_black = var_GetBool( p_vout, "macosx-black" );
1064 /* move the FSPanel to front in case that it is currently shown
1065 * this won't and is not supposed to work when it's fading right now */
1066 if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] )
1067 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
1069 /* tell the fspanel to move itself to front next time it's triggered */
1070 [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
1072 /* Creates a window with size: screen_rect on o_screen */
1073 [self initWithContentRect: screen_rect
1074 styleMask: NSBorderlessWindowMask
1075 backing: NSBackingStoreBuffered
1076 defer: YES screen: o_screen];
1078 if( b_menubar_screen )
1080 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1082 if( b_black == true )
1084 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1085 CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1087 [o_screen blackoutOtherScreens];
1089 CGDisplayFade( token, 0.3 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1090 CGReleaseDisplayFadeReservation( token);
1093 else if( var_GetBool( p_vout, "macosx-background" ) )
1095 NSRect screen_rect = [o_screen frame];
1096 screen_rect.origin.x = screen_rect.origin.y = 0;
1098 /* Creates a window with size: screen_rect on o_screen */
1099 [self initWithContentRect: screen_rect
1100 styleMask: NSBorderlessWindowMask
1101 backing: NSBackingStoreBuffered
1102 defer: YES screen: o_screen];
1104 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1108 unsigned int i_stylemask = NSTitledWindowMask |
1109 NSMiniaturizableWindowMask |
1110 NSClosableWindowMask |
1111 NSResizableWindowMask;
1116 s_rect.size.width = p_vout->i_window_width;
1117 s_rect.size.height = p_vout->i_window_height;
1124 [self initWithContentRect: s_rect
1125 styleMask: i_stylemask
1126 backing: NSBackingStoreBuffered
1127 defer: YES screen: o_screen];
1129 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1137 [self makeKeyAndOrderFront: nil];
1138 [self setReleasedWhenClosed: YES];
1140 /* We'll catch mouse events */
1141 [self makeFirstResponder: o_view];
1143 /* Add the view. It's automatically resized to fit the window */
1144 [self setContentView: o_view];
1159 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1161 [self performSelectorOnMainThread: @selector(closeReal:)
1162 withObject: NULL waitUntilDone: NO];
1165 - (id)closeReal:(id)sender
1167 if( b_black == true )
1169 CGDisplayFadeReservationToken token;
1170 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1171 CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1173 [self disableScreenUpdatesUntilFlush];
1174 [self orderOut: self];
1176 CGDisplayFade( token, 0.6 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, YES );
1177 CGReleaseDisplayFadeReservation( token);
1178 CGDisplayRestoreColorSyncSettings();
1180 [NSScreen unblackoutScreens];
1182 SetSystemUIMode( kUIModeNormal, 0);
1184 /* this does only work in embedded mode */
1185 if( b_embedded == true )
1186 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
1196 - (BOOL)canBecomeKeyWindow
1201 /* Sometimes crashes VLC....
1202 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1204 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1207 /* This is actually the same as VLCControls::stop. */
1209 - (BOOL)windowShouldClose:(id)sender
1211 playlist_t * p_playlist = pl_Yield( p_vout );
1212 if( p_playlist == NULL )
1217 playlist_Stop( p_playlist );
1218 vlc_object_release( p_playlist );
1220 /* The window will be closed by the intf later. */