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;
279 if( !p_vout ) return;
281 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
283 if( !p_input ) return;
285 input_item_t * p_item = input_GetItem( p_input );
287 psz_title = input_item_GetNowPlaying ( p_item );
289 psz_title = input_item_GetName( p_item );
292 o_title = [NSString stringWithUTF8String: psz_title];
294 char *psz_uri = input_item_GetURI( p_item );
296 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
306 /* FIXME once psz_access is exported, we could check if we are
307 * reading from a file in a smarter way. */
309 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
310 if( prefix_range.location != NSNotFound )
311 [o_mrl deleteCharactersInRange: prefix_range];
313 if( [o_mrl characterAtIndex:0] == '/' )
315 /* it's a local file */
316 [o_window setRepresentedFilename: o_mrl];
320 /* it's from the network or somewhere else,
321 * we clear the previous path */
322 [o_window setRepresentedFilename: @""];
324 [o_window setTitle: o_title];
328 [o_window setTitle: [NSString stringWithUTF8String: VOUT_TITLE]];
330 vlc_object_release( p_input );
334 - (void)setOnTop:(BOOL)b_on_top
338 [o_window setLevel: NSStatusWindowLevel];
342 [o_window setLevel: NSNormalWindowLevel];
346 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
349 int i_corrected_height, i_corrected_width;
351 NSPoint topleftscreen;
353 if ( !p_vout->b_fullscreen )
358 topleftbase.y = [o_window frame].size.height;
359 topleftscreen = [o_window convertBaseToScreen: topleftbase];
361 if( p_vout->render.i_height * p_vout->render.i_aspect >
362 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
364 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
366 newsize.width = (int) ( i_corrected_width * factor );
367 newsize.height = (int) ( p_vout->render.i_height * factor );
371 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
372 p_vout->render.i_aspect;
373 newsize.width = (int) ( p_vout->render.i_width * factor );
374 newsize.height = (int) ( i_corrected_height * factor );
377 /* In fullscreen mode we need to use a view that is different from
378 * ourselves, with the VLCEmbeddedWindow */
379 if([o_window isKindOfClass:[VLCEmbeddedWindow class]])
380 mainView = [o_window mainView];
384 /* Calculate the window's new size */
385 new_frame.size.width = [o_window frame].size.width -
386 [mainView frame].size.width + newsize.width;
387 new_frame.size.height = [o_window frame].size.height -
388 [mainView frame].size.height + newsize.height;
390 new_frame.origin.x = topleftscreen.x;
391 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
393 [o_window setFrame: new_frame display: animate animate: animate];
395 p_vout->i_changes |= VOUT_SIZE_CHANGE;
399 - (void)toggleFloatOnTop
403 if( !p_real_vout ) return;
404 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
412 var_Set( p_real_vout, "video-on-top", val );
415 - (void)toggleFullscreen
418 if( !p_real_vout ) return;
419 var_Get( p_real_vout, "fullscreen", &val );
420 val.b_bool = !val.b_bool;
421 var_Set( p_real_vout, "fullscreen", val );
427 if( !p_real_vout ) return NO;
428 var_Get( p_real_vout, "fullscreen", &val );
429 return( val.b_bool );
434 vout_Control( p_real_vout, VOUT_SNAPSHOT );
439 /* Disable Screensaver, when we're playing something, but allow it on pause */
440 if( !VLCIntf || !VLCIntf->p_sys || !VLCIntf->p_sys->i_play_status )
443 if( VLCIntf->p_sys->i_play_status == PLAYING_S )
444 UpdateSystemActivity( UsrActivity );
452 - (void)scrollWheel:(NSEvent *)theEvent
454 VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
455 [o_controls scrollWheel: theEvent];
458 - (void)keyDown:(NSEvent *)o_event
462 unsigned int i_pressed_modifiers = 0;
465 i_pressed_modifiers = [o_event modifierFlags];
467 if( i_pressed_modifiers & NSShiftKeyMask )
468 val.i_int |= KEY_MODIFIER_SHIFT;
469 if( i_pressed_modifiers & NSControlKeyMask )
470 val.i_int |= KEY_MODIFIER_CTRL;
471 if( i_pressed_modifiers & NSAlternateKeyMask )
472 val.i_int |= KEY_MODIFIER_ALT;
473 if( i_pressed_modifiers & NSCommandKeyMask )
474 val.i_int |= KEY_MODIFIER_COMMAND;
476 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
480 /* Escape should always get you out of fullscreen */
481 if( key == (unichar) 0x1b )
483 if( p_real_vout && [self isFullscreen] )
485 [self toggleFullscreen];
488 else if ( key == ' ' )
491 val.i_int = config_GetInt( p_vout, "key-play-pause" );
492 var_Set( p_vout->p_libvlc, "key-pressed", val );
496 val.i_int |= CocoaKeyToVLC( key );
497 var_Set( p_vout->p_libvlc, "key-pressed", val );
502 [super keyDown: o_event];
506 - (void)mouseDown:(NSEvent *)o_event
512 if( ( [o_event type] == NSLeftMouseDown ) &&
513 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
515 if( [o_event clickCount] <= 1 )
517 /* single clicking */
518 var_Get( p_vout, "mouse-button-down", &val );
520 var_Set( p_vout, "mouse-button-down", val );
524 /* multiple clicking */
525 [self toggleFullscreen];
528 else if( ( [o_event type] == NSRightMouseDown ) ||
529 ( ( [o_event type] == NSLeftMouseDown ) &&
530 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
532 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
533 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
537 [super mouseDown: o_event];
540 - (void)otherMouseDown:(NSEvent *)o_event
544 if( p_vout && [o_event type] == NSOtherMouseDown )
546 var_Get( p_vout, "mouse-button-down", &val );
548 var_Set( p_vout, "mouse-button-down", val );
551 [super mouseDown: o_event];
554 - (void)rightMouseDown:(NSEvent *)o_event
556 if( p_vout && [o_event type] == NSRightMouseDown )
558 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
559 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
562 [super mouseDown: o_event];
565 - (void)mouseUp:(NSEvent *)o_event
569 if( p_vout && [o_event type] == NSLeftMouseUp )
573 var_Set( p_vout, "mouse-clicked", b_val );
575 var_Get( p_vout, "mouse-button-down", &val );
577 var_Set( p_vout, "mouse-button-down", val );
580 [super mouseUp: o_event];
583 - (void)otherMouseUp:(NSEvent *)o_event
587 if( p_vout && [o_event type] == NSOtherMouseUp )
589 var_Get( p_vout, "mouse-button-down", &val );
591 var_Set( p_vout, "mouse-button-down", val );
594 [super mouseUp: o_event];
597 - (void)rightMouseUp:(NSEvent *)o_event
599 if( p_vout && [o_event type] == NSRightMouseUp )
601 /* FIXME: this isn't the appropriate place, but we can't receive
602 * NSRightMouseDown some how */
603 msg_Dbg( p_vout, "received NSRightMouseUp" );
604 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
607 [super mouseUp: o_event];
610 - (void)mouseDragged:(NSEvent *)o_event
612 [self mouseMoved: o_event];
615 - (void)otherMouseDragged:(NSEvent *)o_event
617 [self mouseMoved: o_event];
620 - (void)rightMouseDragged:(NSEvent *)o_event
622 [self mouseMoved: o_event];
625 - (void)mouseMoved:(NSEvent *)o_event
633 s_rect = [o_view bounds];
634 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
635 b_inside = [o_view mouse: ml inRect: s_rect];
640 unsigned int i_width, i_height, i_x, i_y;
642 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
643 (unsigned int)s_rect.size.height,
644 &i_x, &i_y, &i_width, &i_height );
646 val.i_int = ( ((int)ml.x) - i_x ) *
647 p_vout->render.i_width / i_width;
648 var_Set( p_vout, "mouse-x", val );
650 if( [[o_view className] isEqualToString: @"VLCGLView"] )
652 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
653 p_vout->render.i_height / i_height;
657 val.i_int = ( ((int)ml.y) - i_y ) *
658 p_vout->render.i_height / i_height;
660 var_Set( p_vout, "mouse-y", val );
663 var_Set( p_vout, "mouse-moved", val );
665 if( [self isFullscreen] )
666 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
669 [super mouseMoved: o_event];
672 - (BOOL)acceptsFirstResponder
677 - (BOOL)becomeFirstResponder
682 - (BOOL)resignFirstResponder
684 /* We need to stay the first responder or we'll miss some
689 /* Class methods used by the different vout modules */
691 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
693 /* p_real_vout: the vout we have to use to check for video-on-top
694 and a few other things. If we are the QuickTime output, it's us.
695 It we are the OpenGL provider, it is our parent. */
696 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
698 return (vout_thread_t *) p_vout->p_parent;
707 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
708 frame: (NSRect *)s_frame
710 vlc_value_t value_drawable;
714 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
716 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
717 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
718 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
719 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
720 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
721 var_Create( p_vout, "embedded-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
723 /* We only wait for NSApp to initialise if we're not embedded (as in the
724 * case of the Mozilla plugin). We can tell whether we're embedded or not
725 * by examining the "drawable" value: if it's zero, we're running in the
726 * main Mac intf; if it's non-zero, we're embedded. */
727 if( value_drawable.i_int == 0 )
729 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
730 for( i_timeout = 20 ; i_timeout-- ; )
734 msleep( INTF_IDLE_SLEEP );
740 /* No MacOS X intf, unable to communicate with MT */
741 msg_Err( p_vout, "no MacOS X interface present" );
746 if ( VLCIntf && !(p_vout->b_fullscreen) &&
747 !(var_GetBool( p_vout, "macosx-background" )) &&
748 var_GetBool( p_vout, "embedded-video") )
750 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
756 /* No embedded vout is available */
757 if( o_return == nil )
760 bzero( &null_rect, sizeof( NSRect ) );
761 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
763 [o_return setVout: p_vout subView: view frame: s_frame];
767 - (void)enterFullscreen
769 /* Save the settings for next playing item */
770 playlist_t * p_playlist = pl_Yield( p_real_vout );
771 var_SetBool( p_playlist, "fullscreen", true );
772 pl_Release( p_real_vout );
775 - (void)leaveFullscreen
777 /* Save the settings for next playing item */
778 playlist_t * p_playlist = pl_Yield( p_real_vout );
779 var_SetBool( p_playlist, "fullscreen", false );
780 pl_Release( p_real_vout );
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];
812 [o_window setAcceptsMouseMovedEvents: TRUE];
818 [o_window closeWindow];
819 [o_window setAcceptsMouseMovedEvents: NO];
820 i_time_mouse_last_moved = 0;
824 - (void)mouseMoved:(NSEvent *)o_event
826 i_time_mouse_last_moved = mdate();
827 [super mouseMoved: o_event];
830 - (void)hideMouse:(BOOL)b_hide
834 NSView *o_contents = [o_window contentView];
836 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
837 ml = [o_contents convertPoint:ml fromView:nil];
838 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
840 if( b_hide && b_inside )
842 [NSCursor setHiddenUntilMouseMoves: YES];
846 [NSCursor setHiddenUntilMouseMoves: NO];
853 unsigned int i_mouse_hide_timeout =
854 var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
855 if( p_vout->b_fullscreen )
857 if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout )
859 [self hideMouse: YES];
864 [self hideMouse: NO];
869 - (void)enterFullscreen
871 [super enterFullscreen];
873 if( var_GetBool( p_real_vout, "video-on-top" ) )
875 [o_window setLevel: NSNormalWindowLevel];
878 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
879 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
882 - (void)leaveFullscreen
884 [super leaveFullscreen];
886 if( var_GetBool( p_real_vout, "video-on-top" ) )
888 [o_window setLevel: NSStatusWindowLevel];
891 [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
892 [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
897 /*****************************************************************************
898 * VLCEmbeddedVoutView implementation
899 *****************************************************************************/
901 @implementation VLCEmbeddedVoutView
905 o_embeddedwindow = [self window];
908 - (id)initWithFrame: (NSRect)frameRect
910 if(self = [super initWithFrame: frameRect])
913 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
914 o_embeddedwindow = nil; /* Filled later on in -awakeFromNib */
919 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
920 frame: (NSRect *)s_arg_frame
924 [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
926 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
929 o_window = [self window];
931 [o_window setAcceptsMouseMovedEvents: TRUE];
933 if( var_GetBool( p_real_vout, "video-on-top" ) )
935 [o_window setLevel: NSStatusWindowLevel];
938 [view setFrameSize: [self frame].size];
941 /* o_window needs to point to our o_embeddedwindow, super might have set it
942 * to the fullscreen window that o_embeddedwindow setups during fullscreen */
943 o_window = o_embeddedwindow;
947 [o_window lockFullscreenAnimation];
949 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
953 [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
955 /* Make the window the front and key window before animating */
956 if ([o_window isVisible] && (![o_window isFullscreen]))
957 [o_window makeKeyAndOrderFront: self];
959 [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
961 [o_window setAspectRatio:NSMakeSize([o_window frame].size.width, [o_window frame].size.height)];
963 /* Make sure our window is visible, if we are not in fullscreen */
964 if (![o_window isFullscreen])
965 [o_window makeKeyAndOrderFront: self];
966 [o_window unlockFullscreenAnimation];
973 - (void)setUsed: (BOOL)b_new_used
987 /* Don't close the window yet, wait a bit to see if a new input is poping up */
988 /* FIXME: Probably fade the window In and Out */
989 /* FIXME: fix core */
990 [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:3.];
992 [o_window setAcceptsMouseMovedEvents: NO];
993 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
996 - (void)enterFullscreen
999 [super enterFullscreen];
1001 /* We are in a VLCEmbeddedWindow */
1002 [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
1005 - (void)leaveFullscreen
1008 [super leaveFullscreen];
1010 /* We are in a VLCEmbeddedWindow */
1011 [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
1015 /*****************************************************************************
1016 * VLCVoutWindow implementation
1017 *****************************************************************************/
1018 @implementation VLCVoutWindow
1020 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
1021 frame: (NSRect *) frame
1027 [self performSelectorOnMainThread: @selector(initMainThread:)
1028 withObject: NULL waitUntilDone: YES];
1038 - (id)initMainThread: (id) sender
1040 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
1041 NSArray *o_screens = [NSScreen screens];
1043 bool b_menubar_screen = false;
1048 p_real_vout = [VLCVoutView getRealVout: p_vout];
1049 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
1051 b_embedded = var_GetBool( p_vout, "embedded-video" );
1053 /* Find out on which screen to open the window */
1054 o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1057 o_screen = [NSScreen mainScreen];
1059 if( [o_screen isMainScreen] )
1060 b_menubar_screen = true;
1062 if( p_vout->b_fullscreen )
1064 CGDisplayFadeReservationToken token;
1065 NSRect screen_rect = [o_screen frame];
1066 screen_rect.origin.x = screen_rect.origin.y = 0;
1068 b_black = var_GetBool( p_vout, "macosx-black" );
1070 /* move the FSPanel to front in case that it is currently shown
1071 * this won't and is not supposed to work when it's fading right now */
1072 if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] )
1073 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
1075 /* tell the fspanel to move itself to front next time it's triggered */
1076 [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
1078 /* Creates a window with size: screen_rect on o_screen */
1079 [self initWithContentRect: screen_rect
1080 styleMask: NSBorderlessWindowMask
1081 backing: NSBackingStoreBuffered
1082 defer: YES screen: o_screen];
1084 if( b_menubar_screen )
1086 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1088 if( b_black == true )
1090 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1091 CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1093 [o_screen blackoutOtherScreens];
1095 CGDisplayFade( token, 0.3 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
1096 CGReleaseDisplayFadeReservation( token);
1099 else if( var_GetBool( p_vout, "macosx-background" ) )
1101 NSRect screen_rect = [o_screen frame];
1102 screen_rect.origin.x = screen_rect.origin.y = 0;
1104 /* Creates a window with size: screen_rect on o_screen */
1105 [self initWithContentRect: screen_rect
1106 styleMask: NSBorderlessWindowMask
1107 backing: NSBackingStoreBuffered
1108 defer: YES screen: o_screen];
1110 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1114 unsigned int i_stylemask = NSTitledWindowMask |
1115 NSMiniaturizableWindowMask |
1116 NSClosableWindowMask |
1117 NSResizableWindowMask;
1122 s_rect.size.width = p_vout->i_window_width;
1123 s_rect.size.height = p_vout->i_window_height;
1130 [self initWithContentRect: s_rect
1131 styleMask: i_stylemask
1132 backing: NSBackingStoreBuffered
1133 defer: YES screen: o_screen];
1135 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1143 [self makeKeyAndOrderFront: nil];
1144 [self setReleasedWhenClosed: YES];
1146 /* We'll catch mouse events */
1147 [self makeFirstResponder: o_view];
1149 /* Add the view. It's automatically resized to fit the window */
1150 [self setContentView: o_view];
1165 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1167 [self performSelectorOnMainThread: @selector(closeMainThread:)
1168 withObject: NULL waitUntilDone: NO];
1171 - (id)closeMainThread:(id)sender
1173 if( b_black == true )
1175 CGDisplayFadeReservationToken token;
1176 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1177 CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
1179 [self disableScreenUpdatesUntilFlush];
1180 [self orderOut: self];
1182 CGDisplayFade( token, 0.6 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, YES );
1183 CGReleaseDisplayFadeReservation( token);
1184 CGDisplayRestoreColorSyncSettings();
1186 [NSScreen unblackoutScreens];
1188 SetSystemUIMode( kUIModeNormal, 0);
1190 /* this does only work in embedded mode */
1191 if( b_embedded == true )
1192 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
1202 - (BOOL)canBecomeKeyWindow
1207 /* Sometimes crashes VLC....
1208 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1210 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1213 /* This is actually the same as VLCControls::stop. */
1215 - (BOOL)windowShouldClose:(id)sender
1217 playlist_t * p_playlist = pl_Yield( p_vout );
1218 if( p_playlist == NULL )
1223 playlist_Stop( p_playlist );
1224 vlc_object_release( p_playlist );
1226 /* The window will be closed by the intf later. */