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 );
61 val.b_bool = VLC_TRUE;
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 = _("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,
231 val2.b_bool = VLC_TRUE;
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)
410 val.b_bool = VLC_FALSE;
414 val.b_bool = VLC_TRUE;
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 )
576 b_val.b_bool = VLC_TRUE;
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 );
666 val.b_bool = VLC_TRUE;
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 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
774 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
777 - (void)leaveFullscreen
779 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
780 [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
785 /*****************************************************************************
786 * VLCDetachedVoutView implementation
787 *****************************************************************************/
788 @implementation VLCDetachedVoutView
790 - (id)initWithFrame: (NSRect)frameRect
792 [super initWithFrame: frameRect];
793 i_time_mouse_last_moved = 0;
797 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
798 frame: (NSRect *) s_arg_frame
800 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
801 i_time_mouse_last_moved = mdate();
802 o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self
805 [view setFrame: [self frame]];
807 if( var_GetBool( p_real_vout, "video-on-top" ) )
809 [o_window setLevel: NSStatusWindowLevel];
813 [o_window setAcceptsMouseMovedEvents: TRUE];
819 [o_window closeWindow];
820 [o_window setAcceptsMouseMovedEvents: NO];
821 i_time_mouse_last_moved = 0;
825 - (void)mouseMoved:(NSEvent *)o_event
827 i_time_mouse_last_moved = mdate();
828 [super mouseMoved: o_event];
831 - (void)hideMouse:(BOOL)b_hide
835 NSView *o_contents = [o_window contentView];
837 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
838 ml = [o_contents convertPoint:ml fromView:nil];
839 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
841 if( b_hide && b_inside )
843 [NSCursor setHiddenUntilMouseMoves: YES];
847 [NSCursor setHiddenUntilMouseMoves: NO];
854 unsigned int i_mouse_hide_timeout =
855 var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
856 if( p_vout->b_fullscreen )
858 if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout )
860 [self hideMouse: YES];
865 [self hideMouse: NO];
871 /*****************************************************************************
872 * VLCEmbeddedVoutView implementation
873 *****************************************************************************/
875 @implementation VLCEmbeddedVoutView
877 - (id)initWithFrame: (NSRect)frameRect
879 [super initWithFrame: frameRect];
881 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
885 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
886 frame: (NSRect *)s_arg_frame showWindow: (BOOL)b_show_window
889 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
892 o_window = [self window];
894 [o_window makeKeyAndOrderFront: self];
895 [o_window setAcceptsMouseMovedEvents: TRUE];
897 if( var_GetBool( p_real_vout, "video-on-top" ) )
899 [o_window setLevel: NSStatusWindowLevel];
902 [view setFrameSize: [self frame].size];
907 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
908 frame: (NSRect *) s_arg_frame
911 return [self setVout: p_arg_vout subView: view frame:s_arg_frame showWindow: YES];
914 - (void)setUsed: (BOOL)b_new_used
927 [o_window setAcceptsMouseMovedEvents: NO];
928 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
934 @implementation VLCDetachedEmbeddedVoutView
937 o_embeddedwindow = [self window];
940 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
941 frame: (NSRect *) s_arg_frame
943 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame showWindow: NO];
945 /* o_window needs to point to our o_embeddedwindow, super might have set it
946 * to the fullscreen window that o_embeddedwindow setups during fullscreen */
947 o_window = o_embeddedwindow;
951 [o_window lockFullscreenAnimation];
953 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
957 /* Make the window the front and key window before animating */
958 if ([o_window isVisible] && (![o_window isFullscreen]))
959 [o_window makeKeyAndOrderFront: self];
961 [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
963 [o_window setAspectRatio:NSMakeSize([o_window frame].size.width, [o_window frame].size.height)];
965 /* Make sure our window is visible, if we are not in fullscreen */
966 if (![o_window isFullscreen])
967 [o_window makeKeyAndOrderFront: self];
968 [o_window unlockFullscreenAnimation];
976 playlist_t * p_playlist = pl_Yield( VLCIntf );
978 if(!playlist_IsPlaying( p_playlist ))
979 [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES];
981 vlc_object_release( p_playlist );
986 - (void)enterFullscreen
988 /* We are in a VLCEmbeddedWindow */
989 [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
992 - (void)leaveFullscreen
994 /* We are in a VLCEmbeddedWindow */
995 [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
999 /*****************************************************************************
1000 * VLCVoutWindow implementation
1001 *****************************************************************************/
1002 @implementation VLCVoutWindow
1004 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
1005 frame: (NSRect *) frame
1011 [self performSelectorOnMainThread: @selector(initReal:)
1012 withObject: NULL waitUntilDone: YES];
1022 - (id)initReal: (id) sender
1024 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1025 NSArray *o_screens = [NSScreen screens];
1027 vlc_bool_t b_menubar_screen = VLC_FALSE;
1030 b_init_ok = VLC_FALSE;
1032 p_real_vout = [VLCVoutView getRealVout: p_vout];
1033 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
1035 b_embedded = var_GetBool( p_vout, "embedded-video" );
1037 /* Find out on which screen to open the window */
1038 o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1041 o_screen = [NSScreen mainScreen];
1043 if( [o_screen isMainScreen] )
1044 b_menubar_screen = VLC_TRUE;
1046 if( p_vout->b_fullscreen )
1048 CGDisplayFadeReservationToken token;
1049 NSRect screen_rect = [o_screen frame];
1050 screen_rect.origin.x = screen_rect.origin.y = 0;
1052 b_black = var_GetBool( p_vout, "macosx-black" );
1054 /* move the FSPanel to front in case that it is currently shown
1055 * this won't and is not supposed to work when it's fading right now */
1056 if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] )
1057 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
1059 /* tell the fspanel to move itself to front next time it's triggered */
1060 [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
1062 /* Creates a window with size: screen_rect on o_screen */
1063 [self initWithContentRect: screen_rect
1064 styleMask: NSBorderlessWindowMask
1065 backing: NSBackingStoreBuffered
1066 defer: YES screen: o_screen];
1068 if( b_menubar_screen )
1070 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1072 if( b_black == VLC_TRUE )
1074 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1075 CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1077 [o_screen blackoutOtherScreens];
1079 CGDisplayFade( token, 0.3 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1080 CGReleaseDisplayFadeReservation( token);
1083 else if( var_GetBool( p_vout, "macosx-background" ) )
1085 NSRect screen_rect = [o_screen frame];
1086 screen_rect.origin.x = screen_rect.origin.y = 0;
1088 /* Creates a window with size: screen_rect on o_screen */
1089 [self initWithContentRect: screen_rect
1090 styleMask: NSBorderlessWindowMask
1091 backing: NSBackingStoreBuffered
1092 defer: YES screen: o_screen];
1094 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1098 unsigned int i_stylemask = NSTitledWindowMask |
1099 NSMiniaturizableWindowMask |
1100 NSClosableWindowMask |
1101 NSResizableWindowMask;
1106 s_rect.size.width = p_vout->i_window_width;
1107 s_rect.size.height = p_vout->i_window_height;
1114 [self initWithContentRect: s_rect
1115 styleMask: i_stylemask
1116 backing: NSBackingStoreBuffered
1117 defer: YES screen: o_screen];
1119 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1127 [self makeKeyAndOrderFront: nil];
1128 [self setReleasedWhenClosed: YES];
1130 /* We'll catch mouse events */
1131 [self makeFirstResponder: o_view];
1133 /* Add the view. It's automatically resized to fit the window */
1134 [self setContentView: o_view];
1138 b_init_ok = VLC_TRUE;
1149 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1151 [self performSelectorOnMainThread: @selector(closeReal:)
1152 withObject: NULL waitUntilDone: NO];
1155 - (id)closeReal:(id)sender
1157 if( b_black == VLC_TRUE )
1159 CGDisplayFadeReservationToken token;
1160 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1161 CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1163 [self disableScreenUpdatesUntilFlush];
1164 [self orderOut: self];
1166 CGDisplayFade( token, 0.6 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, YES );
1167 CGReleaseDisplayFadeReservation( token);
1168 CGDisplayRestoreColorSyncSettings();
1170 [NSScreen unblackoutScreens];
1172 SetSystemUIMode( kUIModeNormal, 0);
1174 /* this does only work in embedded mode */
1175 if( b_embedded == VLC_TRUE )
1176 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
1186 - (BOOL)canBecomeKeyWindow
1191 /* Sometimes crashes VLC....
1192 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1194 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1197 /* This is actually the same as VLCControls::stop. */
1199 - (BOOL)windowShouldClose:(id)sender
1201 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1203 if( p_playlist == NULL )
1208 playlist_Stop( p_playlist );
1209 vlc_object_release( p_playlist );
1211 /* The window will be closed by the intf later. */