1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2009 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>
40 /* prevent system sleep */
41 #import <CoreServices/CoreServices.h>
49 #import "embeddedwindow.h"
51 /*****************************************************************************
52 * DeviceCallback: Callback triggered when the video-device variable is changed
53 *****************************************************************************/
54 int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
55 vlc_value_t old_val, vlc_value_t new_val, void *param )
58 vout_thread_t *p_vout = (vout_thread_t *)p_this;
60 msg_Dbg( p_vout, "set %d", new_val.i_int );
61 var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
62 var_Set( p_vout->p_libvlc, "video-device", new_val );
65 var_Set( p_vout, "intf-change", val );
70 /*****************************************************************************
71 * VLCEmbeddedList implementation
72 *****************************************************************************/
73 @implementation VLCEmbeddedList
78 o_embedded_array = [NSMutableArray array];
86 for( i = 0; i < [o_embedded_array count]; i++ )
88 id o_vout_view = [o_embedded_array objectAtIndex: i];
89 if( ![o_vout_view isUsed] )
91 [o_vout_view setUsed: YES];
98 - (void)releaseEmbeddedVout: (id)o_vout_view
100 if( [o_embedded_array containsObject: o_vout_view] )
102 [o_vout_view setUsed: NO];
106 msg_Warn( VLCIntf, "cannot find Video Output");
110 - (void)addEmbeddedVout: (id)o_vout_view
112 if( ![o_embedded_array containsObject: o_vout_view] )
114 [o_embedded_array addObject: o_vout_view];
118 - (BOOL)windowContainsEmbedded: (id)o_window
120 /* if( ![[o_window className] isEqualToString: @"VLCVoutWindow"] )
122 NSLog( @"We were not given a VLCVoutWindow" );
124 return ([self getViewForWindow: o_window] == nil ? NO : YES );
127 - (id)getViewForWindow: (id)o_window
129 if( o_embedded_array != nil )
131 id o_enumerator = [o_embedded_array objectEnumerator];
132 id o_current_embedded;
133 if( o_window != nil )
135 while( (o_current_embedded = [o_enumerator nextObject]) )
137 if( [o_current_embedded getWindow] == o_window )
139 return o_current_embedded;
149 /*****************************************************************************
150 * VLCVoutView implementation
151 *****************************************************************************/
152 @implementation VLCVoutView
154 - (id)initWithFrame: (NSRect)frameRect
156 self = [super initWithFrame: frameRect];
159 s_frame = &frameRect;
166 - (BOOL)setVout: (vout_thread_t *) vout
167 subView: (NSView *) view
168 frame: (NSRect *) frame
171 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
172 NSArray *o_screens = [NSScreen screens];
178 if( [o_screens count] <= 0 )
180 msg_Err( p_vout, "no OSX screens available" );
184 p_real_vout = [VLCVoutView getRealVout: p_vout];
186 /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */
187 if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 )
189 i_device = var_GetInteger( p_vout, "macosx-vdev" );
193 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
196 /* Setup the menuitem for the multiple displays. */
197 if( var_Type( p_real_vout, "video-device" ) == 0 )
200 vlc_value_t val2, text;
203 var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
205 text.psz_string = _("Fullscreen Video Device");
206 var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
208 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
211 text.psz_string = _("Default");
212 var_Change( p_real_vout, "video-device",
213 VLC_VAR_ADDCHOICE, &val2, &text );
214 var_Set( p_real_vout, "video-device", val2 );
216 while( (o_screen = [o_enumerator nextObject]) != NULL )
219 NSRect s_rect = [o_screen frame];
221 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
222 "%s %d (%dx%d)", _("Screen"), i,
223 (int)s_rect.size.width, (int)s_rect.size.height );
225 text.psz_string = psz_temp;
226 val2.i_int = (int)[o_screen displayID];
227 var_Change( p_real_vout, "video-device",
228 VLC_VAR_ADDCHOICE, &val2, &text );
229 if( (int)[o_screen displayID] == i_device )
231 var_Set( p_real_vout, "video-device", val2 );
236 var_AddCallback( p_real_vout, "video-device", DeviceCallback,
240 var_Set( p_real_vout, "intf-change", val2 );
243 /* Add the view. It's automatically resized to fit the window */
244 [self addSubview: o_view];
245 [self setAutoresizesSubviews: YES];
251 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize
253 [super resizeSubviewsWithOldSize: oldBoundsSize];
254 [o_view setFrameSize: [self frame].size];
257 - (void)drawRect:(NSRect)rect
259 /* When there is no subview we draw a black background */
261 [[NSColor blackColor] set];
268 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut];
270 /* Make sure we don't see a white flash */
271 [[self window] disableScreenUpdatesUntilFlush];
272 [o_view removeFromSuperview];
282 NSString * o_title = nil;
283 NSMutableString * o_mrl = nil;
284 input_thread_t * p_input;
287 if( !p_vout ) return;
289 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
291 if( !p_input ) return;
293 input_item_t * p_item = input_GetItem( p_input );
295 psz_title = input_item_GetNowPlaying ( p_item );
297 psz_title = input_item_GetName( p_item );
300 o_title = [NSString stringWithUTF8String: psz_title];
302 char *psz_uri = input_item_GetURI( p_item );
304 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
314 /* FIXME once psz_access is exported, we could check if we are
315 * reading from a file in a smarter way. */
317 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
318 if( prefix_range.location != NSNotFound )
319 [o_mrl deleteCharactersInRange: prefix_range];
321 if( [o_mrl characterAtIndex:0] == '/' )
323 /* it's a local file */
324 [o_window setRepresentedFilename: o_mrl];
328 /* it's from the network or somewhere else,
329 * we clear the previous path */
330 [o_window setRepresentedFilename: @""];
332 [o_window setTitle: o_title];
336 [o_window setTitle: [NSString stringWithUTF8String: VOUT_TITLE]];
338 vlc_object_release( p_input );
341 - (void)setOnTop:(BOOL)b_on_top
345 [o_window setLevel: NSStatusWindowLevel];
349 [o_window setLevel: NSNormalWindowLevel];
353 - (NSSize)voutSizeForFactor: (float)factor
355 int i_corrected_height, i_corrected_width;
358 if( p_vout->render.i_height * p_vout->render.i_aspect >
359 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
361 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
363 newsize.width = (int) ( i_corrected_width * factor );
364 newsize.height = (int) ( p_vout->render.i_height * factor );
368 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
369 p_vout->render.i_aspect;
370 newsize.width = (int) ( p_vout->render.i_width * factor );
371 newsize.height = (int) ( i_corrected_height * factor );
377 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
379 if ( !p_vout->b_fullscreen )
383 NSPoint topleftscreen;
387 topleftbase.y = [o_window frame].size.height;
388 topleftscreen = [o_window convertBaseToScreen: topleftbase];
390 newsize = [self voutSizeForFactor:factor];
392 /* In fullscreen mode we need to use a view that is different from
393 * ourselves, with the VLCEmbeddedWindow */
394 if([o_window isKindOfClass:[VLCEmbeddedWindow class]])
395 mainView = [o_window mainView];
399 /* Calculate the window's new size */
400 new_frame.size.width = [o_window frame].size.width -
401 [mainView frame].size.width + newsize.width;
402 new_frame.size.height = [o_window frame].size.height -
403 [mainView frame].size.height + newsize.height;
405 new_frame.origin.x = topleftscreen.x;
406 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
408 [o_window setFrame:new_frame display:animate animate:animate];
409 p_vout->i_changes |= VOUT_SIZE_CHANGE;
413 - (void)toggleFloatOnTop
417 if( !p_real_vout ) return;
418 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
426 var_Set( p_real_vout, "video-on-top", val );
429 - (void)toggleFullscreen
432 if( !p_real_vout ) return;
433 var_Get( p_real_vout, "fullscreen", &val );
434 val.b_bool = !val.b_bool;
435 var_Set( p_real_vout, "fullscreen", val );
441 if( !p_real_vout ) return NO;
442 var_Get( p_real_vout, "fullscreen", &val );
443 return( val.b_bool );
448 var_TriggerCallback( p_real_vout, "video-snapshot" );
453 /* Disable Screensaver, when we're playing something, but allow it on pause */
454 if( !VLCIntf || !VLCIntf->p_sys )
458 if( VLCIntf->p_sys->i_play_status == PLAYING_S )
459 UpdateSystemActivity( UsrActivity );
467 - (void)scrollWheel:(NSEvent *)theEvent
469 VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
470 [o_controls scrollWheel: theEvent];
473 - (void)keyDown:(NSEvent *)o_event
477 unsigned int i_pressed_modifiers = 0;
480 i_pressed_modifiers = [o_event modifierFlags];
482 if( i_pressed_modifiers & NSShiftKeyMask )
483 val.i_int |= KEY_MODIFIER_SHIFT;
484 if( i_pressed_modifiers & NSControlKeyMask )
485 val.i_int |= KEY_MODIFIER_CTRL;
486 if( i_pressed_modifiers & NSAlternateKeyMask )
487 val.i_int |= KEY_MODIFIER_ALT;
488 if( i_pressed_modifiers & NSCommandKeyMask )
489 val.i_int |= KEY_MODIFIER_COMMAND;
491 key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
495 /* Escape should always get you out of fullscreen */
496 if( key == (unichar) 0x1b )
498 if( p_real_vout && [self isFullscreen] )
500 [self toggleFullscreen];
506 val.i_int = config_GetInt( p_vout, "key-play-pause" );
508 val.i_int |= (int)CocoaKeyToVLC( key );
509 var_Set( p_vout->p_libvlc, "key-pressed", val );
511 else NSLog( @"Could not send keyevent to VLC core" );
514 [super keyDown: o_event];
517 - (void)mouseDown:(NSEvent *)o_event
522 if( ( [o_event type] == NSLeftMouseDown ) &&
523 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
525 if( [o_event clickCount] <= 1 )
527 /* single clicking */
528 var_Get( p_vout, "mouse-button-down", &val );
530 var_Set( p_vout, "mouse-button-down", val );
534 /* multiple clicking */
535 [self toggleFullscreen];
538 else if( ( [o_event type] == NSRightMouseDown ) ||
539 ( ( [o_event type] == NSLeftMouseDown ) &&
540 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
542 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
543 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] voutView]];
547 [super mouseDown: o_event];
550 - (void)otherMouseDown:(NSEvent *)o_event
554 if( p_vout && [o_event type] == NSOtherMouseDown )
556 var_Get( p_vout, "mouse-button-down", &val );
558 var_Set( p_vout, "mouse-button-down", val );
561 [super mouseDown: o_event];
564 - (void)rightMouseDown:(NSEvent *)o_event
566 if( p_vout && [o_event type] == NSRightMouseDown )
568 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
569 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] voutView]];
572 [super mouseDown: o_event];
575 - (void)mouseUp:(NSEvent *)o_event
579 if( p_vout && [o_event type] == NSLeftMouseUp )
581 var_SetBool( p_vout, "mouse-clicked", true );
583 var_Get( p_vout, "mouse-button-down", &val );
585 var_Set( p_vout, "mouse-button-down", val );
588 [super mouseUp: o_event];
591 - (void)otherMouseUp:(NSEvent *)o_event
595 if( p_vout && [o_event type] == NSOtherMouseUp )
597 var_Get( p_vout, "mouse-button-down", &val );
599 var_Set( p_vout, "mouse-button-down", val );
602 [super mouseUp: o_event];
605 - (void)rightMouseUp:(NSEvent *)o_event
607 if( p_vout && [o_event type] == NSRightMouseUp )
609 /* FIXME: this isn't the appropriate place, but we can't receive
610 * NSRightMouseDown some how */
611 msg_Dbg( p_vout, "received NSRightMouseUp" );
612 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] voutView]];
615 [super mouseUp: o_event];
618 - (void)mouseDragged:(NSEvent *)o_event
620 [self mouseMoved: o_event];
623 - (void)otherMouseDragged:(NSEvent *)o_event
625 [self mouseMoved: o_event];
628 - (void)rightMouseDragged:(NSEvent *)o_event
630 [self mouseMoved: o_event];
633 - (void)mouseMoved:(NSEvent *)o_event
641 s_rect = [o_view bounds];
642 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
643 b_inside = [o_view mouse: ml inRect: s_rect];
648 unsigned int i_width, i_height, i_x, i_y;
650 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
651 (unsigned int)s_rect.size.height,
652 &i_x, &i_y, &i_width, &i_height );
654 val.i_int = ( ((int)ml.x) - i_x ) *
655 p_vout->render.i_width / i_width;
656 var_Set( p_vout, "mouse-x", val );
658 if( [[o_view className] isEqualToString: @"VLCGLView"] )
660 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
661 p_vout->render.i_height / i_height;
665 val.i_int = ( ((int)ml.y) - i_y ) *
666 p_vout->render.i_height / i_height;
668 var_Set( p_vout, "mouse-y", val );
671 var_Set( p_vout, "mouse-moved", val );
673 if( [self isFullscreen] )
674 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
677 [super mouseMoved: o_event];
680 - (BOOL)acceptsFirstResponder
685 - (BOOL)becomeFirstResponder
690 - (BOOL)resignFirstResponder
692 /* We need to stay the first responder or we'll miss some
697 /* Class methods used by the different vout modules */
699 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
701 /* p_real_vout: the vout we have to use to check for video-on-top
702 and a few other things. If we are the QuickTime output, it's us.
703 It we are the OpenGL provider, it is our parent.
704 Since we can't be the QuickTime output anymore, we need to be
706 FIXME: check with the caca and x11 vouts! */
707 return (vout_thread_t *) p_vout->p_parent;
710 + (id)voutView: (vout_thread_t *)p_vout subView: (NSView *)view
711 frame: (NSRect *)s_frame
717 i_drawable_gl = var_GetInteger( p_vout->p_libvlc, "drawable-gl" );
719 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
720 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
721 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
722 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
723 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
724 var_Create( p_vout, "embedded-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
726 /* We only wait for NSApp to initialise if we're not embedded (as in the
727 * case of the Mozilla plugin). We can tell whether we're embedded or not
728 * by examining the "drawable-gl" value: if it's zero, we're running in the
729 * main Mac intf; if it's non-zero, we're embedded. */
730 if( i_drawable_gl == 0 )
732 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
733 for( i_timeout = 20 ; i_timeout-- ; )
737 msleep( INTF_IDLE_SLEEP );
743 /* No MacOS X intf, unable to communicate with MT */
744 msg_Err( p_vout, "no MacOS X interface present" );
749 if ( VLCIntf && !(p_vout->b_fullscreen) &&
750 !(var_GetBool( p_vout, "macosx-background" )) &&
751 var_GetBool( p_vout, "embedded-video") )
753 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
759 /* No embedded vout is available */
760 if( o_return == nil )
763 bzero( &null_rect, sizeof( NSRect ) );
764 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
766 [o_return setVout: p_vout subView: view frame: s_frame];
770 - (void)enterFullscreen
772 /* Save the settings for next playing item */
773 playlist_t * p_playlist = pl_Hold( p_real_vout );
774 var_SetBool( p_playlist, "fullscreen", true );
775 pl_Release( p_real_vout );
778 - (void)leaveFullscreen
780 /* Save the settings for next playing item */
781 playlist_t * p_playlist = pl_Hold( p_real_vout );
782 var_SetBool( p_playlist, "fullscreen", false );
783 pl_Release( p_real_vout );
788 /*****************************************************************************
789 * VLCDetachedVoutView implementation
790 *****************************************************************************/
791 @implementation VLCDetachedVoutView
793 - (id)initWithFrame: (NSRect)frameRect
795 [super initWithFrame: frameRect];
796 i_time_mouse_last_moved = 0;
800 - (BOOL)mouseDownCanMoveWindow
805 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
806 frame: (NSRect *) s_arg_frame
808 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
809 i_time_mouse_last_moved = mdate();
810 o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self
814 if([self isFullscreen])
815 [o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
817 [view setFrame: [self frame]];
824 [o_window performSelectorOnMainThread: @selector(close) withObject: NULL waitUntilDone: YES];
825 i_time_mouse_last_moved = 0;
829 - (void)mouseMoved:(NSEvent *)o_event
831 i_time_mouse_last_moved = mdate();
832 [super mouseMoved: o_event];
835 - (void)hideMouse:(BOOL)b_hide
839 NSView *o_contents = [o_window contentView];
841 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
842 ml = [o_contents convertPoint:ml fromView:nil];
843 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
845 if( b_hide && b_inside )
847 [NSCursor setHiddenUntilMouseMoves: YES];
851 [NSCursor setHiddenUntilMouseMoves: NO];
857 /* Dooh, why do we spend processor time doing this kind of stuff? */
859 unsigned int i_mouse_hide_timeout =
860 var_CreateGetInteger(p_vout, "mouse-hide-timeout") * 1000;
862 if( i_mouse_hide_timeout < 100000 )
863 i_mouse_hide_timeout = 100000;
864 if( p_vout->b_fullscreen )
866 if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout )
868 i_time_mouse_last_moved = mdate();
869 [self hideMouse: YES];
874 [self hideMouse: NO];
879 - (void)enterFullscreen
881 [o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: NO];
882 [super enterFullscreen];
886 - (void)leaveFullscreen
888 [o_window performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: NO];
889 [super leaveFullscreen];
893 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
895 if( p_vout->b_fullscreen )
897 [o_window setMovableByWindowBackground: NO];
898 [super scaleWindowWithFactor: factor animate: animate];
899 [o_window setMovableByWindowBackground: YES];
903 /*****************************************************************************
904 * VLCEmbeddedVoutView implementation
905 *****************************************************************************/
907 @implementation VLCEmbeddedVoutView
911 o_embeddedwindow = [self window];
914 - (BOOL)mouseDownCanMoveWindow
919 - (id)initWithFrame: (NSRect)frameRect
921 if(self = [super initWithFrame: frameRect])
924 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
925 o_embeddedwindow = nil; /* Filled later on in -awakeFromNib */
930 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
931 frame: (NSRect *)s_arg_frame
935 [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
937 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
940 o_window = [self window];
942 [o_window setAcceptsMouseMovedEvents: TRUE];
944 if( var_CreateGetBool( p_real_vout, "video-on-top" ) )
946 [o_window setLevel: NSStatusWindowLevel];
949 [view setFrameSize: [self frame].size];
952 /* o_window needs to point to our o_embeddedwindow, super might have set it
953 * to the fullscreen window that o_embeddedwindow setups during fullscreen */
954 o_window = o_embeddedwindow;
958 [o_window lockFullscreenAnimation];
960 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
964 [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
966 /* Make the window the front and key window before animating */
967 if ([o_window isVisible] && (![o_window isFullscreen]))
968 [o_window makeKeyAndOrderFront: self];
970 [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
972 [o_embeddedwindow setVideoRatio:[self voutSizeForFactor:1.0]];
974 /* Make sure our window is visible, if we are not in fullscreen */
975 if (![o_window isFullscreen])
976 [o_window makeKeyAndOrderFront: self];
977 [o_window unlockFullscreenAnimation];
984 - (void)setUsed: (BOOL)b_new_used
998 /* Don't close the window yet, wait a bit to see if a new input is poping up */
999 /* FIXME: Probably fade the window In and Out */
1000 /* FIXME: fix core */
1001 [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:3.];
1003 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
1006 - (void)enterFullscreen
1009 [super enterFullscreen];
1011 /* We are in a VLCEmbeddedWindow */
1012 [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
1015 - (void)leaveFullscreen
1018 [super leaveFullscreen];
1020 /* We are in a VLCEmbeddedWindow */
1021 [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
1025 /*****************************************************************************
1026 * VLCVoutWindow implementation
1027 *****************************************************************************/
1028 @implementation VLCVoutWindow
1030 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
1031 frame: (NSRect *) frame
1037 [self performSelectorOnMainThread: @selector(initMainThread:)
1038 withObject: NULL waitUntilDone: YES];
1040 return b_init_ok ? self : nil;
1043 - (id)initMainThread: (id) sender
1046 rect.size.height = p_vout->i_window_height;
1047 rect.size.width = p_vout->i_window_width;
1048 rect.origin.x = rect.origin.y = 70.;
1050 if( self = [super initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])
1052 [self setBackgroundColor:[NSColor blackColor]];
1053 [self setHasShadow:YES];
1054 [self setMovableByWindowBackground: YES];
1056 [self makeKeyAndOrderFront: self];
1057 [self setReleasedWhenClosed: YES];
1058 [self setFrameUsingName:@"VLCVoutWindowDetached"];
1059 [self setFrameAutosaveName:@"VLCVoutWindowDetached"];
1061 /* We'll catch mouse events */
1062 [self makeFirstResponder: o_view];
1063 [self setCanBecomeKeyWindow: YES];
1064 [self setAcceptsMouseMovedEvents: YES];
1065 [self setIgnoresMouseEvents: NO];
1067 if( var_CreateGetBool( p_vout, "macosx-background" ) )
1069 int i_device = var_GetInteger( p_vout->p_libvlc, "video-device" );
1071 /* Find out on which screen to open the window */
1072 NSScreen * screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1073 if( !screen ) screen = [NSScreen mainScreen];
1075 NSRect screen_rect = [screen frame];
1076 screen_rect.origin.x = screen_rect.origin.y = 0;
1078 /* Creates a window with size: screen_rect on o_screen */
1079 [self setFrame: screen_rect display: NO];
1081 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1082 [self setMovableByWindowBackground: NO];
1084 if( var_CreateGetBool( p_vout, "video-on-top" ) )
1086 [self setLevel: NSStatusWindowLevel];
1089 [self setAlphaValue: var_CreateGetFloat( p_vout, "macosx-opaqueness" )];
1091 /* Add the view. It's automatically resized to fit the window */
1092 [self setContentView: o_view];
1099 - (void)enterFullscreen
1101 if( fullscreen ) return;
1107 i_device = var_GetInteger( p_vout->p_libvlc, "video-device" );
1108 b_black = var_CreateGetBool( p_vout, "macosx-black" );
1110 /* Find out on which screen to open the window */
1111 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1112 if( !screen ) screen = [self screen];
1115 [screen blackoutOtherScreens];
1117 [self setMovableByWindowBackground: NO];
1119 if( [screen isMainScreen] )
1120 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1122 initialFrame = [self frame];
1123 [self setFrame:[screen frame] display:YES animate:YES];
1124 [self setLevel:NSNormalWindowLevel];
1126 /* tell the fspanel to move itself to front next time it's triggered */
1127 [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
1128 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
1133 - (void)leaveFullscreen
1135 if( !fullscreen ) return;
1138 [NSScreen unblackoutScreens];
1140 [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
1141 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
1142 [self setFrame:initialFrame display:YES animate:YES];
1143 [self setMovableByWindowBackground: YES];
1144 if( var_GetBool( p_vout, "video-on-top" ) )
1145 [self setLevel: NSStatusWindowLevel];