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 <stdlib.h> /* free() */
36 /* prevent system sleep */
37 #import <CoreServices/CoreServices.h>
40 #import <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h>
44 #import <Carbon/Carbon.h>
51 #import "embeddedwindow.h"
53 #include <vlc_common.h>
56 /*****************************************************************************
57 * DeviceCallback: Callback triggered when the video-device variable is changed
58 *****************************************************************************/
59 int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
60 vlc_value_t old_val, vlc_value_t new_val, void *param )
63 vout_thread_t *p_vout = (vout_thread_t *)p_this;
65 msg_Dbg( p_vout, "set %d", new_val.i_int );
66 var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
67 var_Set( p_vout->p_libvlc, "video-device", new_val );
70 var_Set( p_vout, "intf-change", val );
75 /*****************************************************************************
76 * VLCEmbeddedList implementation
77 *****************************************************************************/
78 @implementation VLCEmbeddedList
83 o_embedded_array = [NSMutableArray array];
91 for( i = 0; i < [o_embedded_array count]; i++ )
93 id o_vout_view = [o_embedded_array objectAtIndex: i];
94 if( ![o_vout_view isUsed] )
96 [o_vout_view setUsed: YES];
103 - (void)releaseEmbeddedVout: (id)o_vout_view
105 if( [o_embedded_array containsObject: o_vout_view] )
107 [o_vout_view setUsed: NO];
111 msg_Warn( VLCIntf, "cannot find Video Output");
115 - (void)addEmbeddedVout: (id)o_vout_view
117 if( ![o_embedded_array containsObject: o_vout_view] )
119 [o_embedded_array addObject: o_vout_view];
123 - (BOOL)windowContainsEmbedded: (id)o_window
125 /* if( ![[o_window className] isEqualToString: @"VLCVoutWindow"] )
127 NSLog( @"We were not given a VLCVoutWindow" );
129 return ([self viewForWindow: o_window] == nil ? NO : YES );
132 - (id)viewForWindow: (id)o_window
134 if( o_embedded_array != nil )
136 id o_enumerator = [o_embedded_array objectEnumerator];
137 id o_current_embedded;
138 if( o_window != nil )
140 while( (o_current_embedded = [o_enumerator nextObject]) )
142 if( [o_current_embedded voutWindow] == o_window )
144 return o_current_embedded;
154 /*****************************************************************************
155 * VLCVoutView implementation
156 *****************************************************************************/
157 @implementation VLCVoutView
159 - (id)initWithFrame: (NSRect)frameRect
161 self = [super initWithFrame: frameRect];
164 s_frame = &frameRect;
171 - (BOOL)setVout: (vout_thread_t *) vout
172 subView: (NSView *) view
173 frame: (NSRect *) frame
176 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
177 NSArray *o_screens = [NSScreen screens];
183 if( [o_screens count] <= 0 )
185 msg_Err( p_vout, "no OSX screens available" );
189 p_real_vout = [VLCVoutView realVout: p_vout];
191 /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */
192 if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 )
194 i_device = var_GetInteger( p_vout, "macosx-vdev" );
198 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
201 /* Setup the menuitem for the multiple displays. */
202 if( var_Type( p_real_vout, "video-device" ) == 0 )
205 vlc_value_t val2, text;
208 var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
210 text.psz_string = _("Fullscreen Video Device");
211 var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
213 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
216 text.psz_string = _("Default");
217 var_Change( p_real_vout, "video-device",
218 VLC_VAR_ADDCHOICE, &val2, &text );
219 var_Set( p_real_vout, "video-device", val2 );
221 while( (o_screen = [o_enumerator nextObject]) != NULL )
224 NSRect s_rect = [o_screen frame];
226 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
227 "%s %d (%dx%d)", _("Screen"), i,
228 (int)s_rect.size.width, (int)s_rect.size.height );
230 text.psz_string = psz_temp;
231 val2.i_int = (int)[o_screen displayID];
232 var_Change( p_real_vout, "video-device",
233 VLC_VAR_ADDCHOICE, &val2, &text );
234 if( (int)[o_screen displayID] == i_device )
236 var_Set( p_real_vout, "video-device", val2 );
241 var_AddCallback( p_real_vout, "video-device", DeviceCallback,
245 var_Set( p_real_vout, "intf-change", val2 );
248 /* Add the view. It's automatically resized to fit the window */
249 [self addSubview: o_view];
250 [self setAutoresizesSubviews: YES];
256 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize
258 [super resizeSubviewsWithOldSize: oldBoundsSize];
259 [o_view setFrameSize: [self frame].size];
262 - (void)drawRect:(NSRect)rect
264 /* When there is no subview we draw a black background */
266 [[NSColor blackColor] set];
273 [[[[VLCMain sharedInstance] controls] fspanel] fadeOut];
275 /* Make sure we don't see a white flash */
276 [[self voutWindow] disableScreenUpdatesUntilFlush];
277 [o_view removeFromSuperview];
287 NSString * o_title = nil;
288 NSMutableString * o_mrl = nil;
289 input_thread_t * p_input;
292 if( !p_vout ) return;
294 p_input = getInput();
296 if( !p_input ) return;
298 input_item_t * p_item = input_GetItem( p_input );
300 psz_title = input_item_GetNowPlaying ( p_item );
302 psz_title = input_item_GetName( p_item );
305 o_title = [NSString stringWithUTF8String: psz_title];
307 char *psz_uri = input_item_GetURI( p_item );
309 o_mrl = [NSMutableString stringWithUTF8String: psz_uri];
319 /* FIXME once psz_access is exported, we could check if we are
320 * reading from a file in a smarter way. */
322 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
323 if( prefix_range.location != NSNotFound )
324 [o_mrl deleteCharactersInRange: prefix_range];
326 if( [o_mrl characterAtIndex:0] == '/' )
328 /* it's a local file */
329 [o_window setRepresentedFilename: o_mrl];
333 /* it's from the network or somewhere else,
334 * we clear the previous path */
335 [o_window setRepresentedFilename: @""];
337 [o_window setTitle: o_title];
341 [o_window setTitle: [NSString stringWithUTF8String: VOUT_TITLE]];
343 vlc_object_release( p_input );
346 - (void)setOnTop:(BOOL)b_on_top
350 [o_window setLevel: NSStatusWindowLevel];
354 [o_window setLevel: NSNormalWindowLevel];
358 - (NSSize)voutSizeForFactor: (float)factor
360 int i_corrected_height, i_corrected_width;
363 if( p_vout->render.i_height * p_vout->render.i_aspect >
364 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
366 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
368 newsize.width = (int) ( i_corrected_width * factor );
369 newsize.height = (int) ( p_vout->render.i_height * factor );
373 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
374 p_vout->render.i_aspect;
375 newsize.width = (int) ( p_vout->render.i_width * factor );
376 newsize.height = (int) ( i_corrected_height * factor );
382 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
384 if ( !p_vout->b_fullscreen )
388 NSPoint topleftscreen;
392 topleftbase.y = [o_window frame].size.height;
393 topleftscreen = [o_window convertBaseToScreen: topleftbase];
395 newsize = [self voutSizeForFactor:factor];
397 /* In fullscreen mode we need to use a view that is different from
398 * ourselves, with the VLCEmbeddedWindow */
399 if([o_window isKindOfClass:[VLCEmbeddedWindow class]])
400 mainView = [o_window mainView];
404 /* Calculate the window's new size */
405 new_frame.size.width = [o_window frame].size.width -
406 [mainView frame].size.width + newsize.width;
407 new_frame.size.height = [o_window frame].size.height -
408 [mainView frame].size.height + newsize.height;
410 new_frame.origin.x = topleftscreen.x;
411 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
413 [o_window setFrame:new_frame display:animate animate:animate];
414 p_vout->i_changes |= VOUT_SIZE_CHANGE;
418 - (void)toggleFloatOnTop
422 if( !p_real_vout ) return;
423 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
431 var_Set( p_real_vout, "video-on-top", val );
434 - (void)toggleFullscreen
437 if( !p_real_vout ) return;
438 var_ToggleBool( p_real_vout, "fullscreen" );
444 if( !p_real_vout ) return NO;
445 var_Get( p_real_vout, "fullscreen", &val );
446 return( val.b_bool );
451 var_TriggerCallback( p_real_vout, "video-snapshot" );
456 /* Disable Screensaver, when we're playing something, but allow it on pause */
457 if( !VLCIntf || !VLCIntf->p_sys )
460 if( VLCIntf->p_sys->i_play_status == PLAYING_S )
461 UpdateSystemActivity( UsrActivity );
469 - (void)scrollWheel:(NSEvent *)theEvent
471 VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls];
472 [o_controls scrollWheel: theEvent];
475 - (void)keyDown:(NSEvent *)o_event
479 unsigned int i_pressed_modifiers = 0;
482 i_pressed_modifiers = [o_event modifierFlags];
484 if( i_pressed_modifiers & NSShiftKeyMask )
485 val.i_int |= KEY_MODIFIER_SHIFT;
486 if( i_pressed_modifiers & NSControlKeyMask )
487 val.i_int |= KEY_MODIFIER_CTRL;
488 if( i_pressed_modifiers & NSAlternateKeyMask )
489 val.i_int |= KEY_MODIFIER_ALT;
490 if( i_pressed_modifiers & NSCommandKeyMask )
491 val.i_int |= KEY_MODIFIER_COMMAND;
493 key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
497 /* Escape should always get you out of fullscreen */
498 if( key == (unichar) 0x1b )
500 if( p_real_vout && [self isFullscreen] )
502 [self toggleFullscreen];
508 val.i_int = config_GetInt( p_vout, "key-play-pause" );
510 val.i_int |= (int)CocoaKeyToVLC( key );
511 var_Set( p_vout->p_libvlc, "key-pressed", val );
513 else NSLog( @"Could not send keyevent to VLC core" );
516 [super keyDown: o_event];
519 - (void)mouseDown:(NSEvent *)o_event
524 if( ( [o_event type] == NSLeftMouseDown ) &&
525 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
527 if( [o_event clickCount] <= 1 )
529 /* single clicking */
530 var_Get( p_vout, "mouse-button-down", &val );
532 var_Set( p_vout, "mouse-button-down", val );
536 /* multiple clicking */
537 [self toggleFullscreen];
540 else if( ( [o_event type] == NSRightMouseDown ) ||
541 ( ( [o_event type] == NSLeftMouseDown ) &&
542 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
544 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
545 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]];
549 [super mouseDown: o_event];
552 - (void)otherMouseDown:(NSEvent *)o_event
556 if( p_vout && [o_event type] == NSOtherMouseDown )
558 var_Get( p_vout, "mouse-button-down", &val );
560 var_Set( p_vout, "mouse-button-down", val );
563 [super mouseDown: o_event];
566 - (void)rightMouseDown:(NSEvent *)o_event
568 if( p_vout && [o_event type] == NSRightMouseDown )
570 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
571 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]];
574 [super mouseDown: o_event];
577 - (void)mouseUp:(NSEvent *)o_event
581 if( p_vout && [o_event type] == NSLeftMouseUp )
585 var_GetCoords( p_vout, "mouse-moved", &x, &y );
586 var_SetCoords( p_vout, "mouse-clicked", x, y );
588 var_Get( p_vout, "mouse-button-down", &val );
590 var_Set( p_vout, "mouse-button-down", val );
593 [super mouseUp: o_event];
596 - (void)otherMouseUp:(NSEvent *)o_event
600 if( p_vout && [o_event type] == NSOtherMouseUp )
602 var_Get( p_vout, "mouse-button-down", &val );
604 var_Set( p_vout, "mouse-button-down", val );
607 [super mouseUp: o_event];
610 - (void)rightMouseUp:(NSEvent *)o_event
612 if( p_vout && [o_event type] == NSRightMouseUp )
614 /* FIXME: this isn't the appropriate place, but we can't receive
615 * NSRightMouseDown some how */
616 msg_Dbg( p_vout, "received NSRightMouseUp" );
617 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]];
620 [super mouseUp: o_event];
623 - (void)mouseDragged:(NSEvent *)o_event
625 [self mouseMoved: o_event];
628 - (void)otherMouseDragged:(NSEvent *)o_event
630 [self mouseMoved: o_event];
633 - (void)rightMouseDragged:(NSEvent *)o_event
635 [self mouseMoved: o_event];
638 - (void)mouseMoved:(NSEvent *)o_event
646 s_rect = [o_view bounds];
647 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
648 b_inside = [o_view mouse: ml inRect: s_rect];
653 unsigned int i_width, i_height, i_x, i_y;
655 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
656 (unsigned int)s_rect.size.height,
657 &i_x, &i_y, &i_width, &i_height );
659 x = (((int)ml.x) - i_x) * p_vout->render.i_width / i_width;
660 if( [[o_view className] isEqualToString: @"VLCGLView"] )
662 y = (((int)(s_rect.size.height - ml.y)) - i_y) *
663 p_vout->render.i_height / i_height;
667 y = (((int)ml.y) - i_y) * p_vout->render.i_height / i_height;
669 var_SetCoords( p_vout, "mouse-moved", x, y );
671 if( [self isFullscreen] )
672 [[[[VLCMain sharedInstance] controls] fspanel] fadeIn];
675 [super mouseMoved: o_event];
678 - (BOOL)acceptsFirstResponder
683 - (BOOL)becomeFirstResponder
688 - (BOOL)resignFirstResponder
690 /* We need to stay the first responder or we'll miss some
695 /* Class methods used by the different vout modules */
697 + (vout_thread_t *)realVout: (vout_thread_t *)p_vout
699 /* p_real_vout: the vout we have to use to check for video-on-top
700 and a few other things. If we are the QuickTime output, it's us.
701 It we are the OpenGL provider, it is our parent.
702 Since we can't be the QuickTime output anymore, we need to be
704 FIXME: check with the caca and x11 vouts! */
705 return (vout_thread_t *) p_vout->p_parent;
708 + (id)voutView: (vout_thread_t *)p_vout subView: (NSView *)view
709 frame: (NSRect *)s_frame
715 i_drawable_gl = var_GetInteger( p_vout->p_libvlc, "drawable-gl" );
717 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
718 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
719 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
720 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
721 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
722 var_Create( p_vout, "embedded-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
724 /* We only wait for NSApp to initialise if we're not embedded (as in the
725 * case of the Mozilla plugin). We can tell whether we're embedded or not
726 * by examining the "drawable-gl" value: if it's zero, we're running in the
727 * main Mac intf; if it's non-zero, we're embedded. */
728 if( i_drawable_gl == 0 )
730 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
731 for( i_timeout = 20 ; i_timeout-- ; )
735 msleep( INTF_IDLE_SLEEP );
741 /* No MacOS X intf, unable to communicate with MT */
742 msg_Err( p_vout, "no MacOS X interface present" );
747 if ( VLCIntf && !(p_vout->b_fullscreen) &&
748 !(var_GetBool( p_vout, "macosx-background" )) &&
749 var_GetBool( p_vout, "embedded-video") )
751 o_return = [[[VLCMain sharedInstance] embeddedList] embeddedVout];
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_Get( p_real_vout );
771 var_SetBool( p_playlist, "fullscreen", true );
774 - (void)leaveFullscreen
776 /* Save the settings for next playing item */
777 playlist_t * p_playlist = pl_Get( p_real_vout );
778 var_SetBool( p_playlist, "fullscreen", false );
783 /*****************************************************************************
784 * VLCDetachedVoutView implementation
785 *****************************************************************************/
786 @implementation VLCDetachedVoutView
788 - (id)initWithFrame: (NSRect)frameRect
790 [super initWithFrame: frameRect];
791 i_time_mouse_last_moved = 0;
795 - (BOOL)mouseDownCanMoveWindow
800 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
801 frame: (NSRect *) s_arg_frame
803 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
804 i_time_mouse_last_moved = mdate();
805 o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self
809 if([self isFullscreen])
810 [o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
812 [view setFrame: [self frame]];
819 [o_window performSelectorOnMainThread: @selector(close) withObject: NULL waitUntilDone: YES];
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];
852 /* Dooh, why do we spend processor time doing this kind of stuff? */
854 unsigned int i_mouse_hide_timeout =
855 var_CreateGetInteger(p_vout, "mouse-hide-timeout") * 1000;
857 if( i_mouse_hide_timeout < 100000 )
858 i_mouse_hide_timeout = 100000;
859 if( p_vout->b_fullscreen )
861 if( mdate() - i_time_mouse_last_moved > i_mouse_hide_timeout )
863 i_time_mouse_last_moved = mdate();
864 [self hideMouse: YES];
869 [self hideMouse: NO];
874 - (void)enterFullscreen
876 [o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: NO];
877 [super enterFullscreen];
881 - (void)leaveFullscreen
883 [o_window performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: NO];
884 [super leaveFullscreen];
888 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
890 if( p_vout->b_fullscreen )
892 [o_window setMovableByWindowBackground: NO];
893 [super scaleWindowWithFactor: factor animate: animate];
894 [o_window setMovableByWindowBackground: YES];
898 /*****************************************************************************
899 * VLCEmbeddedVoutView implementation
900 *****************************************************************************/
902 @implementation VLCEmbeddedVoutView
906 o_embeddedwindow = [self window];
909 - (BOOL)mouseDownCanMoveWindow
914 - (id)initWithFrame: (NSRect)frameRect
916 if(self = [super initWithFrame: frameRect])
919 [[[VLCMain sharedInstance] embeddedList] addEmbeddedVout: self];
920 o_embeddedwindow = nil; /* Filled later on in -awakeFromNib */
925 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
926 frame: (NSRect *)s_arg_frame
930 [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
932 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
935 o_window = [self window];
937 [o_window setAcceptsMouseMovedEvents: TRUE];
939 if( var_CreateGetBool( p_real_vout, "video-on-top" ) )
941 [o_window setLevel: NSStatusWindowLevel];
944 [view setFrameSize: [self frame].size];
947 /* o_window needs to point to our o_embeddedwindow, super might have set it
948 * to the fullscreen window that o_embeddedwindow setups during fullscreen */
949 o_window = o_embeddedwindow;
953 [o_window lockFullscreenAnimation];
955 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
959 [NSObject cancelPreviousPerformRequestsWithTarget:o_window];
961 /* Make the window the front and key window before animating */
962 if ([o_window isVisible] && (![o_window isFullscreen]))
963 [o_window makeKeyAndOrderFront: self];
965 [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
967 [o_embeddedwindow setVideoRatio:[self voutSizeForFactor:1.0]];
969 /* Make sure our window is visible, if we are not in fullscreen */
970 if (![o_window isFullscreen])
971 [o_window makeKeyAndOrderFront: self];
972 [o_window unlockFullscreenAnimation];
979 - (void)setUsed: (BOOL)b_new_used
993 /* Don't close the window yet, wait a bit to see if a new input is poping up */
994 /* FIXME: Probably fade the window In and Out */
995 /* FIXME: fix core */
996 [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:3.];
998 [[[VLCMain sharedInstance] embeddedList] releaseEmbeddedVout: self];
1001 - (void)enterFullscreen
1004 [super enterFullscreen];
1006 /* We are in a VLCEmbeddedWindow */
1007 [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
1010 - (void)leaveFullscreen
1013 [super leaveFullscreen];
1015 /* We are in a VLCEmbeddedWindow */
1016 [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
1020 /*****************************************************************************
1021 * VLCVoutWindow implementation
1022 *****************************************************************************/
1023 @implementation VLCVoutWindow
1025 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
1026 frame: (NSRect *) frame
1032 [self performSelectorOnMainThread: @selector(initMainThread:)
1033 withObject: NULL waitUntilDone: YES];
1035 return b_init_ok ? self : nil;
1038 - (id)initMainThread: (id) sender
1041 rect.size.height = p_vout->i_window_height;
1042 rect.size.width = p_vout->i_window_width;
1043 rect.origin.x = rect.origin.y = 70.;
1045 if( self = [super initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])
1047 [self setBackgroundColor:[NSColor blackColor]];
1048 [self setHasShadow:YES];
1049 [self setMovableByWindowBackground: YES];
1051 [self makeKeyAndOrderFront: self];
1052 [self setReleasedWhenClosed: YES];
1053 [self setFrameUsingName:@"VLCVoutWindowDetached"];
1054 [self setFrameAutosaveName:@"VLCVoutWindowDetached"];
1056 /* We'll catch mouse events */
1057 [self makeFirstResponder: o_view];
1058 [self setCanBecomeKeyWindow: YES];
1059 [self setAcceptsMouseMovedEvents: YES];
1060 [self setIgnoresMouseEvents: NO];
1062 if( var_CreateGetBool( p_vout, "macosx-background" ) )
1064 int i_device = var_GetInteger( p_vout->p_libvlc, "video-device" );
1066 /* Find out on which screen to open the window */
1067 NSScreen * screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1068 if( !screen ) screen = [NSScreen mainScreen];
1070 NSRect screen_rect = [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 setFrame: screen_rect display: NO];
1076 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1077 [self setMovableByWindowBackground: NO];
1079 if( var_CreateGetBool( p_vout, "video-on-top" ) )
1081 [self setLevel: NSStatusWindowLevel];
1084 [self setAlphaValue: var_CreateGetFloat( p_vout, "macosx-opaqueness" )];
1086 /* Add the view. It's automatically resized to fit the window */
1087 [self setContentView: o_view];
1094 - (void)enterFullscreen
1096 if( fullscreen ) return;
1102 i_device = var_GetInteger( p_vout->p_libvlc, "video-device" );
1103 b_black = var_CreateGetBool( p_vout, "macosx-black" );
1105 /* Find out on which screen to open the window */
1106 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
1107 if( !screen ) screen = [self screen];
1110 [screen blackoutOtherScreens];
1112 [self setMovableByWindowBackground: NO];
1114 if( [screen isMainScreen] )
1115 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1117 initialFrame = [self frame];
1118 [self setFrame:[screen frame] display:YES animate:YES];
1119 [self setLevel:NSNormalWindowLevel];
1121 /* tell the fspanel to move itself to front next time it's triggered */
1122 [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: i_device];
1123 [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil];
1128 - (void)leaveFullscreen
1130 if( !fullscreen ) return;
1133 [NSScreen unblackoutScreens];
1135 [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
1136 SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
1138 [self setFrame:initialFrame display:YES animate:YES];
1139 [self setMovableByWindowBackground: YES];
1140 if( var_GetBool( p_vout, "video-on-top" ) )
1141 [self setLevel: NSStatusWindowLevel];