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;
218 var_Change( p_real_vout, "video-device",
219 VLC_VAR_ADDCHOICE, &val2, &text );
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];
250 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut];
252 [o_view removeFromSuperview];
262 NSMutableString * o_title = nil, * o_mrl = nil;
263 input_thread_t * p_input;
270 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
272 if( p_input == NULL )
277 if( input_GetItem(p_input)->psz_name != NULL )
278 o_title = [NSMutableString stringWithUTF8String:
279 input_GetItem(p_input)->psz_name];
280 if( input_GetItem(p_input)->psz_uri != NULL )
281 o_mrl = [NSMutableString stringWithUTF8String:
282 input_GetItem(p_input)->psz_uri];
288 /* FIXME once psz_access is exported, we could check if we are
289 * reading from a file in a smarter way. */
291 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
292 if( prefix_range.location != NSNotFound )
293 [o_mrl deleteCharactersInRange: prefix_range];
295 if( [o_mrl characterAtIndex:0] == '/' )
297 /* it's a local file */
298 [o_window setRepresentedFilename: o_mrl];
302 /* it's from the network or somewhere else,
303 * we clear the previous path */
304 [o_window setRepresentedFilename: @""];
306 [o_window setTitle: o_title];
310 [o_window setTitle: [NSString stringWithCString: VOUT_TITLE]];
312 vlc_object_release( p_input );
316 - (void)setOnTop:(BOOL)b_on_top
320 [o_window setLevel: NSStatusWindowLevel];
324 [o_window setLevel: NSNormalWindowLevel];
328 - (void)scaleWindowWithFactor: (float)factor animate: (BOOL)animate
331 int i_corrected_height, i_corrected_width;
333 NSPoint topleftscreen;
335 if ( !p_vout->b_fullscreen )
339 topleftbase.y = [o_window frame].size.height;
340 topleftscreen = [o_window convertBaseToScreen: topleftbase];
342 if( p_vout->render.i_height * p_vout->render.i_aspect >
343 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
345 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
347 newsize.width = (int) ( i_corrected_width * factor );
348 newsize.height = (int) ( p_vout->render.i_height * factor );
352 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
353 p_vout->render.i_aspect;
354 newsize.width = (int) ( p_vout->render.i_width * factor );
355 newsize.height = (int) ( i_corrected_height * factor );
358 /* Calculate the window's new size */
359 new_frame.size.width = [o_window frame].size.width -
360 [self frame].size.width + newsize.width;
361 new_frame.size.height = [o_window frame].size.height -
362 [self frame].size.height + newsize.height;
364 new_frame.origin.x = topleftscreen.x;
365 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
367 [o_window setFrame: new_frame display: animate animate: animate];
369 p_vout->i_changes |= VOUT_SIZE_CHANGE;
373 - (void)toggleFloatOnTop
377 if( !p_real_vout ) return;
378 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
380 val.b_bool = VLC_FALSE;
384 val.b_bool = VLC_TRUE;
386 var_Set( p_real_vout, "video-on-top", val );
389 - (void)toggleFullscreen
392 if( !p_real_vout ) return;
393 var_Get( p_real_vout, "fullscreen", &val );
394 val.b_bool = !val.b_bool;
395 var_Set( p_real_vout, "fullscreen", val );
401 var_Get( p_real_vout, "fullscreen", &val );
402 return( val.b_bool );
407 vout_Control( p_real_vout, VOUT_SNAPSHOT );
412 /* Disable Screensaver, when we're playing something, but allow it on pause */
413 if( VLCIntf->p_sys->i_play_status == PLAYING_S )
414 UpdateSystemActivity( UsrActivity );
422 - (void)keyDown:(NSEvent *)o_event
426 unsigned int i_pressed_modifiers = 0;
429 i_pressed_modifiers = [o_event modifierFlags];
431 if( i_pressed_modifiers & NSShiftKeyMask )
432 val.i_int |= KEY_MODIFIER_SHIFT;
433 if( i_pressed_modifiers & NSControlKeyMask )
434 val.i_int |= KEY_MODIFIER_CTRL;
435 if( i_pressed_modifiers & NSAlternateKeyMask )
436 val.i_int |= KEY_MODIFIER_ALT;
437 if( i_pressed_modifiers & NSCommandKeyMask )
438 val.i_int |= KEY_MODIFIER_COMMAND;
440 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
444 /* Escape should always get you out of fullscreen */
445 if( key == (unichar) 0x1b )
447 if( p_real_vout && [self isFullscreen] )
449 [self toggleFullscreen];
452 else if ( key == ' ' )
455 val.i_int = config_GetInt( p_vout, "key-play-pause" );
456 var_Set( p_vout->p_libvlc, "key-pressed", val );
460 val.i_int |= CocoaKeyToVLC( key );
461 var_Set( p_vout->p_libvlc, "key-pressed", val );
466 [super keyDown: o_event];
470 - (void)mouseDown:(NSEvent *)o_event
476 if( ( [o_event type] == NSLeftMouseDown ) &&
477 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
479 if( [o_event clickCount] <= 1 )
481 /* single clicking */
482 var_Get( p_vout, "mouse-button-down", &val );
484 var_Set( p_vout, "mouse-button-down", val );
488 /* multiple clicking */
489 [self toggleFullscreen];
492 else if( ( [o_event type] == NSRightMouseDown ) ||
493 ( ( [o_event type] == NSLeftMouseDown ) &&
494 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
496 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
497 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
501 [super mouseDown: o_event];
504 - (void)otherMouseDown:(NSEvent *)o_event
508 if( p_vout && [o_event type] == NSOtherMouseDown )
510 var_Get( p_vout, "mouse-button-down", &val );
512 var_Set( p_vout, "mouse-button-down", val );
515 [super mouseDown: o_event];
518 - (void)rightMouseDown:(NSEvent *)o_event
520 if( p_vout && [o_event type] == NSRightMouseDown )
522 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
523 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
526 [super mouseDown: o_event];
529 - (void)mouseUp:(NSEvent *)o_event
533 if( p_vout && [o_event type] == NSLeftMouseUp )
536 b_val.b_bool = VLC_TRUE;
537 var_Set( p_vout, "mouse-clicked", b_val );
539 var_Get( p_vout, "mouse-button-down", &val );
541 var_Set( p_vout, "mouse-button-down", val );
544 [super mouseUp: o_event];
547 - (void)otherMouseUp:(NSEvent *)o_event
551 if( p_vout && [o_event type] == NSOtherMouseUp )
553 var_Get( p_vout, "mouse-button-down", &val );
555 var_Set( p_vout, "mouse-button-down", val );
558 [super mouseUp: o_event];
561 - (void)rightMouseUp:(NSEvent *)o_event
563 if( p_vout && [o_event type] == NSRightMouseUp )
565 /* FIXME: this isn't the appropriate place, but we can't receive
566 * NSRightMouseDown some how */
567 msg_Dbg( p_vout, "received NSRightMouseUp" );
568 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
571 [super mouseUp: o_event];
574 - (void)mouseDragged:(NSEvent *)o_event
576 [self mouseMoved: o_event];
579 - (void)otherMouseDragged:(NSEvent *)o_event
581 [self mouseMoved: o_event];
584 - (void)rightMouseDragged:(NSEvent *)o_event
586 [self mouseMoved: o_event];
589 - (void)mouseMoved:(NSEvent *)o_event
597 s_rect = [o_view bounds];
598 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
599 b_inside = [o_view mouse: ml inRect: s_rect];
604 unsigned int i_width, i_height, i_x, i_y;
606 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
607 (unsigned int)s_rect.size.height,
608 &i_x, &i_y, &i_width, &i_height );
610 val.i_int = ( ((int)ml.x) - i_x ) *
611 p_vout->render.i_width / i_width;
612 var_Set( p_vout, "mouse-x", val );
614 if( [[o_view className] isEqualToString: @"VLCGLView"] )
616 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
617 p_vout->render.i_height / i_height;
621 val.i_int = ( ((int)ml.y) - i_y ) *
622 p_vout->render.i_height / i_height;
624 var_Set( p_vout, "mouse-y", val );
626 val.b_bool = VLC_TRUE;
627 var_Set( p_vout, "mouse-moved", val );
629 if( [self isFullscreen] )
630 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
633 [super mouseMoved: o_event];
636 - (BOOL)acceptsFirstResponder
641 - (BOOL)becomeFirstResponder
646 - (BOOL)resignFirstResponder
648 /* We need to stay the first responder or we'll miss some
653 /* Class methods used by the different vout modules */
655 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
657 /* p_real_vout: the vout we have to use to check for video-on-top
658 and a few other things. If we are the QuickTime output, it's us.
659 It we are the OpenGL provider, it is our parent. */
660 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
662 return (vout_thread_t *) p_vout->p_parent;
671 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
672 frame: (NSRect *)s_frame
674 vlc_value_t value_drawable;
678 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
680 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
681 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
682 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
683 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
684 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
685 var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
688 /* We only wait for NSApp to initialise if we're not embedded (as in the
689 * case of the Mozilla plugin). We can tell whether we're embedded or not
690 * by examining the "drawable" value: if it's zero, we're running in the
691 * main Mac intf; if it's non-zero, we're embedded. */
692 if( value_drawable.i_int == 0 )
694 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
695 for( i_timeout = 20 ; i_timeout-- ; )
699 msleep( INTF_IDLE_SLEEP );
705 /* No MacOS X intf, unable to communicate with MT */
706 msg_Err( p_vout, "no MacOS X interface present" );
711 if ( VLCIntf && !(p_vout->b_fullscreen) &&
712 !(var_GetBool( p_vout, "macosx-background" )) &&
713 var_GetBool( p_vout, "macosx-embedded") )
715 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
721 /* No embedded vout is available */
722 if( o_return == nil )
725 bzero( &null_rect, sizeof( NSRect ) );
726 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
728 [o_return setVout: p_vout subView: view frame: s_frame];
732 - (void)enterFullscreen
734 [[o_view class] resetVout: p_vout];
735 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
738 - (void)leaveFullscreen
740 [[o_view class] resetVout: p_vout];
741 [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
746 /*****************************************************************************
747 * VLCDetachedVoutView implementation
748 *****************************************************************************/
749 @implementation VLCDetachedVoutView
751 - (id)initWithFrame: (NSRect)frameRect
753 [super initWithFrame: frameRect];
754 i_time_mouse_last_moved = 0;
758 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
759 frame: (NSRect *) s_arg_frame
761 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
762 i_time_mouse_last_moved = mdate();
763 o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self
766 [view setFrame: [self frame]];
768 if( var_GetBool( p_real_vout, "video-on-top" ) )
770 [o_window setLevel: NSStatusWindowLevel];
774 [o_window setAcceptsMouseMovedEvents: TRUE];
780 [o_window closeWindow];
781 [o_window setAcceptsMouseMovedEvents: NO];
782 i_time_mouse_last_moved = 0;
786 - (void)mouseMoved:(NSEvent *)o_event
788 i_time_mouse_last_moved = mdate();
789 [super mouseMoved: o_event];
792 - (void)hideMouse:(BOOL)b_hide
796 NSView *o_contents = [o_window contentView];
798 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
799 ml = [o_contents convertPoint:ml fromView:nil];
800 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
802 if( b_hide && b_inside )
804 [NSCursor setHiddenUntilMouseMoves: YES];
808 [NSCursor setHiddenUntilMouseMoves: NO];
815 if( p_vout->b_fullscreen )
817 if( mdate() - i_time_mouse_last_moved > 3000000 )
819 [self hideMouse: YES];
824 [self hideMouse: NO];
830 /*****************************************************************************
831 * VLCEmbeddedVoutView implementation
832 *****************************************************************************/
834 @implementation VLCEmbeddedVoutView
836 - (id)initWithFrame: (NSRect)frameRect
838 [super initWithFrame: frameRect];
840 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
844 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
845 frame: (NSRect *) s_arg_frame
849 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
852 o_window = [self window];
853 [o_window makeKeyAndOrderFront: self];
854 [o_window setAcceptsMouseMovedEvents: TRUE];
856 if( var_GetBool( p_real_vout, "video-on-top" ) )
858 [o_window setLevel: NSStatusWindowLevel];
861 [view setFrameSize: [self frame].size];
866 - (void)setUsed: (BOOL)b_new_used
879 [o_window setAcceptsMouseMovedEvents: NO];
880 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
886 @implementation VLCDetachedEmbeddedVoutView
889 o_embeddedwindow = [self window];
892 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
893 frame: (NSRect *) s_arg_frame
895 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
899 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
901 [self scaleWindowWithFactor: 1.0 animate: NO];
902 [o_window makeKeyAndOrderFront: self];
909 [o_window orderOut: self];
913 - (void)enterFullscreen
915 /* We are in a VLCEmbeddedWindow */
916 [o_embeddedwindow performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
919 - (void)leaveFullscreen
921 /* We are in a VLCEmbeddedWindow */
922 [o_embeddedwindow performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: YES];
926 /*****************************************************************************
927 * VLCVoutWindow implementation
928 *****************************************************************************/
929 @implementation VLCVoutWindow
931 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
932 frame: (NSRect *) frame
938 [self performSelectorOnMainThread: @selector(initReal:)
939 withObject: NULL waitUntilDone: YES];
949 - (id)initReal: (id) sender
951 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
952 NSArray *o_screens = [NSScreen screens];
954 vlc_bool_t b_menubar_screen = VLC_FALSE;
957 b_init_ok = VLC_FALSE;
959 p_real_vout = [VLCVoutView getRealVout: p_vout];
960 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
961 b_black = var_GetBool( p_vout, "macosx-black" );
962 b_embedded = var_GetBool( p_vout, "macosx-embedded" );
964 /* Find out on which screen to open the window */
965 if( i_device <= 0 || i_device > (int)[o_screens count] )
967 /* No preference specified. Use the main screen */
968 o_screen = [NSScreen mainScreen];
969 i_device = [o_screens indexOfObject: o_screen];
970 if( o_screen == [o_screens objectAtIndex: 0] )
971 b_menubar_screen = VLC_TRUE;
976 o_screen = [o_screens objectAtIndex: i_device];
977 b_menubar_screen = ( i_device == 0 );
980 if( p_vout->b_fullscreen )
982 CGDisplayFadeReservationToken token;
983 NSRect screen_rect = [o_screen frame];
984 screen_rect.origin.x = screen_rect.origin.y = 0;
986 /* move the FSPanel to front in case that it is currently shown
987 * this won't and is not supposed to work when it's fading right now */
988 if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] )
989 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderFront: self];
991 /* tell the fspanel to move itself to front next time it's triggered */
992 [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
994 /* Creates a window with size: screen_rect on o_screen */
995 [self initWithContentRect: screen_rect
996 styleMask: NSBorderlessWindowMask
997 backing: NSBackingStoreBuffered
998 defer: YES screen: o_screen];
1000 if( b_black == VLC_TRUE )
1002 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1003 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true );
1004 CGReleaseDisplayFadeReservation( token );
1006 for( i = 0 ; i < [o_screens count]; i++)
1010 CGDirectDisplayID displayID;
1011 CGGammaValue redMin, redMax, redGamma,
1012 greenMin, greenMax, greenGamma,
1013 blueMin, blueMax, blueGamma;
1015 CGDisplayCount dspyCnt;
1018 if( i == (unsigned int)i_device ) continue;
1020 screen_rect = [[o_screens objectAtIndex: i] frame];
1022 gPoint.x = screen_rect.origin.x;
1023 gPoint.y = screen_rect.origin.y;
1024 CGGetDisplaysWithPoint( gPoint, 1, &(dispSettings.displayID), &dspyCnt);
1025 CGGetDisplayTransferByFormula(
1026 dispSettings.displayID,
1027 &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma,
1028 &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma,
1029 &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma );
1030 CGSetDisplayTransferByFormula(
1031 dispSettings.displayID,
1032 dispSettings.redMin, 0, dispSettings.redGamma,
1033 dispSettings.greenMin, 0, dispSettings.greenGamma,
1034 dispSettings.blueMin, 0, dispSettings.blueGamma );
1037 if( b_menubar_screen )
1039 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1041 if( b_black == VLC_TRUE )
1043 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1044 CGDisplayFade( token, 2 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1045 CGReleaseDisplayFadeReservation( token);
1048 else if( var_GetBool( p_vout, "macosx-background" ) )
1050 NSRect screen_rect = [o_screen frame];
1051 screen_rect.origin.x = screen_rect.origin.y = 0;
1053 /* Creates a window with size: screen_rect on o_screen */
1054 [self initWithContentRect: screen_rect
1055 styleMask: NSBorderlessWindowMask
1056 backing: NSBackingStoreBuffered
1057 defer: YES screen: o_screen];
1059 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1063 unsigned int i_stylemask = NSTitledWindowMask |
1064 NSMiniaturizableWindowMask |
1065 NSClosableWindowMask |
1066 NSResizableWindowMask;
1071 s_rect.size.width = p_vout->i_window_width;
1072 s_rect.size.height = p_vout->i_window_height;
1079 [self initWithContentRect: s_rect
1080 styleMask: i_stylemask
1081 backing: NSBackingStoreBuffered
1082 defer: YES screen: o_screen];
1084 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1092 [self makeKeyAndOrderFront: nil];
1093 [self setReleasedWhenClosed: YES];
1095 /* We'll catch mouse events */
1096 [self makeFirstResponder: o_view];
1098 /* Add the view. It's automatically resized to fit the window */
1099 [self setContentView: o_view];
1103 b_init_ok = VLC_TRUE;
1114 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1116 [self setContentView: NULL];
1117 [self performSelectorOnMainThread: @selector(closeReal:)
1118 withObject: NULL waitUntilDone: NO];
1121 - (id)closeReal:(id)sender
1123 if( b_black == VLC_TRUE )
1125 CGDisplayFadeReservationToken token;
1126 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1127 CGDisplayFade( token, 2, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1128 CGReleaseDisplayFadeReservation( token);
1129 CGDisplayRestoreColorSyncSettings();
1131 SetSystemUIMode( kUIModeNormal, 0);
1133 /* this does only work in embedded mode */
1134 if( b_embedded == VLC_TRUE )
1135 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
1145 - (BOOL)canBecomeKeyWindow
1150 /* Sometimes crashes VLC....
1151 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1153 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1156 /* This is actually the same as VLCControls::stop. */
1158 - (BOOL)windowShouldClose:(id)sender
1160 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1162 if( p_playlist == NULL )
1167 playlist_Stop( p_playlist );
1168 vlc_object_release( p_playlist );
1170 /* The window will be closed by the intf later. */