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>
45 /*****************************************************************************
46 * DeviceCallback: Callback triggered when the video-device variable is changed
47 *****************************************************************************/
48 int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
49 vlc_value_t old_val, vlc_value_t new_val, void *param )
52 vout_thread_t *p_vout = (vout_thread_t *)p_this;
54 msg_Dbg( p_vout, "set %d", new_val.i_int );
55 var_Create( p_vout->p_vlc, "video-device", VLC_VAR_INTEGER );
56 var_Set( p_vout->p_vlc, "video-device", new_val );
58 val.b_bool = VLC_TRUE;
59 var_Set( p_vout, "intf-change", val );
64 /*****************************************************************************
65 * VLCEmbeddedList implementation
66 *****************************************************************************/
67 @implementation VLCEmbeddedList
72 o_embedded_array = [NSMutableArray array];
80 for( i = 0; i < [o_embedded_array count]; i++ )
82 id o_vout_view = [o_embedded_array objectAtIndex: i];
83 if( ![o_vout_view isUsed] )
85 [o_vout_view setUsed: YES];
92 - (void)releaseEmbeddedVout: (id)o_vout_view
94 if( [o_embedded_array containsObject: o_vout_view] )
96 [o_vout_view setUsed: NO];
100 msg_Warn( VLCIntf, "cannot find Video Output");
104 - (void)addEmbeddedVout: (id)o_vout_view
106 if( ![o_embedded_array containsObject: o_vout_view] )
108 [o_embedded_array addObject: o_vout_view];
112 - (BOOL)windowContainsEmbedded: (id)o_window
114 /* if( ![[o_window className] isEqualToString: @"VLCWindow"] )
116 NSLog( @"We were not given a VLCWindow" );
118 return ([self getViewForWindow: o_window] == nil ? NO : YES );
121 - (id)getViewForWindow: (id)o_window
123 id o_enumerator = [o_embedded_array objectEnumerator];
124 id o_current_embedded;
126 while( (o_current_embedded = [o_enumerator nextObject]) )
128 if( [o_current_embedded getWindow] == o_window )
130 return o_current_embedded;
138 /*****************************************************************************
139 * VLCVoutView implementation
140 *****************************************************************************/
141 @implementation VLCVoutView
143 - (id)initWithFrame:(NSRect)frameRect
145 [super initWithFrame: frameRect];
148 s_frame = &frameRect;
155 - (BOOL)setVout: (vout_thread_t *) vout subView: (NSView *) view
156 frame: (NSRect *) frame
159 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
160 NSArray *o_screens = [NSScreen screens];
166 if( [o_screens count] <= 0 )
168 msg_Err( p_vout, "no OSX screens available" );
172 p_real_vout = [VLCVoutView getRealVout: p_vout];
174 /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */
175 if( var_Type( p_real_vout->p_vlc, "video-device" ) == 0 )
177 i_device = var_GetInteger( p_vout, "macosx-vdev" );
181 i_device = var_GetInteger( p_real_vout->p_vlc, "video-device" );
184 /* Setup the menuitem for the multiple displays. */
185 if( var_Type( p_real_vout, "video-device" ) == 0 )
188 vlc_value_t val2, text;
191 var_Create( p_real_vout, "video-device", VLC_VAR_INTEGER |
193 text.psz_string = _("Video Device");
194 var_Change( p_real_vout, "video-device", VLC_VAR_SETTEXT, &text, NULL );
196 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
199 text.psz_string = _("Default");
200 var_Change( p_real_vout, "video-device",
201 VLC_VAR_ADDCHOICE, &val2, &text );
202 var_Set( p_real_vout, "video-device", val2 );
204 while( (o_screen = [o_enumerator nextObject]) != NULL )
207 NSRect s_rect = [o_screen frame];
209 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
210 "%s %d (%dx%d)", _("Screen"), i,
211 (int)s_rect.size.width, (int)s_rect.size.height );
213 text.psz_string = psz_temp;
215 var_Change( p_real_vout, "video-device",
216 VLC_VAR_ADDCHOICE, &val2, &text );
219 var_Set( p_real_vout, "video-device", val2 );
224 var_AddCallback( p_real_vout, "video-device", DeviceCallback,
227 val2.b_bool = VLC_TRUE;
228 var_Set( p_real_vout, "intf-change", val2 );
231 /* Add the view. It's automatically resized to fit the window */
232 [self addSubview: o_view];
233 [self setAutoresizesSubviews: YES];
239 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize
241 [super resizeSubviewsWithOldSize: oldBoundsSize];
242 [o_view setFrameSize: [self frame].size];
247 [o_view removeFromSuperview];
257 NSMutableString * o_title = nil, * o_mrl = nil;
258 input_thread_t * p_input;
265 p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
267 if( p_input == NULL )
272 if( p_input->input.p_item->psz_name != NULL )
273 o_title = [NSMutableString stringWithUTF8String:
274 p_input->input.p_item->psz_name];
275 if( p_input->input.p_item->psz_uri != NULL )
276 o_mrl = [NSMutableString stringWithUTF8String:
277 p_input->input.p_item->psz_uri];
283 if( p_input->input.p_access && !strcmp( p_input->input.p_access->p_module->psz_shortname, "File" ) )
285 NSRange prefix_range = [o_mrl rangeOfString: @"file:"];
286 if( prefix_range.location != NSNotFound )
287 [o_mrl deleteCharactersInRange: prefix_range];
288 [o_window setRepresentedFilename: o_mrl];
290 [o_window setTitle: o_title];
294 [o_window setTitle: [NSString stringWithCString: VOUT_TITLE]];
296 vlc_object_release( p_input );
300 - (void)setOnTop:(BOOL)b_on_top
304 [o_window setLevel: NSStatusWindowLevel];
308 [o_window setLevel: NSNormalWindowLevel];
312 - (void)scaleWindowWithFactor: (float)factor
315 int i_corrected_height, i_corrected_width;
317 NSPoint topleftscreen;
319 if ( !p_vout->b_fullscreen )
323 topleftbase.y = [o_window frame].size.height;
324 topleftscreen = [o_window convertBaseToScreen: topleftbase];
326 if( p_vout->render.i_height * p_vout->render.i_aspect >
327 p_vout->render.i_width * VOUT_ASPECT_FACTOR )
329 i_corrected_width = p_vout->render.i_height * p_vout->render.i_aspect /
331 newsize.width = (int) ( i_corrected_width * factor );
332 newsize.height = (int) ( p_vout->render.i_height * factor );
336 i_corrected_height = p_vout->render.i_width * VOUT_ASPECT_FACTOR /
337 p_vout->render.i_aspect;
338 newsize.width = (int) ( p_vout->render.i_width * factor );
339 newsize.height = (int) ( i_corrected_height * factor );
342 /* Calculate the window's new size */
343 new_frame.size.width = [o_window frame].size.width -
344 [self frame].size.width + newsize.width;
345 new_frame.size.height = [o_window frame].size.height -
346 [self frame].size.height + newsize.height;
348 new_frame.origin.x = topleftscreen.x;
349 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
351 [o_window setFrame: new_frame display: YES];
353 p_vout->i_changes |= VOUT_SIZE_CHANGE;
357 - (void)toggleFloatOnTop
361 if( !p_real_vout ) return;
362 if( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
364 val.b_bool = VLC_FALSE;
368 val.b_bool = VLC_TRUE;
370 var_Set( p_real_vout, "video-on-top", val );
373 - (void)toggleFullscreen
376 if( !p_real_vout ) return;
377 var_Get( p_real_vout, "fullscreen", &val );
378 val.b_bool = !val.b_bool;
379 var_Set( p_real_vout, "fullscreen", val );
385 var_Get( p_real_vout, "fullscreen", &val );
386 return( val.b_bool );
391 vout_Control( p_real_vout, VOUT_SNAPSHOT );
396 /* Disable Screensaver */
397 UpdateSystemActivity( UsrActivity );
405 - (void)keyDown:(NSEvent *)o_event
409 unsigned int i_pressed_modifiers = 0;
412 i_pressed_modifiers = [o_event modifierFlags];
414 if( i_pressed_modifiers & NSShiftKeyMask )
415 val.i_int |= KEY_MODIFIER_SHIFT;
416 if( i_pressed_modifiers & NSControlKeyMask )
417 val.i_int |= KEY_MODIFIER_CTRL;
418 if( i_pressed_modifiers & NSAlternateKeyMask )
419 val.i_int |= KEY_MODIFIER_ALT;
420 if( i_pressed_modifiers & NSCommandKeyMask )
421 val.i_int |= KEY_MODIFIER_COMMAND;
423 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
427 /* Escape should always get you out of fullscreen */
428 if( key == (unichar) 0x1b )
430 if( p_real_vout && [self isFullscreen] )
432 [self toggleFullscreen];
435 else if ( key == ' ' )
438 val.i_int = config_GetInt( p_vout, "key-play-pause" );
439 var_Set( p_vout->p_vlc, "key-pressed", val );
443 val.i_int |= CocoaKeyToVLC( key );
444 var_Set( p_vout->p_vlc, "key-pressed", val );
449 [super keyDown: o_event];
453 - (void)mouseDown:(NSEvent *)o_event
459 if( ( [o_event type] == NSLeftMouseDown ) &&
460 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
462 if( [o_event clickCount] <= 1 )
464 /* single clicking */
465 var_Get( p_vout, "mouse-button-down", &val );
467 var_Set( p_vout, "mouse-button-down", val );
471 /* multiple clicking */
472 [self toggleFullscreen];
475 else if( ( [o_event type] == NSRightMouseDown ) ||
476 ( ( [o_event type] == NSLeftMouseDown ) &&
477 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
479 msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
480 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
483 [super mouseDown: o_event];
487 - (void)otherMouseDown:(NSEvent *)o_event
493 switch( [o_event type] )
495 case NSOtherMouseDown:
497 var_Get( p_vout, "mouse-button-down", &val );
499 var_Set( p_vout, "mouse-button-down", val );
504 [super mouseDown: o_event];
510 - (void)rightMouseDown:(NSEvent *)o_event
514 switch( [o_event type] )
516 case NSRightMouseDown:
518 msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
519 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
524 [super mouseDown: o_event];
530 - (void)mouseUp:(NSEvent *)o_event
536 switch( [o_event type] )
541 b_val.b_bool = VLC_TRUE;
542 var_Set( p_vout, "mouse-clicked", b_val );
544 var_Get( p_vout, "mouse-button-down", &val );
546 var_Set( p_vout, "mouse-button-down", val );
551 [super mouseUp: o_event];
557 - (void)otherMouseUp:(NSEvent *)o_event
563 switch( [o_event type] )
567 var_Get( p_vout, "mouse-button-down", &val );
569 var_Set( p_vout, "mouse-button-down", val );
574 [super mouseUp: o_event];
580 - (void)rightMouseUp:(NSEvent *)o_event
584 switch( [o_event type] )
588 /* FIXME: this isn't the appropriate place, but we can't receive
589 * NSRightMouseDown some how */
590 msg_Dbg( p_vout, "received NSRightMouseUp" );
591 [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
596 [super mouseUp: o_event];
602 - (void)mouseDragged:(NSEvent *)o_event
604 [self mouseMoved: o_event];
607 - (void)otherMouseDragged:(NSEvent *)o_event
609 [self mouseMoved: o_event];
612 - (void)rightMouseDragged:(NSEvent *)o_event
614 [self mouseMoved: o_event];
617 - (void)mouseMoved:(NSEvent *)o_event
625 s_rect = [o_view bounds];
626 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
627 b_inside = [o_view mouse: ml inRect: s_rect];
632 unsigned int i_width, i_height, i_x, i_y;
634 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
635 (unsigned int)s_rect.size.height,
636 &i_x, &i_y, &i_width, &i_height );
638 val.i_int = ( ((int)ml.x) - i_x ) *
639 p_vout->render.i_width / i_width;
640 var_Set( p_vout, "mouse-x", val );
642 if( [[o_view className] isEqualToString: @"VLCGLView"] )
644 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
645 p_vout->render.i_height / i_height;
649 val.i_int = ( ((int)ml.y) - i_y ) *
650 p_vout->render.i_height / i_height;
652 var_Set( p_vout, "mouse-y", val );
654 val.b_bool = VLC_TRUE;
655 var_Set( p_vout, "mouse-moved", val );
658 [super mouseMoved: o_event];
661 - (BOOL)acceptsFirstResponder
666 - (BOOL)becomeFirstResponder
671 - (BOOL)resignFirstResponder
673 /* We need to stay the first responder or we'll miss some
678 /* Class methods used by the different vout modules */
680 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
682 /* p_real_vout: the vout we have to use to check for video-on-top
683 and a few other things. If we are the QuickTime output, it's us.
684 It we are the OpenGL provider, it is our parent. */
685 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
687 return (vout_thread_t *) p_vout->p_parent;
696 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
697 frame: (NSRect *)s_frame
699 vlc_value_t value_drawable;
702 vout_thread_t * p_real_vout = [VLCVoutView getRealVout: p_vout];
704 var_Get( p_vout->p_vlc, "drawable", &value_drawable );
706 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
707 var_Create( p_vout, "macosx-fill", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
708 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
709 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
710 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
711 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
712 var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
715 /* We only wait for NSApp to initialise if we're not embedded (as in the
716 * case of the Mozilla plugin). We can tell whether we're embedded or not
717 * by examining the "drawable" value: if it's zero, we're running in the
718 * main Mac intf; if it's non-zero, we're embedded. */
719 if( value_drawable.i_int == 0 )
721 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
722 for( i_timeout = 20 ; i_timeout-- ; )
726 msleep( INTF_IDLE_SLEEP );
732 /* No MacOS X intf, unable to communicate with MT */
733 msg_Err( p_vout, "no MacOS X interface present" );
738 if ( VLCIntf && !(p_vout->b_fullscreen) &&
739 !(var_GetBool( p_real_vout, "macosx-background" )) &&
740 var_GetBool( p_vout, "macosx-embedded") )
742 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
748 /* No embedded vout is available */
749 if( o_return == nil )
752 bzero( &null_rect, sizeof( NSRect ) );
753 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
755 [o_return setVout: p_vout subView: view frame: s_frame];
761 /*****************************************************************************
762 * VLCDetachedVoutView implementation
763 *****************************************************************************/
764 @implementation VLCDetachedVoutView
766 - (id)initWithFrame: (NSRect)frameRect
768 [super initWithFrame: frameRect];
769 i_time_mouse_last_moved = 0;
773 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
774 frame: (NSRect *) s_arg_frame
776 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
777 i_time_mouse_last_moved = mdate();
778 o_window = [[VLCWindow alloc] initWithVout: p_arg_vout view: self
781 [view setFrame: [self frame]];
783 if( var_GetBool( p_real_vout, "video-on-top" ) )
785 [o_window setLevel: NSStatusWindowLevel];
789 [o_window setAcceptsMouseMovedEvents: TRUE];
795 [o_window closeWindow];
796 [o_window setAcceptsMouseMovedEvents: NO];
797 i_time_mouse_last_moved = 0;
801 - (void)mouseMoved:(NSEvent *)o_event
803 i_time_mouse_last_moved = mdate();
804 [super mouseMoved: o_event];
807 - (void)hideMouse:(BOOL)b_hide
811 NSView *o_contents = [o_window contentView];
813 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
814 ml = [o_contents convertPoint:ml fromView:nil];
815 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
817 if( b_hide && b_inside )
819 [NSCursor setHiddenUntilMouseMoves: YES];
823 [NSCursor setHiddenUntilMouseMoves: NO];
830 if( p_vout->b_fullscreen )
832 if( mdate() - i_time_mouse_last_moved > 3000000 )
834 [self hideMouse: YES];
839 [self hideMouse: NO];
845 /*****************************************************************************
846 * VLCEmbeddedVoutView implementation
847 *****************************************************************************/
849 @implementation VLCEmbeddedVoutView
851 - (id)initWithFrame: (NSRect)frameRect
853 [super initWithFrame: frameRect];
855 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
859 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
860 frame: (NSRect *) s_arg_frame
864 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
867 o_window = [self window];
868 [o_window makeKeyAndOrderFront: self];
869 [o_window setAcceptsMouseMovedEvents: TRUE];
871 if( var_GetBool( p_real_vout, "video-on-top" ) )
873 [o_window setLevel: NSStatusWindowLevel];
876 [view setFrameSize: [self frame].size];
881 - (void)setUsed: (BOOL)b_new_used
894 [o_window setAcceptsMouseMovedEvents: NO];
895 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
901 @implementation VLCDetachedEmbeddedVoutView
903 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
904 frame: (NSRect *) s_arg_frame
906 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
910 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
912 [self scaleWindowWithFactor: 1.0];
913 [o_window makeKeyAndOrderFront: self];
920 [o_window orderOut: self];
926 /*****************************************************************************
927 * VLCWindow implementation
928 *****************************************************************************/
929 @implementation VLCWindow
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_vlc, "video-device" );
961 b_black = var_GetBool( p_real_vout->p_vlc, "macosx-black" );
963 /* Find out on which screen to open the window */
964 if( i_device <= 0 || i_device > (int)[o_screens count] )
966 /* No preference specified. Use the main screen */
967 o_screen = [NSScreen mainScreen];
968 i_device = [o_screens indexOfObject: o_screen];
969 if( o_screen == [o_screens objectAtIndex: 0] )
970 b_menubar_screen = VLC_TRUE;
975 o_screen = [o_screens objectAtIndex: i_device];
976 b_menubar_screen = ( i_device == 0 );
979 if( p_vout->b_fullscreen )
981 CGDisplayFadeReservationToken token;
982 NSRect screen_rect = [o_screen frame];
983 screen_rect.origin.x = screen_rect.origin.y = 0;
985 /* Creates a window with size: screen_rect on o_screen */
986 [self initWithContentRect: screen_rect
987 styleMask: NSBorderlessWindowMask
988 backing: NSBackingStoreBuffered
989 defer: YES screen: o_screen];
991 if( var_GetBool( p_real_vout, "macosx-black" ) )
992 if( b_black == VLC_TRUE )
994 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
995 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true );
996 CGReleaseDisplayFadeReservation( token );
998 for( i = 0 ; i < [o_screens count]; i++)
1002 CGDirectDisplayID displayID;
1003 CGGammaValue redMin, redMax, redGamma,
1004 greenMin, greenMax, greenGamma,
1005 blueMin, blueMax, blueGamma;
1007 CGDisplayCount dspyCnt;
1010 if( i == (unsigned int)i_device ) continue;
1012 screen_rect = [[o_screens objectAtIndex: i] frame];
1014 gPoint.x = screen_rect.origin.x;
1015 gPoint.y = screen_rect.origin.y;
1016 CGGetDisplaysWithPoint( gPoint, 1, &(dispSettings.displayID), &dspyCnt);
1017 CGGetDisplayTransferByFormula(
1018 dispSettings.displayID,
1019 &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma,
1020 &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma,
1021 &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma );
1022 CGSetDisplayTransferByFormula(
1023 dispSettings.displayID,
1024 dispSettings.redMin, 0, dispSettings.redGamma,
1025 dispSettings.greenMin, 0, dispSettings.greenGamma,
1026 dispSettings.blueMin, 0, dispSettings.blueGamma );
1029 if( b_menubar_screen )
1031 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
1033 if( b_black == VLC_TRUE )
1035 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1036 CGDisplayFade( token, 2 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1037 CGReleaseDisplayFadeReservation( token);
1040 else if( var_GetBool( p_real_vout, "macosx-background" ) )
1042 NSRect screen_rect = [o_screen frame];
1043 screen_rect.origin.x = screen_rect.origin.y = 0;
1045 /* Creates a window with size: screen_rect on o_screen */
1046 [self initWithContentRect: screen_rect
1047 styleMask: NSBorderlessWindowMask
1048 backing: NSBackingStoreBuffered
1049 defer: YES screen: o_screen];
1051 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1055 unsigned int i_stylemask = NSTitledWindowMask |
1056 NSMiniaturizableWindowMask |
1057 NSClosableWindowMask |
1058 NSResizableWindowMask;
1063 s_rect.size.width = p_vout->i_window_width;
1064 s_rect.size.height = p_vout->i_window_height;
1071 [self initWithContentRect: s_rect
1072 styleMask: i_stylemask
1073 backing: NSBackingStoreBuffered
1074 defer: YES screen: o_screen];
1076 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1084 [self makeKeyAndOrderFront: nil];
1085 [self setReleasedWhenClosed: YES];
1087 /* We'll catch mouse events */
1088 [self makeFirstResponder: o_view];
1090 /* Add the view. It's automatically resized to fit the window */
1091 [self setContentView: o_view];
1095 b_init_ok = VLC_TRUE;
1104 - (void) closeWindow
1106 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1108 [self setContentView: NULL];
1109 [self performSelectorOnMainThread: @selector(closeReal:)
1110 withObject: NULL waitUntilDone: NO];
1113 - (id) closeReal: (id) sender
1115 if( b_black == VLC_TRUE )
1117 CGDisplayFadeReservationToken token;
1118 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1119 CGDisplayFade( token, 2, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1120 CGReleaseDisplayFadeReservation( token);
1121 CGDisplayRestoreColorSyncSettings();
1123 SetSystemUIMode( kUIModeNormal, 0);
1133 - (BOOL)canBecomeKeyWindow
1138 /* Sometimes crashes VLC....
1139 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1141 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1144 /* This is actually the same as VLCControls::stop. */
1146 - (BOOL)windowShouldClose:(id)sender
1148 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1150 if( p_playlist == NULL )
1155 playlist_Stop( p_playlist );
1156 vlc_object_release( p_playlist );
1158 /* The window will be closed by the intf later. */