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( p_input->input.p_item->psz_name != NULL )
277 o_title = [NSMutableString stringWithUTF8String:
278 p_input->input.p_item->psz_name];
279 if( p_input->input.p_item->psz_uri != NULL )
280 o_mrl = [NSMutableString stringWithUTF8String:
281 p_input->input.p_item->psz_uri];
287 if( p_input->input.p_access && !strcmp( p_input->input.p_access->p_module->psz_shortname, "File" ) )
289 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
290 if( prefix_range.location != NSNotFound )
291 [o_mrl deleteCharactersInRange: prefix_range];
292 [o_window setRepresentedFilename: o_mrl];
294 [o_window setTitle: o_title];
298 [o_window setTitle: [NSString stringWithCString: VOUT_TITLE]];
300 vlc_object_release( p_input );
304 - (void)setOnTop:(BOOL)b_on_top
308 [o_window setLevel: NSStatusWindowLevel];
312 [o_window setLevel: NSNormalWindowLevel];
316 - (void)scaleWindowWithFactor: (float)factor
319 int i_corrected_height, i_corrected_width;
321 NSPoint topleftscreen;
323 if ( !p_vout->b_fullscreen )
327 topleftbase.y = [o_window frame].size.height;
328 topleftscreen = [o_window convertBaseToScreen: topleftbase];
330 if( p_vout->render.i_height * p_vout->render.i_aspect >
331 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
333 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
335 newsize.width = (int) ( i_corrected_width * factor );
336 newsize.height = (int) ( p_vout->render.i_height * factor );
340 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
341 p_vout->render.i_aspect;
342 newsize.width = (int) ( p_vout->render.i_width * factor );
343 newsize.height = (int) ( i_corrected_height * factor );
346 /* Calculate the window's new size */
347 new_frame.size.width = [o_window frame].size.width -
348 [self frame].size.width + newsize.width;
349 new_frame.size.height = [o_window frame].size.height -
350 [self frame].size.height + newsize.height;
352 new_frame.origin.x = topleftscreen.x;
353 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
355 [o_window setFrame: new_frame display: YES];
357 p_vout->i_changes |= VOUT_SIZE_CHANGE;
361 - (void)toggleFloatOnTop
365 if( !p_real_vout ) return;
366 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
368 val.b_bool = VLC_FALSE;
372 val.b_bool = VLC_TRUE;
374 var_Set( p_real_vout, "video-on-top", val );
377 - (void)toggleFullscreen
380 if( !p_real_vout ) return;
381 var_Get( p_real_vout, "fullscreen", &val );
382 val.b_bool = !val.b_bool;
383 var_Set( p_real_vout, "fullscreen", val );
384 if( [self isFullscreen] )
385 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderFront: self];
387 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
393 var_Get( p_real_vout, "fullscreen", &val );
394 return( val.b_bool );
399 vout_Control( p_real_vout, VOUT_SNAPSHOT );
404 /* Disable Screensaver */
405 UpdateSystemActivity( UsrActivity );
413 - (void)keyDown:(NSEvent *)o_event
417 unsigned int i_pressed_modifiers = 0;
420 i_pressed_modifiers = [o_event modifierFlags];
422 if( i_pressed_modifiers & NSShiftKeyMask )
423 val.i_int |= KEY_MODIFIER_SHIFT;
424 if( i_pressed_modifiers & NSControlKeyMask )
425 val.i_int |= KEY_MODIFIER_CTRL;
426 if( i_pressed_modifiers & NSAlternateKeyMask )
427 val.i_int |= KEY_MODIFIER_ALT;
428 if( i_pressed_modifiers & NSCommandKeyMask )
429 val.i_int |= KEY_MODIFIER_COMMAND;
431 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
435 /* Escape should always get you out of fullscreen */
436 if( key == (unichar) 0x1b )
438 if( p_real_vout && [self isFullscreen] )
440 [self toggleFullscreen];
443 else if ( key == ' ' )
446 val.i_int = config_GetInt( p_vout, "key-play-pause" );
447 var_Set( p_vout->p_libvlc, "key-pressed", val );
451 val.i_int |= CocoaKeyToVLC( key );
452 var_Set( p_vout->p_libvlc, "key-pressed", val );
457 [super keyDown: o_event];
461 - (void)mouseDown:(NSEvent *)o_event
467 if( ( [o_event type] == NSLeftMouseDown ) &&
468 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
470 if( [o_event clickCount] <= 1 )
472 /* single clicking */
473 var_Get( p_vout, "mouse-button-down", &val );
475 var_Set( p_vout, "mouse-button-down", val );
479 /* multiple clicking */
480 [self toggleFullscreen];
483 else if( ( [o_event type] == NSRightMouseDown ) ||
484 ( ( [o_event type] == NSLeftMouseDown ) &&
485 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
487 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
488 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
492 [super mouseDown: o_event];
495 - (void)otherMouseDown:(NSEvent *)o_event
499 if( p_vout && [o_event type] == NSOtherMouseDown )
501 var_Get( p_vout, "mouse-button-down", &val );
503 var_Set( p_vout, "mouse-button-down", val );
506 [super mouseDown: o_event];
509 - (void)rightMouseDown:(NSEvent *)o_event
511 if( p_vout && [o_event type] == NSRightMouseDown )
513 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
514 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
517 [super mouseDown: o_event];
520 - (void)mouseUp:(NSEvent *)o_event
524 if( p_vout && [o_event type] == NSLeftMouseUp )
527 b_val.b_bool = VLC_TRUE;
528 var_Set( p_vout, "mouse-clicked", b_val );
530 var_Get( p_vout, "mouse-button-down", &val );
532 var_Set( p_vout, "mouse-button-down", val );
535 [super mouseUp: o_event];
538 - (void)otherMouseUp:(NSEvent *)o_event
542 if( p_vout && [o_event type] == NSOtherMouseUp )
544 var_Get( p_vout, "mouse-button-down", &val );
546 var_Set( p_vout, "mouse-button-down", val );
549 [super mouseUp: o_event];
552 - (void)rightMouseUp:(NSEvent *)o_event
554 if( p_vout && [o_event type] == NSRightMouseUp )
556 /* FIXME: this isn't the appropriate place, but we can't receive
557 * NSRightMouseDown some how */
558 msg_Dbg( p_vout, "received NSRightMouseUp" );
559 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
562 [super mouseUp: o_event];
565 - (void)mouseDragged:(NSEvent *)o_event
567 [self mouseMoved: o_event];
570 - (void)otherMouseDragged:(NSEvent *)o_event
572 [self mouseMoved: o_event];
575 - (void)rightMouseDragged:(NSEvent *)o_event
577 [self mouseMoved: o_event];
580 - (void)mouseMoved:(NSEvent *)o_event
588 s_rect = [o_view bounds];
589 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
590 b_inside = [o_view mouse: ml inRect: s_rect];
595 unsigned int i_width, i_height, i_x, i_y;
597 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
598 (unsigned int)s_rect.size.height,
599 &i_x, &i_y, &i_width, &i_height );
601 val.i_int = ( ((int)ml.x) - i_x ) *
602 p_vout->render.i_width / i_width;
603 var_Set( p_vout, "mouse-x", val );
605 if( [[o_view className] isEqualToString: @"VLCGLView"] )
607 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
608 p_vout->render.i_height / i_height;
612 val.i_int = ( ((int)ml.y) - i_y ) *
613 p_vout->render.i_height / i_height;
615 var_Set( p_vout, "mouse-y", val );
617 val.b_bool = VLC_TRUE;
618 var_Set( p_vout, "mouse-moved", val );
620 if( [self isFullscreen] )
621 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
624 [super mouseMoved: o_event];
627 - (BOOL)acceptsFirstResponder
632 - (BOOL)becomeFirstResponder
637 - (BOOL)resignFirstResponder
639 /* We need to stay the first responder or we'll miss some
644 /* Class methods used by the different vout modules */
646 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
648 /* p_real_vout: the vout we have to use to check for video-on-top
649 and a few other things. If we are the QuickTime output, it's us.
650 It we are the OpenGL provider, it is our parent. */
651 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
653 return (vout_thread_t *) p_vout->p_parent;
662 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
663 frame: (NSRect *)s_frame
665 vlc_value_t value_drawable;
668 vout_thread_t * p_real_vout = [VLCVoutView getRealVout: p_vout];
670 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
672 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
673 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
674 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
675 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
676 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
677 var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
680 /* We only wait for NSApp to initialise if we're not embedded (as in the
681 * case of the Mozilla plugin). We can tell whether we're embedded or not
682 * by examining the "drawable" value: if it's zero, we're running in the
683 * main Mac intf; if it's non-zero, we're embedded. */
684 if( value_drawable.i_int == 0 )
686 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
687 for( i_timeout = 20 ; i_timeout-- ; )
691 msleep( INTF_IDLE_SLEEP );
697 /* No MacOS X intf, unable to communicate with MT */
698 msg_Err( p_vout, "no MacOS X interface present" );
703 if ( VLCIntf && !(p_vout->b_fullscreen) &&
704 !(var_GetBool( p_vout, "macosx-background" )) &&
705 var_GetBool( p_vout, "macosx-embedded") )
707 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
713 /* No embedded vout is available */
714 if( o_return == nil )
717 bzero( &null_rect, sizeof( NSRect ) );
718 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
720 [o_return setVout: p_vout subView: view frame: s_frame];
726 /*****************************************************************************
727 * VLCDetachedVoutView implementation
728 *****************************************************************************/
729 @implementation VLCDetachedVoutView
731 - (id)initWithFrame: (NSRect)frameRect
733 [super initWithFrame: frameRect];
734 i_time_mouse_last_moved = 0;
738 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
739 frame: (NSRect *) s_arg_frame
741 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
742 i_time_mouse_last_moved = mdate();
743 o_window = [[VLCWindow alloc] initWithVout: p_arg_vout view: self
746 [view setFrame: [self frame]];
748 if( var_GetBool( p_real_vout, "video-on-top" ) )
750 [o_window setLevel: NSStatusWindowLevel];
754 [o_window setAcceptsMouseMovedEvents: TRUE];
760 [o_window closeWindow];
761 [o_window setAcceptsMouseMovedEvents: NO];
762 i_time_mouse_last_moved = 0;
766 - (void)mouseMoved:(NSEvent *)o_event
768 i_time_mouse_last_moved = mdate();
769 [super mouseMoved: o_event];
772 - (void)hideMouse:(BOOL)b_hide
776 NSView *o_contents = [o_window contentView];
778 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
779 ml = [o_contents convertPoint:ml fromView:nil];
780 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
782 if( b_hide && b_inside )
784 [NSCursor setHiddenUntilMouseMoves: YES];
788 [NSCursor setHiddenUntilMouseMoves: NO];
795 if( p_vout->b_fullscreen )
797 if( mdate() - i_time_mouse_last_moved > 3000000 )
799 [self hideMouse: YES];
804 [self hideMouse: NO];
810 /*****************************************************************************
811 * VLCEmbeddedVoutView implementation
812 *****************************************************************************/
814 @implementation VLCEmbeddedVoutView
816 - (id)initWithFrame: (NSRect)frameRect
818 [super initWithFrame: frameRect];
820 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
824 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
825 frame: (NSRect *) s_arg_frame
829 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
832 o_window = [self window];
833 [o_window makeKeyAndOrderFront: self];
834 [o_window setAcceptsMouseMovedEvents: TRUE];
836 if( var_GetBool( p_real_vout, "video-on-top" ) )
838 [o_window setLevel: NSStatusWindowLevel];
841 [view setFrameSize: [self frame].size];
846 - (void)setUsed: (BOOL)b_new_used
859 [o_window setAcceptsMouseMovedEvents: NO];
860 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
866 @implementation VLCDetachedEmbeddedVoutView
868 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
869 frame: (NSRect *) s_arg_frame
871 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
875 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
877 [self scaleWindowWithFactor: 1.0];
878 [o_window makeKeyAndOrderFront: self];
885 [o_window orderOut: self];
891 /*****************************************************************************
892 * VLCWindow implementation
893 *****************************************************************************/
894 @implementation VLCWindow
896 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
897 frame: (NSRect *) frame
903 [self performSelectorOnMainThread: @selector(initReal:)
904 withObject: NULL waitUntilDone: YES];
914 - (id)initReal: (id) sender
916 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
917 NSArray *o_screens = [NSScreen screens];
919 vlc_bool_t b_menubar_screen = VLC_FALSE;
922 b_init_ok = VLC_FALSE;
924 p_real_vout = [VLCVoutView getRealVout: p_vout];
925 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
926 b_black = var_GetBool( p_vout, "macosx-black" );
927 b_embedded = var_GetBool( p_vout, "macosx-embedded" );
929 /* Find out on which screen to open the window */
930 if( i_device <= 0 || i_device > (int)[o_screens count] )
932 /* No preference specified. Use the main screen */
933 o_screen = [NSScreen mainScreen];
934 i_device = [o_screens indexOfObject: o_screen];
935 if( o_screen == [o_screens objectAtIndex: 0] )
936 b_menubar_screen = VLC_TRUE;
941 o_screen = [o_screens objectAtIndex: i_device];
942 b_menubar_screen = ( i_device == 0 );
945 if( p_vout->b_fullscreen )
947 CGDisplayFadeReservationToken token;
948 NSRect screen_rect = [o_screen frame];
949 screen_rect.origin.x = screen_rect.origin.y = 0;
951 /* Creates a window with size: screen_rect on o_screen */
952 [self initWithContentRect: screen_rect
953 styleMask: NSBorderlessWindowMask
954 backing: NSBackingStoreBuffered
955 defer: YES screen: o_screen];
957 if( b_black == VLC_TRUE )
959 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
960 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true );
961 CGReleaseDisplayFadeReservation( token );
963 for( i = 0 ; i < [o_screens count]; i++)
967 CGDirectDisplayID displayID;
968 CGGammaValue redMin, redMax, redGamma,
969 greenMin, greenMax, greenGamma,
970 blueMin, blueMax, blueGamma;
972 CGDisplayCount dspyCnt;
975 if( i == (unsigned int)i_device ) continue;
977 screen_rect = [[o_screens objectAtIndex: i] frame];
979 gPoint.x = screen_rect.origin.x;
980 gPoint.y = screen_rect.origin.y;
981 CGGetDisplaysWithPoint( gPoint, 1, &(dispSettings.displayID), &dspyCnt);
982 CGGetDisplayTransferByFormula(
983 dispSettings.displayID,
984 &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma,
985 &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma,
986 &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma );
987 CGSetDisplayTransferByFormula(
988 dispSettings.displayID,
989 dispSettings.redMin, 0, dispSettings.redGamma,
990 dispSettings.greenMin, 0, dispSettings.greenGamma,
991 dispSettings.blueMin, 0, dispSettings.blueGamma );
994 if( b_menubar_screen )
996 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
998 if( b_black == VLC_TRUE )
1000 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1001 CGDisplayFade( token, 2 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1002 CGReleaseDisplayFadeReservation( token);
1005 else if( var_GetBool( p_vout, "macosx-background" ) )
1007 NSRect screen_rect = [o_screen frame];
1008 screen_rect.origin.x = screen_rect.origin.y = 0;
1010 /* Creates a window with size: screen_rect on o_screen */
1011 [self initWithContentRect: screen_rect
1012 styleMask: NSBorderlessWindowMask
1013 backing: NSBackingStoreBuffered
1014 defer: YES screen: o_screen];
1016 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1020 unsigned int i_stylemask = NSTitledWindowMask |
1021 NSMiniaturizableWindowMask |
1022 NSClosableWindowMask |
1023 NSResizableWindowMask;
1028 s_rect.size.width = p_vout->i_window_width;
1029 s_rect.size.height = p_vout->i_window_height;
1036 [self initWithContentRect: s_rect
1037 styleMask: i_stylemask
1038 backing: NSBackingStoreBuffered
1039 defer: YES screen: o_screen];
1041 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1049 [self makeKeyAndOrderFront: nil];
1050 [self setReleasedWhenClosed: YES];
1052 /* We'll catch mouse events */
1053 [self makeFirstResponder: o_view];
1055 /* Add the view. It's automatically resized to fit the window */
1056 [self setContentView: o_view];
1060 b_init_ok = VLC_TRUE;
1071 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1073 [self setContentView: NULL];
1074 [self performSelectorOnMainThread: @selector(closeReal:)
1075 withObject: NULL waitUntilDone: NO];
1078 - (id)closeReal:(id)sender
1080 if( b_black == VLC_TRUE )
1082 CGDisplayFadeReservationToken token;
1083 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1084 CGDisplayFade( token, 2, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1085 CGReleaseDisplayFadeReservation( token);
1086 CGDisplayRestoreColorSyncSettings();
1088 SetSystemUIMode( kUIModeNormal, 0);
1090 /* this does only work in embedded mode */
1091 if( b_embedded == VLC_TRUE )
1092 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
1102 - (BOOL)canBecomeKeyWindow
1107 /* Sometimes crashes VLC....
1108 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1110 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1113 /* This is actually the same as VLCControls::stop. */
1115 - (BOOL)windowShouldClose:(id)sender
1117 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1119 if( p_playlist == NULL )
1124 playlist_Stop( p_playlist );
1125 vlc_object_release( p_playlist );
1127 /* The window will be closed by the intf later. */