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 [o_view removeFromSuperview];
259 NSMutableString * o_title = nil, * o_mrl = nil;
260 input_thread_t * p_input;
267 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
269 if( p_input == NULL )
274 if( p_input->input.p_item->psz_name != NULL )
275 o_title = [NSMutableString stringWithUTF8String:
276 p_input->input.p_item->psz_name];
277 if( p_input->input.p_item->psz_uri != NULL )
278 o_mrl = [NSMutableString stringWithUTF8String:
279 p_input->input.p_item->psz_uri];
285 if( p_input->input.p_access && !strcmp( p_input->input.p_access->p_module->psz_shortname, "File" ) )
287 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
288 if( prefix_range.location != NSNotFound )
289 [o_mrl deleteCharactersInRange: prefix_range];
290 [o_window setRepresentedFilename: o_mrl];
292 [o_window setTitle: o_title];
296 [o_window setTitle: [NSString stringWithCString: VOUT_TITLE]];
298 vlc_object_release( p_input );
302 - (void)setOnTop:(BOOL)b_on_top
306 [o_window setLevel: NSStatusWindowLevel];
310 [o_window setLevel: NSNormalWindowLevel];
314 - (void)scaleWindowWithFactor: (float)factor
317 int i_corrected_height, i_corrected_width;
319 NSPoint topleftscreen;
321 if ( !p_vout->b_fullscreen )
325 topleftbase.y = [o_window frame].size.height;
326 topleftscreen = [o_window convertBaseToScreen: topleftbase];
328 if( p_vout->render.i_height * p_vout->render.i_aspect >
329 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
331 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
333 newsize.width = (int) ( i_corrected_width * factor );
334 newsize.height = (int) ( p_vout->render.i_height * factor );
338 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
339 p_vout->render.i_aspect;
340 newsize.width = (int) ( p_vout->render.i_width * factor );
341 newsize.height = (int) ( i_corrected_height * factor );
344 /* Calculate the window's new size */
345 new_frame.size.width = [o_window frame].size.width -
346 [self frame].size.width + newsize.width;
347 new_frame.size.height = [o_window frame].size.height -
348 [self frame].size.height + newsize.height;
350 new_frame.origin.x = topleftscreen.x;
351 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
353 [o_window setFrame: new_frame display: YES];
355 p_vout->i_changes |= VOUT_SIZE_CHANGE;
359 - (void)toggleFloatOnTop
363 if( !p_real_vout ) return;
364 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
366 val.b_bool = VLC_FALSE;
370 val.b_bool = VLC_TRUE;
372 var_Set( p_real_vout, "video-on-top", val );
375 - (void)toggleFullscreen
378 if( !p_real_vout ) return;
379 var_Get( p_real_vout, "fullscreen", &val );
380 val.b_bool = !val.b_bool;
381 var_Set( p_real_vout, "fullscreen", val );
382 if( [self isFullscreen] )
383 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderFront: self];
385 [[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
391 var_Get( p_real_vout, "fullscreen", &val );
392 return( val.b_bool );
397 vout_Control( p_real_vout, VOUT_SNAPSHOT );
402 /* Disable Screensaver */
403 UpdateSystemActivity( UsrActivity );
411 - (void)keyDown:(NSEvent *)o_event
415 unsigned int i_pressed_modifiers = 0;
418 i_pressed_modifiers = [o_event modifierFlags];
420 if( i_pressed_modifiers & NSShiftKeyMask )
421 val.i_int |= KEY_MODIFIER_SHIFT;
422 if( i_pressed_modifiers & NSControlKeyMask )
423 val.i_int |= KEY_MODIFIER_CTRL;
424 if( i_pressed_modifiers & NSAlternateKeyMask )
425 val.i_int |= KEY_MODIFIER_ALT;
426 if( i_pressed_modifiers & NSCommandKeyMask )
427 val.i_int |= KEY_MODIFIER_COMMAND;
429 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
433 /* Escape should always get you out of fullscreen */
434 if( key == (unichar) 0x1b )
436 if( p_real_vout && [self isFullscreen] )
438 [self toggleFullscreen];
441 else if ( key == ' ' )
444 val.i_int = config_GetInt( p_vout, "key-play-pause" );
445 var_Set( p_vout->p_libvlc, "key-pressed", val );
449 val.i_int |= CocoaKeyToVLC( key );
450 var_Set( p_vout->p_libvlc, "key-pressed", val );
455 [super keyDown: o_event];
459 - (void)mouseDown:(NSEvent *)o_event
465 if( ( [o_event type] == NSLeftMouseDown ) &&
466 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
468 if( [o_event clickCount] <= 1 )
470 /* single clicking */
471 var_Get( p_vout, "mouse-button-down", &val );
473 var_Set( p_vout, "mouse-button-down", val );
477 /* multiple clicking */
478 [self toggleFullscreen];
481 else if( ( [o_event type] == NSRightMouseDown ) ||
482 ( ( [o_event type] == NSLeftMouseDown ) &&
483 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
485 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
486 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
490 [super mouseDown: o_event];
493 - (void)otherMouseDown:(NSEvent *)o_event
497 if( p_vout && [o_event type] == NSOtherMouseDown )
499 var_Get( p_vout, "mouse-button-down", &val );
501 var_Set( p_vout, "mouse-button-down", val );
504 [super mouseDown: o_event];
507 - (void)rightMouseDown:(NSEvent *)o_event
509 if( p_vout && [o_event type] == NSRightMouseDown )
511 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
512 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
515 [super mouseDown: o_event];
518 - (void)mouseUp:(NSEvent *)o_event
522 if( p_vout && [o_event type] == NSLeftMouseUp )
525 b_val.b_bool = VLC_TRUE;
526 var_Set( p_vout, "mouse-clicked", b_val );
528 var_Get( p_vout, "mouse-button-down", &val );
530 var_Set( p_vout, "mouse-button-down", val );
533 [super mouseUp: o_event];
536 - (void)otherMouseUp:(NSEvent *)o_event
540 if( p_vout && [o_event type] == NSOtherMouseUp )
542 var_Get( p_vout, "mouse-button-down", &val );
544 var_Set( p_vout, "mouse-button-down", val );
547 [super mouseUp: o_event];
550 - (void)rightMouseUp:(NSEvent *)o_event
552 if( p_vout && [o_event type] == NSRightMouseUp )
554 /* FIXME: this isn't the appropriate place, but we can't receive
555 * NSRightMouseDown some how */
556 msg_Dbg( p_vout, "received NSRightMouseUp" );
557 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
560 [super mouseUp: o_event];
563 - (void)mouseDragged:(NSEvent *)o_event
565 [self mouseMoved: o_event];
568 - (void)otherMouseDragged:(NSEvent *)o_event
570 [self mouseMoved: o_event];
573 - (void)rightMouseDragged:(NSEvent *)o_event
575 [self mouseMoved: o_event];
578 - (void)mouseMoved:(NSEvent *)o_event
586 s_rect = [o_view bounds];
587 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
588 b_inside = [o_view mouse: ml inRect: s_rect];
593 unsigned int i_width, i_height, i_x, i_y;
595 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
596 (unsigned int)s_rect.size.height,
597 &i_x, &i_y, &i_width, &i_height );
599 val.i_int = ( ((int)ml.x) - i_x ) *
600 p_vout->render.i_width / i_width;
601 var_Set( p_vout, "mouse-x", val );
603 if( [[o_view className] isEqualToString: @"VLCGLView"] )
605 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
606 p_vout->render.i_height / i_height;
610 val.i_int = ( ((int)ml.y) - i_y ) *
611 p_vout->render.i_height / i_height;
613 var_Set( p_vout, "mouse-y", val );
615 val.b_bool = VLC_TRUE;
616 var_Set( p_vout, "mouse-moved", val );
618 if( [self isFullscreen] )
619 [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
622 [super mouseMoved: o_event];
625 - (BOOL)acceptsFirstResponder
630 - (BOOL)becomeFirstResponder
635 - (BOOL)resignFirstResponder
637 /* We need to stay the first responder or we'll miss some
642 /* Class methods used by the different vout modules */
644 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
646 /* p_real_vout: the vout we have to use to check for video-on-top
647 and a few other things. If we are the QuickTime output, it's us.
648 It we are the OpenGL provider, it is our parent. */
649 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
651 return (vout_thread_t *) p_vout->p_parent;
660 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
661 frame: (NSRect *)s_frame
663 vlc_value_t value_drawable;
666 vout_thread_t * p_real_vout = [VLCVoutView getRealVout: p_vout];
668 var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
670 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
671 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
672 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
673 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
674 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
675 var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
678 /* We only wait for NSApp to initialise if we're not embedded (as in the
679 * case of the Mozilla plugin). We can tell whether we're embedded or not
680 * by examining the "drawable" value: if it's zero, we're running in the
681 * main Mac intf; if it's non-zero, we're embedded. */
682 if( value_drawable.i_int == 0 )
684 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
685 for( i_timeout = 20 ; i_timeout-- ; )
689 msleep( INTF_IDLE_SLEEP );
695 /* No MacOS X intf, unable to communicate with MT */
696 msg_Err( p_vout, "no MacOS X interface present" );
701 if ( VLCIntf && !(p_vout->b_fullscreen) &&
702 !(var_GetBool( p_vout, "macosx-background" )) &&
703 var_GetBool( p_vout, "macosx-embedded") )
705 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
711 /* No embedded vout is available */
712 if( o_return == nil )
715 bzero( &null_rect, sizeof( NSRect ) );
716 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
718 [o_return setVout: p_vout subView: view frame: s_frame];
724 /*****************************************************************************
725 * VLCDetachedVoutView implementation
726 *****************************************************************************/
727 @implementation VLCDetachedVoutView
729 - (id)initWithFrame: (NSRect)frameRect
731 [super initWithFrame: frameRect];
732 i_time_mouse_last_moved = 0;
736 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
737 frame: (NSRect *) s_arg_frame
739 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
740 i_time_mouse_last_moved = mdate();
741 o_window = [[VLCWindow alloc] initWithVout: p_arg_vout view: self
744 [view setFrame: [self frame]];
746 if( var_GetBool( p_real_vout, "video-on-top" ) )
748 [o_window setLevel: NSStatusWindowLevel];
752 [o_window setAcceptsMouseMovedEvents: TRUE];
758 [o_window closeWindow];
759 [o_window setAcceptsMouseMovedEvents: NO];
760 i_time_mouse_last_moved = 0;
764 - (void)mouseMoved:(NSEvent *)o_event
766 i_time_mouse_last_moved = mdate();
767 [super mouseMoved: o_event];
770 - (void)hideMouse:(BOOL)b_hide
774 NSView *o_contents = [o_window contentView];
776 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
777 ml = [o_contents convertPoint:ml fromView:nil];
778 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
780 if( b_hide && b_inside )
782 [NSCursor setHiddenUntilMouseMoves: YES];
786 [NSCursor setHiddenUntilMouseMoves: NO];
793 if( p_vout->b_fullscreen )
795 if( mdate() - i_time_mouse_last_moved > 3000000 )
797 [self hideMouse: YES];
802 [self hideMouse: NO];
808 /*****************************************************************************
809 * VLCEmbeddedVoutView implementation
810 *****************************************************************************/
812 @implementation VLCEmbeddedVoutView
814 - (id)initWithFrame: (NSRect)frameRect
816 [super initWithFrame: frameRect];
818 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
822 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
823 frame: (NSRect *) s_arg_frame
827 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
830 o_window = [self window];
831 [o_window makeKeyAndOrderFront: self];
832 [o_window setAcceptsMouseMovedEvents: TRUE];
834 if( var_GetBool( p_real_vout, "video-on-top" ) )
836 [o_window setLevel: NSStatusWindowLevel];
839 [view setFrameSize: [self frame].size];
844 - (void)setUsed: (BOOL)b_new_used
857 [o_window setAcceptsMouseMovedEvents: NO];
858 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
864 @implementation VLCDetachedEmbeddedVoutView
866 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
867 frame: (NSRect *) s_arg_frame
869 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
873 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
875 [self scaleWindowWithFactor: 1.0];
876 [o_window makeKeyAndOrderFront: self];
883 [o_window orderOut: self];
889 /*****************************************************************************
890 * VLCWindow implementation
891 *****************************************************************************/
892 @implementation VLCWindow
894 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
895 frame: (NSRect *) frame
901 [self performSelectorOnMainThread: @selector(initReal:)
902 withObject: NULL waitUntilDone: YES];
912 - (id)initReal: (id) sender
914 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
915 NSArray *o_screens = [NSScreen screens];
917 vlc_bool_t b_menubar_screen = VLC_FALSE;
920 b_init_ok = VLC_FALSE;
922 p_real_vout = [VLCVoutView getRealVout: p_vout];
923 i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
924 b_black = var_GetBool( p_vout, "macosx-black" );
926 /* Find out on which screen to open the window */
927 if( i_device <= 0 || i_device > (int)[o_screens count] )
929 /* No preference specified. Use the main screen */
930 o_screen = [NSScreen mainScreen];
931 i_device = [o_screens indexOfObject: o_screen];
932 if( o_screen == [o_screens objectAtIndex: 0] )
933 b_menubar_screen = VLC_TRUE;
938 o_screen = [o_screens objectAtIndex: i_device];
939 b_menubar_screen = ( i_device == 0 );
942 if( p_vout->b_fullscreen )
944 CGDisplayFadeReservationToken token;
945 NSRect screen_rect = [o_screen frame];
946 screen_rect.origin.x = screen_rect.origin.y = 0;
948 /* Creates a window with size: screen_rect on o_screen */
949 [self initWithContentRect: screen_rect
950 styleMask: NSBorderlessWindowMask
951 backing: NSBackingStoreBuffered
952 defer: YES screen: o_screen];
954 if( b_black == VLC_TRUE )
956 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
957 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true );
958 CGReleaseDisplayFadeReservation( token );
960 for( i = 0 ; i < [o_screens count]; i++)
964 CGDirectDisplayID displayID;
965 CGGammaValue redMin, redMax, redGamma,
966 greenMin, greenMax, greenGamma,
967 blueMin, blueMax, blueGamma;
969 CGDisplayCount dspyCnt;
972 if( i == (unsigned int)i_device ) continue;
974 screen_rect = [[o_screens objectAtIndex: i] frame];
976 gPoint.x = screen_rect.origin.x;
977 gPoint.y = screen_rect.origin.y;
978 CGGetDisplaysWithPoint( gPoint, 1, &(dispSettings.displayID), &dspyCnt);
979 CGGetDisplayTransferByFormula(
980 dispSettings.displayID,
981 &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma,
982 &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma,
983 &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma );
984 CGSetDisplayTransferByFormula(
985 dispSettings.displayID,
986 dispSettings.redMin, 0, dispSettings.redGamma,
987 dispSettings.greenMin, 0, dispSettings.greenGamma,
988 dispSettings.blueMin, 0, dispSettings.blueGamma );
991 if( b_menubar_screen )
993 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
995 if( b_black == VLC_TRUE )
997 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
998 CGDisplayFade( token, 2 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
999 CGReleaseDisplayFadeReservation( token);
1002 else if( var_GetBool( p_vout, "macosx-background" ) )
1004 NSRect screen_rect = [o_screen frame];
1005 screen_rect.origin.x = screen_rect.origin.y = 0;
1007 /* Creates a window with size: screen_rect on o_screen */
1008 [self initWithContentRect: screen_rect
1009 styleMask: NSBorderlessWindowMask
1010 backing: NSBackingStoreBuffered
1011 defer: YES screen: o_screen];
1013 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1017 unsigned int i_stylemask = NSTitledWindowMask |
1018 NSMiniaturizableWindowMask |
1019 NSClosableWindowMask |
1020 NSResizableWindowMask;
1025 s_rect.size.width = p_vout->i_window_width;
1026 s_rect.size.height = p_vout->i_window_height;
1033 [self initWithContentRect: s_rect
1034 styleMask: i_stylemask
1035 backing: NSBackingStoreBuffered
1036 defer: YES screen: o_screen];
1038 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1046 [self makeKeyAndOrderFront: nil];
1047 [self setReleasedWhenClosed: YES];
1049 /* We'll catch mouse events */
1050 [self makeFirstResponder: o_view];
1052 /* Add the view. It's automatically resized to fit the window */
1053 [self setContentView: o_view];
1057 b_init_ok = VLC_TRUE;
1066 - (void) closeWindow
1068 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1070 [self setContentView: NULL];
1071 [self performSelectorOnMainThread: @selector(closeReal:)
1072 withObject: NULL waitUntilDone: NO];
1075 - (id) closeReal: (id) sender
1077 if( b_black == VLC_TRUE )
1079 CGDisplayFadeReservationToken token;
1080 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1081 CGDisplayFade( token, 2, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1082 CGReleaseDisplayFadeReservation( token);
1083 CGDisplayRestoreColorSyncSettings();
1085 SetSystemUIMode( kUIModeNormal, 0);
1095 - (BOOL)canBecomeKeyWindow
1100 /* Sometimes crashes VLC....
1101 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1103 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1106 /* This is actually the same as VLCControls::stop. */
1108 - (BOOL)windowShouldClose:(id)sender
1110 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1112 if( p_playlist == NULL )
1117 playlist_Stop( p_playlist );
1118 vlc_object_release( p_playlist );
1120 /* The window will be closed by the intf later. */