1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2006 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>
47 /*****************************************************************************
48 * DeviceCallback: Callback triggered when the video-device variable is changed
49 *****************************************************************************/
50 int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
51 vlc_value_t old_val, vlc_value_t new_val, void *param )
54 vout_thread_t *p_vout = (vout_thread_t *)p_this;
56 msg_Dbg( p_vout, "set %d", new_val.i_int );
57 var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
58 var_Set( p_vout->p_libvlc, "video-device", new_val );
60 val.b_bool = VLC_TRUE;
61 var_Set( p_vout, "intf-change", val );
66 /*****************************************************************************
67 * VLCEmbeddedList implementation
68 *****************************************************************************/
69 @implementation VLCEmbeddedList
74 o_embedded_array = [NSMutableArray array];
82 for( i = 0; i < [o_embedded_array count]; i++ )
84 id o_vout_view = [o_embedded_array objectAtIndex: i];
85 if( ![o_vout_view isUsed] )
87 [o_vout_view setUsed: YES];
94 - (void)releaseEmbeddedVout: (id)o_vout_view
96 if( [o_embedded_array containsObject: o_vout_view] )
98 [o_vout_view setUsed: NO];
102 msg_Warn( VLCIntf, "cannot find Video Output");
106 - (void)addEmbeddedVout: (id)o_vout_view
108 if( ![o_embedded_array containsObject: o_vout_view] )
110 [o_embedded_array addObject: o_vout_view];
114 - (BOOL)windowContainsEmbedded: (id)o_window
116 /* if( ![[o_window className] isEqualToString: @"VLCWindow"] )
118 NSLog( @"We were not given a VLCWindow" );
120 return ([self getViewForWindow: o_window] == nil ? NO : YES );
123 - (id)getViewForWindow: (id)o_window
125 id o_enumerator = [o_embedded_array objectEnumerator];
126 id o_current_embedded;
128 while( (o_current_embedded = [o_enumerator nextObject]) )
130 if( [o_current_embedded getWindow] == o_window )
132 return o_current_embedded;
140 /*****************************************************************************
141 * VLCVoutView implementation
142 *****************************************************************************/
143 @implementation VLCVoutView
145 - (id)initWithFrame:(NSRect)frameRect
147 [super initWithFrame: frameRect];
150 s_frame = &frameRect;
157 - (BOOL)setVout: (vout_thread_t *) vout subView: (NSView *) view
158 frame: (NSRect *) frame
161 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
162 NSArray *o_screens = [NSScreen screens];
168 if( [o_screens count] <= 0 )
170 msg_Err( p_vout, "no OSX screens available" );
174 p_real_vout = [VLCVoutView getRealVout: p_vout];
176 /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */
177 if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 )
179 i_device = var_GetInteger( p_vout, "macosx-vdev" );
183 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
186 /* Setup the menuitem for the multiple displays. */
187 if( var_Type( p_real_vout, "video-device" ) == 0 )
190 vlc_value_t val2, text;
193 var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
195 text.psz_string = _("Video Device");
196 var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
198 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
201 text.psz_string = _("Default");
202 var_Change( p_real_vout, "video-device",
203 VLC_VAR_ADDCHOICE, &val2, &text );
204 var_Set( p_real_vout, "video-device", val2 );
206 while( (o_screen = [o_enumerator nextObject]) != NULL )
209 NSRect s_rect = [o_screen frame];
211 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
212 "%s %d (%dx%d)", _("Screen"), i,
213 (int)s_rect.size.width, (int)s_rect.size.height );
215 text.psz_string = psz_temp;
217 var_Change( p_real_vout, "video-device",
218 VLC_VAR_ADDCHOICE, &val2, &text );
221 var_Set( p_real_vout, "video-device", val2 );
226 var_AddCallback( p_real_vout, "video-device", DeviceCallback,
229 val2.b_bool = VLC_TRUE;
230 var_Set( p_real_vout, "intf-change", val2 );
233 /* Add the view. It's automatically resized to fit the window */
234 [self addSubview: o_view];
235 [self setAutoresizesSubviews: YES];
241 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize
243 [super resizeSubviewsWithOldSize: oldBoundsSize];
244 [o_view setFrameSize: [self frame].size];
249 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut];
251 [o_view removeFromSuperview];
261 NSMutableString * o_title = nil, * o_mrl = nil;
262 input_thread_t * p_input;
269 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
271 if( p_input == NULL )
276 if( input_GetItem(p_input)->psz_name != NULL )
277 o_title = [NSMutableString stringWithUTF8String:
278 input_GetItem(p_input)->psz_name];
279 if( input_GetItem(p_input)->psz_uri != NULL )
280 o_mrl = [NSMutableString stringWithUTF8String:
281 input_GetItem(p_input)->psz_uri];
287 /* FIXME once psz_access is exported, since that syntax is no longer valid */
289 if( p_input->input.p_access && !strcmp( p_input->input.p_access->p_module->psz_shortname, "File" ) )
291 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
292 if( prefix_range.location != NSNotFound )
293 [o_mrl deleteCharactersInRange: prefix_range];
294 [o_window setRepresentedFilename: o_mrl];
297 [o_window setTitle: o_title];
301 [o_window setTitle: [NSString stringWithCString: VOUT_TITLE]];
303 vlc_object_release( p_input );
307 - (void)setOnTop:(BOOL)b_on_top
311 [o_window setLevel: NSStatusWindowLevel];
315 [o_window setLevel: NSNormalWindowLevel];
319 - (void)scaleWindowWithFactor: (float)factor
322 int i_corrected_height, i_corrected_width;
324 NSPoint topleftscreen;
326 if ( !p_vout->b_fullscreen )
330 topleftbase.y = [o_window frame].size.height;
331 topleftscreen = [o_window convertBaseToScreen: topleftbase];
333 if( p_vout->render.i_height * p_vout->render.i_aspect >
334 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
336 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
338 newsize.width = (int) ( i_corrected_width * factor );
339 newsize.height = (int) ( p_vout->render.i_height * factor );
343 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
344 p_vout->render.i_aspect;
345 newsize.width = (int) ( p_vout->render.i_width * factor );
346 newsize.height = (int) ( i_corrected_height * factor );
349 /* Calculate the window's new size */
350 new_frame.size.width = [o_window frame].size.width -
351 [self frame].size.width + newsize.width;
352 new_frame.size.height = [o_window frame].size.height -
353 [self frame].size.height + newsize.height;
355 new_frame.origin.x = topleftscreen.x;
356 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
358 [o_window setFrame: new_frame display: NO];
360 p_vout->i_changes |= VOUT_SIZE_CHANGE;
364 - (void)toggleFloatOnTop
368 if( !p_real_vout ) return;
369 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
371 val.b_bool = VLC_FALSE;
375 val.b_bool = VLC_TRUE;
377 var_Set( p_real_vout, "video-on-top", val );
380 - (void)toggleFullscreen
383 if( !p_real_vout ) return;
384 var_Get( p_real_vout, "fullscreen", &val );
385 val.b_bool = !val.b_bool;
386 var_Set( p_real_vout, "fullscreen", val );
387 if( [self isFullscreen] )
388 [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
390 [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
396 var_Get( p_real_vout, "fullscreen", &val );
397 return( val.b_bool );
402 vout_Control( p_real_vout, VOUT_SNAPSHOT );
407 /* Disable Screensaver */
408 UpdateSystemActivity( UsrActivity );
416 - (void)keyDown:(NSEvent *)o_event
420 unsigned int i_pressed_modifiers = 0;
423 i_pressed_modifiers = [o_event modifierFlags];
425 if( i_pressed_modifiers & NSShiftKeyMask )
426 val.i_int |= KEY_MODIFIER_SHIFT;
427 if( i_pressed_modifiers & NSControlKeyMask )
428 val.i_int |= KEY_MODIFIER_CTRL;
429 if( i_pressed_modifiers & NSAlternateKeyMask )
430 val.i_int |= KEY_MODIFIER_ALT;
431 if( i_pressed_modifiers & NSCommandKeyMask )
432 val.i_int |= KEY_MODIFIER_COMMAND;
434 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
438 /* Escape should always get you out of fullscreen */
439 if( key == (unichar) 0x1b )
441 if( p_real_vout && [self isFullscreen] )
443 [self toggleFullscreen];
446 else if ( key == ' ' )
449 val.i_int = config_GetInt( p_vout, "key-play-pause" );
450 var_Set( p_vout->p_libvlc, "key-pressed", val );
454 val.i_int |= CocoaKeyToVLC( key );
455 var_Set( p_vout->p_libvlc, "key-pressed", val );
460 [super keyDown: o_event];
464 - (void)mouseDown:(NSEvent *)o_event
470 if( ( [o_event type] == NSLeftMouseDown ) &&
471 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
473 if( [o_event clickCount] <= 1 )
475 /* single clicking */
476 var_Get( p_vout, "mouse-button-down", &val );
478 var_Set( p_vout, "mouse-button-down", val );
482 /* multiple clicking */
483 [self toggleFullscreen];
486 else if( ( [o_event type] == NSRightMouseDown ) ||
487 ( ( [o_event type] == NSLeftMouseDown ) &&
488 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
490 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
491 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
495 [super mouseDown: o_event];
498 - (void)otherMouseDown:(NSEvent *)o_event
502 if( p_vout && [o_event type] == NSOtherMouseDown )
504 var_Get( p_vout, "mouse-button-down", &val );
506 var_Set( p_vout, "mouse-button-down", val );
509 [super mouseDown: o_event];
512 - (void)rightMouseDown:(NSEvent *)o_event
514 if( p_vout && [o_event type] == NSRightMouseDown )
516 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
517 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
520 [super mouseDown: o_event];
523 - (void)mouseUp:(NSEvent *)o_event
527 if( p_vout && [o_event type] == NSLeftMouseUp )
530 b_val.b_bool = VLC_TRUE;
531 var_Set( p_vout, "mouse-clicked", b_val );
533 var_Get( p_vout, "mouse-button-down", &val );
535 var_Set( p_vout, "mouse-button-down", val );
538 [super mouseUp: o_event];
541 - (void)otherMouseUp:(NSEvent *)o_event
545 if( p_vout && [o_event type] == NSOtherMouseUp )
547 var_Get( p_vout, "mouse-button-down", &val );
549 var_Set( p_vout, "mouse-button-down", val );
552 [super mouseUp: o_event];
555 - (void)rightMouseUp:(NSEvent *)o_event
557 if( p_vout && [o_event type] == NSRightMouseUp )
559 /* FIXME: this isn't the appropriate place, but we can't receive
560 * NSRightMouseDown some how */
561 msg_Dbg( p_vout, "received NSRightMouseUp" );
562 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
565 [super mouseUp: o_event];
568 - (void)mouseDragged:(NSEvent *)o_event
570 [self mouseMoved: o_event];
573 - (void)otherMouseDragged:(NSEvent *)o_event
575 [self mouseMoved: o_event];
578 - (void)rightMouseDragged:(NSEvent *)o_event
580 [self mouseMoved: o_event];
583 - (void)mouseMoved:(NSEvent *)o_event
591 s_rect = [o_view bounds];
592 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
593 b_inside = [o_view mouse: ml inRect: s_rect];
598 unsigned int i_width, i_height, i_x, i_y;
600 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
601 (unsigned int)s_rect.size.height,
602 &i_x, &i_y, &i_width, &i_height );
604 val.i_int = ( ((int)ml.x) - i_x ) *
605 p_vout->render.i_width / i_width;
606 var_Set( p_vout, "mouse-x", val );
608 if( [[o_view className] isEqualToString: @"VLCGLView"] )
610 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
611 p_vout->render.i_height / i_height;
615 val.i_int = ( ((int)ml.y) - i_y ) *
616 p_vout->render.i_height / i_height;
618 var_Set( p_vout, "mouse-y", val );
620 val.b_bool = VLC_TRUE;
621 var_Set( p_vout, "mouse-moved", val );
623 if( [self isFullscreen] )
624 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
627 [super mouseMoved: o_event];
630 - (BOOL)acceptsFirstResponder
635 - (BOOL)becomeFirstResponder
640 - (BOOL)resignFirstResponder
642 /* We need to stay the first responder or we'll miss some
647 /* Class methods used by the different vout modules */
649 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
651 /* p_real_vout: the vout we have to use to check for video-on-top
652 and a few other things. If we are the QuickTime output, it's us.
653 It we are the OpenGL provider, it is our parent. */
654 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
656 return (vout_thread_t *) p_vout->p_parent;
665 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
666 frame: (NSRect *)s_frame
668 vlc_value_t value_drawable;
672 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
674 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
675 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
676 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
677 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
678 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
679 var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
682 /* We only wait for NSApp to initialise if we're not embedded (as in the
683 * case of the Mozilla plugin). We can tell whether we're embedded or not
684 * by examining the "drawable" value: if it's zero, we're running in the
685 * main Mac intf; if it's non-zero, we're embedded. */
686 if( value_drawable.i_int == 0 )
688 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
689 for( i_timeout = 20 ; i_timeout-- ; )
693 msleep( INTF_IDLE_SLEEP );
699 /* No MacOS X intf, unable to communicate with MT */
700 msg_Err( p_vout, "no MacOS X interface present" );
705 if ( VLCIntf && !(p_vout->b_fullscreen) &&
706 !(var_GetBool( p_vout, "macosx-background" )) &&
707 var_GetBool( p_vout, "macosx-embedded") )
709 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
715 /* No embedded vout is available */
716 if( o_return == nil )
719 bzero( &null_rect, sizeof( NSRect ) );
720 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
722 [o_return setVout: p_vout subView: view frame: s_frame];
728 /*****************************************************************************
729 * VLCDetachedVoutView implementation
730 *****************************************************************************/
731 @implementation VLCDetachedVoutView
733 - (id)initWithFrame: (NSRect)frameRect
735 [super initWithFrame: frameRect];
736 i_time_mouse_last_moved = 0;
740 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
741 frame: (NSRect *) s_arg_frame
743 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
744 i_time_mouse_last_moved = mdate();
745 o_window = [[VLCWindow alloc] initWithVout: p_arg_vout view: self
748 [view setFrame: [self frame]];
750 if( var_GetBool( p_real_vout, "video-on-top" ) )
752 [o_window setLevel: NSStatusWindowLevel];
756 [o_window setAcceptsMouseMovedEvents: TRUE];
762 [o_window closeWindow];
763 [o_window setAcceptsMouseMovedEvents: NO];
764 i_time_mouse_last_moved = 0;
768 - (void)mouseMoved:(NSEvent *)o_event
770 i_time_mouse_last_moved = mdate();
771 [super mouseMoved: o_event];
774 - (void)hideMouse:(BOOL)b_hide
778 NSView *o_contents = [o_window contentView];
780 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
781 ml = [o_contents convertPoint:ml fromView:nil];
782 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
784 if( b_hide && b_inside )
786 [NSCursor setHiddenUntilMouseMoves: YES];
790 [NSCursor setHiddenUntilMouseMoves: NO];
797 if( p_vout->b_fullscreen )
799 if( mdate() - i_time_mouse_last_moved > 3000000 )
801 [self hideMouse: YES];
806 [self hideMouse: NO];
812 /*****************************************************************************
813 * VLCEmbeddedVoutView implementation
814 *****************************************************************************/
816 @implementation VLCEmbeddedVoutView
818 - (id)initWithFrame: (NSRect)frameRect
820 [super initWithFrame: frameRect];
822 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
826 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
827 frame: (NSRect *) s_arg_frame
831 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
834 o_window = [self window];
835 [o_window makeKeyAndOrderFront: self];
836 [o_window setAcceptsMouseMovedEvents: TRUE];
838 if( var_GetBool( p_real_vout, "video-on-top" ) )
840 [o_window setLevel: NSStatusWindowLevel];
843 [view setFrameSize: [self frame].size];
848 - (void)setUsed: (BOOL)b_new_used
861 [o_window setAcceptsMouseMovedEvents: NO];
862 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
868 @implementation VLCDetachedEmbeddedVoutView
870 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
871 frame: (NSRect *) s_arg_frame
873 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
877 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
879 [self scaleWindowWithFactor: 1.0];
880 [o_window makeKeyAndOrderFront: self];
887 [o_window orderOut: self];
893 /*****************************************************************************
894 * VLCWindow implementation
895 *****************************************************************************/
896 @implementation VLCWindow
898 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
899 frame: (NSRect *) frame
905 [self performSelectorOnMainThread: @selector(initReal:)
906 withObject: NULL waitUntilDone: YES];
916 - (id)initReal: (id) sender
918 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
919 NSArray *o_screens = [NSScreen screens];
921 vlc_bool_t b_menubar_screen = VLC_FALSE;
924 b_init_ok = VLC_FALSE;
926 p_real_vout = [VLCVoutView getRealVout: p_vout];
927 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
928 b_black = var_GetBool( p_vout, "macosx-black" );
929 b_embedded = var_GetBool( p_vout, "macosx-embedded" );
931 /* Find out on which screen to open the window */
932 if( i_device <= 0 || i_device > (int)[o_screens count] )
934 /* No preference specified. Use the main screen */
935 o_screen = [NSScreen mainScreen];
936 i_device = [o_screens indexOfObject: o_screen];
937 if( o_screen == [o_screens objectAtIndex: 0] )
938 b_menubar_screen = VLC_TRUE;
943 o_screen = [o_screens objectAtIndex: i_device];
944 b_menubar_screen = ( i_device == 0 );
947 if( p_vout->b_fullscreen )
949 CGDisplayFadeReservationToken token;
950 NSRect screen_rect = [o_screen frame];
951 screen_rect.origin.x = screen_rect.origin.y = 0;
953 /* move the FSPanel to front in case that it is currently shown
954 * this won't and is not supposed to work when it's fading right now */
955 if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] )
956 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderFront: self];
958 /* tell the fspanel to move itself to front next time it's triggered */
959 [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
961 /* Creates a window with size: screen_rect on o_screen */
962 [self initWithContentRect: screen_rect
963 styleMask: NSBorderlessWindowMask
964 backing: NSBackingStoreBuffered
965 defer: YES screen: o_screen];
967 if( b_black == VLC_TRUE )
969 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
970 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true );
971 CGReleaseDisplayFadeReservation( token );
973 for( i = 0 ; i < [o_screens count]; i++)
977 CGDirectDisplayID displayID;
978 CGGammaValue redMin, redMax, redGamma,
979 greenMin, greenMax, greenGamma,
980 blueMin, blueMax, blueGamma;
982 CGDisplayCount dspyCnt;
985 if( i == (unsigned int)i_device ) continue;
987 screen_rect = [[o_screens objectAtIndex: i] frame];
989 gPoint.x = screen_rect.origin.x;
990 gPoint.y = screen_rect.origin.y;
991 CGGetDisplaysWithPoint( gPoint, 1, &(dispSettings.displayID), &dspyCnt);
992 CGGetDisplayTransferByFormula(
993 dispSettings.displayID,
994 &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma,
995 &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma,
996 &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma );
997 CGSetDisplayTransferByFormula(
998 dispSettings.displayID,
999 dispSettings.redMin, 0, dispSettings.redGamma,
1000 dispSettings.greenMin, 0, dispSettings.greenGamma,
1001 dispSettings.blueMin, 0, dispSettings.blueGamma );
1004 if( b_menubar_screen )
1006 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1008 if( b_black == VLC_TRUE )
1010 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1011 CGDisplayFade( token, 2 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1012 CGReleaseDisplayFadeReservation( token);
1015 else if( var_GetBool( p_vout, "macosx-background" ) )
1017 NSRect screen_rect = [o_screen frame];
1018 screen_rect.origin.x = screen_rect.origin.y = 0;
1020 /* Creates a window with size: screen_rect on o_screen */
1021 [self initWithContentRect: screen_rect
1022 styleMask: NSBorderlessWindowMask
1023 backing: NSBackingStoreBuffered
1024 defer: YES screen: o_screen];
1026 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1030 unsigned int i_stylemask = NSTitledWindowMask |
1031 NSMiniaturizableWindowMask |
1032 NSClosableWindowMask |
1033 NSResizableWindowMask;
1038 s_rect.size.width = p_vout->i_window_width;
1039 s_rect.size.height = p_vout->i_window_height;
1046 [self initWithContentRect: s_rect
1047 styleMask: i_stylemask
1048 backing: NSBackingStoreBuffered
1049 defer: YES screen: o_screen];
1051 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1059 [self makeKeyAndOrderFront: nil];
1060 [self setReleasedWhenClosed: YES];
1062 /* We'll catch mouse events */
1063 [self makeFirstResponder: o_view];
1065 /* Add the view. It's automatically resized to fit the window */
1066 [self setContentView: o_view];
1070 b_init_ok = VLC_TRUE;
1081 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1083 [self setContentView: NULL];
1084 [self performSelectorOnMainThread: @selector(closeReal:)
1085 withObject: NULL waitUntilDone: NO];
1088 - (id)closeReal:(id)sender
1090 if( b_black == VLC_TRUE )
1092 CGDisplayFadeReservationToken token;
1093 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1094 CGDisplayFade( token, 2, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1095 CGReleaseDisplayFadeReservation( token);
1096 CGDisplayRestoreColorSyncSettings();
1098 SetSystemUIMode( kUIModeNormal, 0);
1100 /* this does only work in embedded mode */
1101 if( b_embedded == VLC_TRUE )
1102 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
1112 - (BOOL)canBecomeKeyWindow
1117 /* Sometimes crashes VLC....
1118 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1120 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1123 /* This is actually the same as VLCControls::stop. */
1125 - (BOOL)windowShouldClose:(id)sender
1127 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1129 if( p_playlist == NULL )
1134 playlist_Stop( p_playlist );
1135 vlc_object_release( p_playlist );
1137 /* The window will be closed by the intf later. */