1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2007 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 K
\9fhne <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() */
35 #include <string.h> /* strerror() */
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 subView: (NSView *) view
159 frame: (NSRect *) frame
162 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
163 NSArray *o_screens = [NSScreen screens];
169 if( [o_screens count] <= 0 )
171 msg_Err( p_vout, "no OSX screens available" );
175 p_real_vout = [VLCVoutView getRealVout: p_vout];
177 /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */
178 if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 )
180 i_device = var_GetInteger( p_vout, "macosx-vdev" );
184 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
187 /* Setup the menuitem for the multiple displays. */
188 if( var_Type( p_real_vout, "video-device" ) == 0 )
191 vlc_value_t val2, text;
194 var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
196 text.psz_string = _("Video Device");
197 var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
199 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
202 text.psz_string = _("Default");
203 var_Change( p_real_vout, "video-device",
204 VLC_VAR_ADDCHOICE, &val2, &text );
205 var_Set( p_real_vout, "video-device", val2 );
207 while( (o_screen = [o_enumerator nextObject]) != NULL )
210 NSRect s_rect = [o_screen frame];
212 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
213 "%s %d (%dx%d)", _("Screen"), i,
214 (int)s_rect.size.width, (int)s_rect.size.height );
216 text.psz_string = psz_temp;
217 val2.i_int = (int)[o_screen displayID];
218 var_Change( p_real_vout, "video-device",
219 VLC_VAR_ADDCHOICE, &val2, &text );
220 if( (int)[o_screen displayID] == i_device )
222 var_Set( p_real_vout, "video-device", val2 );
227 var_AddCallback( p_real_vout, "video-device", DeviceCallback,
230 val2.b_bool = VLC_TRUE;
231 var_Set( p_real_vout, "intf-change", val2 );
234 /* Add the view. It's automatically resized to fit the window */
235 [self addSubview: o_view];
236 [self setAutoresizesSubviews: YES];
242 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize
244 [super resizeSubviewsWithOldSize: oldBoundsSize];
245 [o_view setFrameSize: [self frame].size];
248 - (void)drawRect:(NSRect)rect
250 /* When there is no subview we draw a black background */
252 [[NSColor blackColor] set];
259 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut];
261 /* Make sure we don't see a white flash */
262 [[self window] disableScreenUpdatesUntilFlush];
263 [o_view removeFromSuperview];
273 NSMutableString * o_title = nil, * o_mrl = nil;
274 input_thread_t * p_input;
281 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
283 if( p_input == NULL )
288 if( input_GetItem(p_input)->psz_name != NULL )
289 o_title = [NSMutableString stringWithUTF8String:
290 input_GetItem(p_input)->psz_name];
291 if( input_GetItem(p_input)->psz_uri != NULL )
292 o_mrl = [NSMutableString stringWithUTF8String:
293 input_GetItem(p_input)->psz_uri];
299 /* FIXME once psz_access is exported, we could check if we are
300 * reading from a file in a smarter way. */
302 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
303 if( prefix_range.location != NSNotFound )
304 [o_mrl deleteCharactersInRange: prefix_range];
306 if( [o_mrl characterAtIndex:0] == '/' )
308 /* it's a local file */
309 [o_window setRepresentedFilename: o_mrl];
313 /* it's from the network or somewhere else,
314 * we clear the previous path */
315 [o_window setRepresentedFilename: @""];
317 [o_window setTitle: o_title];
321 [o_window setTitle: [NSString stringWithCString: VOUT_TITLE]];
323 vlc_object_release( p_input );
327 - (void)setOnTop:(BOOL)b_on_top
331 [o_window setLevel: NSStatusWindowLevel];
335 [o_window setLevel: NSNormalWindowLevel];
339 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
342 int i_corrected_height, i_corrected_width;
344 NSPoint topleftscreen;
346 if ( !p_vout->b_fullscreen )
351 topleftbase.y = [o_window frame].size.height;
352 topleftscreen = [o_window convertBaseToScreen: topleftbase];
354 if( p_vout->render.i_height * p_vout->render.i_aspect >
355 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
357 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
359 newsize.width = (int) ( i_corrected_width * factor );
360 newsize.height = (int) ( p_vout->render.i_height * factor );
364 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
365 p_vout->render.i_aspect;
366 newsize.width = (int) ( p_vout->render.i_width * factor );
367 newsize.height = (int) ( i_corrected_height * factor );
370 /* In fullscreen mode we need to use a view that is different from
371 * ourselves, with the VLCEmbeddedWindow */
372 if([o_window isKindOfClass:[VLCEmbeddedWindow class]])
373 mainView = [o_window mainView];
377 /* Calculate the window's new size */
378 new_frame.size.width = [o_window frame].size.width -
379 [mainView frame].size.width + newsize.width;
380 new_frame.size.height = [o_window frame].size.height -
381 [mainView frame].size.height + newsize.height;
383 new_frame.origin.x = topleftscreen.x;
384 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
386 [o_window setFrame: new_frame display: animate animate: animate];
388 p_vout->i_changes |= VOUT_SIZE_CHANGE;
392 - (void)toggleFloatOnTop
396 if( !p_real_vout ) return;
397 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
399 val.b_bool = VLC_FALSE;
403 val.b_bool = VLC_TRUE;
405 var_Set( p_real_vout, "video-on-top", val );
408 - (void)toggleFullscreen
411 if( !p_real_vout ) return;
412 var_Get( p_real_vout, "fullscreen", &val );
413 val.b_bool = !val.b_bool;
414 var_Set( p_real_vout, "fullscreen", val );
420 if( !p_real_vout ) return NO;
421 var_Get( p_real_vout, "fullscreen", &val );
422 return( val.b_bool );
427 vout_Control( p_real_vout, VOUT_SNAPSHOT );
432 /* Disable Screensaver, when we're playing something, but allow it on pause */
433 if( VLCIntf->p_sys->i_play_status == PLAYING_S )
434 UpdateSystemActivity( UsrActivity );
442 - (void)scrollWheel:(NSEvent *)theEvent
444 VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
445 [o_controls scrollWheel: theEvent];
448 - (void)keyDown:(NSEvent *)o_event
452 unsigned int i_pressed_modifiers = 0;
455 i_pressed_modifiers = [o_event modifierFlags];
457 if( i_pressed_modifiers & NSShiftKeyMask )
458 val.i_int |= KEY_MODIFIER_SHIFT;
459 if( i_pressed_modifiers & NSControlKeyMask )
460 val.i_int |= KEY_MODIFIER_CTRL;
461 if( i_pressed_modifiers & NSAlternateKeyMask )
462 val.i_int |= KEY_MODIFIER_ALT;
463 if( i_pressed_modifiers & NSCommandKeyMask )
464 val.i_int |= KEY_MODIFIER_COMMAND;
466 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
470 /* Escape should always get you out of fullscreen */
471 if( key == (unichar) 0x1b )
473 if( p_real_vout && [self isFullscreen] )
475 [self toggleFullscreen];
478 else if ( key == ' ' )
481 val.i_int = config_GetInt( p_vout, "key-play-pause" );
482 var_Set( p_vout->p_libvlc, "key-pressed", val );
486 val.i_int |= CocoaKeyToVLC( key );
487 var_Set( p_vout->p_libvlc, "key-pressed", val );
492 [super keyDown: o_event];
496 - (void)mouseDown:(NSEvent *)o_event
502 if( ( [o_event type] == NSLeftMouseDown ) &&
503 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
505 if( [o_event clickCount] <= 1 )
507 /* single clicking */
508 var_Get( p_vout, "mouse-button-down", &val );
510 var_Set( p_vout, "mouse-button-down", val );
514 /* multiple clicking */
515 [self toggleFullscreen];
518 else if( ( [o_event type] == NSRightMouseDown ) ||
519 ( ( [o_event type] == NSLeftMouseDown ) &&
520 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
522 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
523 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
527 [super mouseDown: o_event];
530 - (void)otherMouseDown:(NSEvent *)o_event
534 if( p_vout && [o_event type] == NSOtherMouseDown )
536 var_Get( p_vout, "mouse-button-down", &val );
538 var_Set( p_vout, "mouse-button-down", val );
541 [super mouseDown: o_event];
544 - (void)rightMouseDown:(NSEvent *)o_event
546 if( p_vout && [o_event type] == NSRightMouseDown )
548 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
549 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
552 [super mouseDown: o_event];
555 - (void)mouseUp:(NSEvent *)o_event
559 if( p_vout && [o_event type] == NSLeftMouseUp )
562 b_val.b_bool = VLC_TRUE;
563 var_Set( p_vout, "mouse-clicked", b_val );
565 var_Get( p_vout, "mouse-button-down", &val );
567 var_Set( p_vout, "mouse-button-down", val );
570 [super mouseUp: o_event];
573 - (void)otherMouseUp:(NSEvent *)o_event
577 if( p_vout && [o_event type] == NSOtherMouseUp )
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)rightMouseUp:(NSEvent *)o_event
589 if( p_vout && [o_event type] == NSRightMouseUp )
591 /* FIXME: this isn't the appropriate place, but we can't receive
592 * NSRightMouseDown some how */
593 msg_Dbg( p_vout, "received NSRightMouseUp" );
594 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
597 [super mouseUp: o_event];
600 - (void)mouseDragged:(NSEvent *)o_event
602 [self mouseMoved: o_event];
605 - (void)otherMouseDragged:(NSEvent *)o_event
607 [self mouseMoved: o_event];
610 - (void)rightMouseDragged:(NSEvent *)o_event
612 [self mouseMoved: o_event];
615 - (void)mouseMoved:(NSEvent *)o_event
623 s_rect = [o_view bounds];
624 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
625 b_inside = [o_view mouse: ml inRect: s_rect];
630 unsigned int i_width, i_height, i_x, i_y;
632 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
633 (unsigned int)s_rect.size.height,
634 &i_x, &i_y, &i_width, &i_height );
636 val.i_int = ( ((int)ml.x) - i_x ) *
637 p_vout->render.i_width / i_width;
638 var_Set( p_vout, "mouse-x", val );
640 if( [[o_view className] isEqualToString: @"VLCGLView"] )
642 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
643 p_vout->render.i_height / i_height;
647 val.i_int = ( ((int)ml.y) - i_y ) *
648 p_vout->render.i_height / i_height;
650 var_Set( p_vout, "mouse-y", val );
652 val.b_bool = VLC_TRUE;
653 var_Set( p_vout, "mouse-moved", val );
655 if( [self isFullscreen] )
656 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
659 [super mouseMoved: o_event];
662 - (BOOL)acceptsFirstResponder
667 - (BOOL)becomeFirstResponder
672 - (BOOL)resignFirstResponder
674 /* We need to stay the first responder or we'll miss some
679 /* Class methods used by the different vout modules */
681 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
683 /* p_real_vout: the vout we have to use to check for video-on-top
684 and a few other things. If we are the QuickTime output, it's us.
685 It we are the OpenGL provider, it is our parent. */
686 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
688 return (vout_thread_t *) p_vout->p_parent;
697 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
698 frame: (NSRect *)s_frame
700 vlc_value_t value_drawable;
704 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
706 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
707 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
708 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
709 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
710 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
711 var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
714 /* We only wait for NSApp to initialise if we're not embedded (as in the
715 * case of the Mozilla plugin). We can tell whether we're embedded or not
716 * by examining the "drawable" value: if it's zero, we're running in the
717 * main Mac intf; if it's non-zero, we're embedded. */
718 if( value_drawable.i_int == 0 )
720 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
721 for( i_timeout = 20 ; i_timeout-- ; )
725 msleep( INTF_IDLE_SLEEP );
731 /* No MacOS X intf, unable to communicate with MT */
732 msg_Err( p_vout, "no MacOS X interface present" );
737 if ( VLCIntf && !(p_vout->b_fullscreen) &&
738 !(var_GetBool( p_vout, "macosx-background" )) &&
739 var_GetBool( p_vout, "macosx-embedded") )
741 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
747 /* No embedded vout is available */
748 if( o_return == nil )
751 bzero( &null_rect, sizeof( NSRect ) );
752 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
754 [o_return setVout: p_vout subView: view frame: s_frame];
758 - (void)enterFullscreen
760 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
761 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
764 - (void)leaveFullscreen
766 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
767 [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
772 /*****************************************************************************
773 * VLCDetachedVoutView implementation
774 *****************************************************************************/
775 @implementation VLCDetachedVoutView
777 - (id)initWithFrame: (NSRect)frameRect
779 [super initWithFrame: frameRect];
780 i_time_mouse_last_moved = 0;
784 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
785 frame: (NSRect *) s_arg_frame
787 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
788 i_time_mouse_last_moved = mdate();
789 o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self
792 [view setFrame: [self frame]];
794 if( var_GetBool( p_real_vout, "video-on-top" ) )
796 [o_window setLevel: NSStatusWindowLevel];
800 [o_window setAcceptsMouseMovedEvents: TRUE];
806 [o_window closeWindow];
807 [o_window setAcceptsMouseMovedEvents: NO];
808 i_time_mouse_last_moved = 0;
812 - (void)mouseMoved:(NSEvent *)o_event
814 i_time_mouse_last_moved = mdate();
815 [super mouseMoved: o_event];
818 - (void)hideMouse:(BOOL)b_hide
822 NSView *o_contents = [o_window contentView];
824 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
825 ml = [o_contents convertPoint:ml fromView:nil];
826 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
828 if( b_hide && b_inside )
830 [NSCursor setHiddenUntilMouseMoves: YES];
834 [NSCursor setHiddenUntilMouseMoves: NO];
841 if( p_vout->b_fullscreen )
843 if( mdate() - i_time_mouse_last_moved > 3000000 )
845 [self hideMouse: YES];
850 [self hideMouse: NO];
856 /*****************************************************************************
857 * VLCEmbeddedVoutView implementation
858 *****************************************************************************/
860 @implementation VLCEmbeddedVoutView
862 - (id)initWithFrame: (NSRect)frameRect
864 [super initWithFrame: frameRect];
866 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
870 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
871 frame: (NSRect *)s_arg_frame showWindow: (BOOL)b_show_window
874 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
877 o_window = [self window];
879 [o_window makeKeyAndOrderFront: self];
880 [o_window setAcceptsMouseMovedEvents: TRUE];
882 if( var_GetBool( p_real_vout, "video-on-top" ) )
884 [o_window setLevel: NSStatusWindowLevel];
887 [view setFrameSize: [self frame].size];
892 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
893 frame: (NSRect *) s_arg_frame
896 return [self setVout: p_arg_vout subView: view frame:s_arg_frame showWindow: YES];
899 - (void)setUsed: (BOOL)b_new_used
912 [o_window setAcceptsMouseMovedEvents: NO];
913 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
919 @implementation VLCDetachedEmbeddedVoutView
922 o_embeddedwindow = [self window];
925 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
926 frame: (NSRect *) s_arg_frame
928 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame showWindow: NO];
930 /* o_window needs to point to our o_embeddedwindow, super might have set it
931 * to the fullscreen window that o_embeddedwindow setups during fullscreen */
932 o_window = o_embeddedwindow;
936 [o_window lockFullscreenAnimation];
938 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
942 /* Make the window the front and key window before animating */
943 if ([o_window isVisible] && (![o_window isFullscreen]))
944 [o_window makeKeyAndOrderFront: self];
946 [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
948 [o_window setAspectRatio:NSMakeSize([o_window frame].size.width, [o_window frame].size.height)];
950 /* Make sure our window is visible, if we are not in fullscreen */
951 if (![o_window isFullscreen])
952 [o_window makeKeyAndOrderFront: self];
953 [o_window unlockFullscreenAnimation];
961 playlist_t * p_playlist = pl_Yield( VLCIntf );
963 if(!playlist_IsPlaying( p_playlist ))
964 [o_window performSelectorOnMainThread: @selector(orderOut:) withObject: self waitUntilDone: YES];
966 vlc_object_release( p_playlist );
971 - (void)enterFullscreen
973 /* We are in a VLCEmbeddedWindow */
974 [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
977 - (void)leaveFullscreen
979 /* We are in a VLCEmbeddedWindow */
980 [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
984 /*****************************************************************************
985 * VLCVoutWindow implementation
986 *****************************************************************************/
987 @implementation VLCVoutWindow
989 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
990 frame: (NSRect *) frame
996 [self performSelectorOnMainThread: @selector(initReal:)
997 withObject: NULL waitUntilDone: YES];
1007 - (id)initReal: (id) sender
1009 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1010 NSArray *o_screens = [NSScreen screens];
1012 vlc_bool_t b_menubar_screen = VLC_FALSE;
1015 b_init_ok = VLC_FALSE;
1017 p_real_vout = [VLCVoutView getRealVout: p_vout];
1018 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
1020 b_embedded = var_GetBool( p_vout, "macosx-embedded" );
1022 /* Find out on which screen to open the window */
1023 o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1026 o_screen = [NSScreen mainScreen];
1028 if( [o_screen isMainScreen] )
1029 b_menubar_screen = VLC_TRUE;
1031 if( p_vout->b_fullscreen )
1033 CGDisplayFadeReservationToken token;
1034 NSRect screen_rect = [o_screen frame];
1035 screen_rect.origin.x = screen_rect.origin.y = 0;
1037 b_black = var_GetBool( p_vout, "macosx-black" );
1039 /* move the FSPanel to front in case that it is currently shown
1040 * this won't and is not supposed to work when it's fading right now */
1041 if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] )
1042 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
1044 /* tell the fspanel to move itself to front next time it's triggered */
1045 [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
1047 /* Creates a window with size: screen_rect on o_screen */
1048 [self initWithContentRect: screen_rect
1049 styleMask: NSBorderlessWindowMask
1050 backing: NSBackingStoreBuffered
1051 defer: YES screen: o_screen];
1053 if( b_menubar_screen )
1055 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1057 if( b_black == VLC_TRUE )
1059 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1060 CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1062 [o_screen blackoutOtherScreens];
1064 CGDisplayFade( token, 0.3 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1065 CGReleaseDisplayFadeReservation( token);
1068 else if( var_GetBool( p_vout, "macosx-background" ) )
1070 NSRect screen_rect = [o_screen frame];
1071 screen_rect.origin.x = screen_rect.origin.y = 0;
1073 /* Creates a window with size: screen_rect on o_screen */
1074 [self initWithContentRect: screen_rect
1075 styleMask: NSBorderlessWindowMask
1076 backing: NSBackingStoreBuffered
1077 defer: YES screen: o_screen];
1079 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1083 unsigned int i_stylemask = NSTitledWindowMask |
1084 NSMiniaturizableWindowMask |
1085 NSClosableWindowMask |
1086 NSResizableWindowMask;
1091 s_rect.size.width = p_vout->i_window_width;
1092 s_rect.size.height = p_vout->i_window_height;
1099 [self initWithContentRect: s_rect
1100 styleMask: i_stylemask
1101 backing: NSBackingStoreBuffered
1102 defer: YES screen: o_screen];
1104 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1112 [self makeKeyAndOrderFront: nil];
1113 [self setReleasedWhenClosed: YES];
1115 /* We'll catch mouse events */
1116 [self makeFirstResponder: o_view];
1118 /* Add the view. It's automatically resized to fit the window */
1119 [self setContentView: o_view];
1123 b_init_ok = VLC_TRUE;
1134 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1136 [self performSelectorOnMainThread: @selector(closeReal:)
1137 withObject: NULL waitUntilDone: NO];
1140 - (id)closeReal:(id)sender
1142 if( b_black == VLC_TRUE )
1144 CGDisplayFadeReservationToken token;
1145 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1146 CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1148 [self disableScreenUpdatesUntilFlush];
1149 [self orderOut: self];
1151 CGDisplayFade( token, 0.6 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, YES );
1152 CGReleaseDisplayFadeReservation( token);
1153 CGDisplayRestoreColorSyncSettings();
1155 [NSScreen unblackoutScreens];
1157 SetSystemUIMode( kUIModeNormal, 0);
1159 /* this does only work in embedded mode */
1160 if( b_embedded == VLC_TRUE )
1161 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
1171 - (BOOL)canBecomeKeyWindow
1176 /* Sometimes crashes VLC....
1177 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1179 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1182 /* This is actually the same as VLCControls::stop. */
1184 - (BOOL)windowShouldClose:(id)sender
1186 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1188 if( p_playlist == NULL )
1193 playlist_Stop( p_playlist );
1194 vlc_object_release( p_playlist );
1196 /* The window will be closed by the intf later. */