1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2005 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>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27 *****************************************************************************/
29 /*****************************************************************************
31 *****************************************************************************/
32 #include <errno.h> /* ENOMEM */
33 #include <stdlib.h> /* free() */
34 #include <string.h> /* strerror() */
36 /* BeginFullScreen, EndFullScreen */
37 #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( var_Get( p_real_vout, "video-on-top", &val )>=0 && val.b_bool)
363 val.b_bool = VLC_FALSE;
367 val.b_bool = VLC_TRUE;
369 var_Set( p_real_vout, "video-on-top", val );
372 - (void)toggleFullscreen
375 var_Get( p_real_vout, "fullscreen", &val );
376 val.b_bool = !val.b_bool;
377 var_Set( p_real_vout, "fullscreen", val );
383 var_Get( p_real_vout, "fullscreen", &val );
384 return( val.b_bool );
389 vout_Control( p_real_vout, VOUT_SNAPSHOT );
394 /* Disable Screensaver */
395 UpdateSystemActivity( UsrActivity );
403 - (void)keyDown:(NSEvent *)o_event
407 unsigned int i_pressed_modifiers = 0;
410 i_pressed_modifiers = [o_event modifierFlags];
412 if( i_pressed_modifiers & NSShiftKeyMask )
413 val.i_int |= KEY_MODIFIER_SHIFT;
414 if( i_pressed_modifiers & NSControlKeyMask )
415 val.i_int |= KEY_MODIFIER_CTRL;
416 if( i_pressed_modifiers & NSAlternateKeyMask )
417 val.i_int |= KEY_MODIFIER_ALT;
418 if( i_pressed_modifiers & NSCommandKeyMask )
419 val.i_int |= KEY_MODIFIER_COMMAND;
421 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
425 /* Escape should always get you out of fullscreen */
426 if( key == (unichar) 0x1b )
428 if( [self isFullscreen] )
430 [self toggleFullscreen];
433 else if ( key == ' ' )
436 val.i_int = config_GetInt( p_vout, "key-play-pause" );
437 var_Set( p_vout->p_vlc, "key-pressed", val );
441 val.i_int |= CocoaKeyToVLC( key );
442 var_Set( p_vout->p_vlc, "key-pressed", val );
447 [super keyDown: o_event];
451 - (void)mouseDown:(NSEvent *)o_event
457 switch( [o_event type] )
459 case NSLeftMouseDown:
461 var_Get( p_vout, "mouse-button-down", &val );
463 var_Set( p_vout, "mouse-button-down", val );
468 [super mouseDown: o_event];
474 - (void)otherMouseDown:(NSEvent *)o_event
480 switch( [o_event type] )
482 case NSOtherMouseDown:
484 var_Get( p_vout, "mouse-button-down", &val );
486 var_Set( p_vout, "mouse-button-down", val );
491 [super mouseDown: o_event];
497 - (void)rightMouseDown:(NSEvent *)o_event
503 switch( [o_event type] )
505 case NSRightMouseDown:
507 var_Get( p_vout, "mouse-button-down", &val );
509 var_Set( p_vout, "mouse-button-down", val );
514 [super mouseDown: o_event];
520 - (void)mouseUp:(NSEvent *)o_event
526 switch( [o_event type] )
531 b_val.b_bool = VLC_TRUE;
532 var_Set( p_vout, "mouse-clicked", b_val );
534 var_Get( p_vout, "mouse-button-down", &val );
536 var_Set( p_vout, "mouse-button-down", val );
541 [super mouseUp: o_event];
547 - (void)otherMouseUp:(NSEvent *)o_event
553 switch( [o_event type] )
557 var_Get( p_vout, "mouse-button-down", &val );
559 var_Set( p_vout, "mouse-button-down", val );
564 [super mouseUp: o_event];
570 - (void)rightMouseUp:(NSEvent *)o_event
576 switch( [o_event type] )
580 var_Get( p_vout, "mouse-button-down", &val );
582 var_Set( p_vout, "mouse-button-down", val );
587 [super mouseUp: o_event];
593 - (void)mouseDragged:(NSEvent *)o_event
595 [self mouseMoved: o_event];
598 - (void)otherMouseDragged:(NSEvent *)o_event
600 [self mouseMoved: o_event];
603 - (void)rightMouseDragged:(NSEvent *)o_event
605 [self mouseMoved: o_event];
608 - (void)mouseMoved:(NSEvent *)o_event
616 s_rect = [o_view bounds];
617 ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
618 b_inside = [o_view mouse: ml inRect: s_rect];
623 unsigned int i_width, i_height, i_x, i_y;
625 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
626 (unsigned int)s_rect.size.height,
627 &i_x, &i_y, &i_width, &i_height );
629 val.i_int = ( ((int)ml.x) - i_x ) *
630 p_vout->render.i_width / i_width;
631 var_Set( p_vout, "mouse-x", val );
633 if( [[o_view className] isEqualToString: @"VLCGLView"] )
635 val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
636 p_vout->render.i_height / i_height;
640 val.i_int = ( ((int)ml.y) - i_y ) *
641 p_vout->render.i_height / i_height;
643 var_Set( p_vout, "mouse-y", val );
645 val.b_bool = VLC_TRUE;
646 var_Set( p_vout, "mouse-moved", val );
649 [super mouseMoved: o_event];
652 - (BOOL)acceptsFirstResponder
657 - (BOOL)becomeFirstResponder
662 - (BOOL)resignFirstResponder
664 /* We need to stay the first responder or we'll miss some
669 /* Class methods used by the different vout modules */
671 + (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
673 /* p_real_vout: the vout we have to use to check for video-on-top
674 and a few other things. If we are the QuickTime output, it's us.
675 It we are the OpenGL provider, it is our parent. */
676 if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
678 return (vout_thread_t *) p_vout->p_parent;
687 + (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
688 frame: (NSRect *)s_frame
690 vlc_value_t value_drawable;
693 vout_thread_t * p_real_vout = [VLCVoutView getRealVout: p_vout];
695 var_Get( p_vout->p_vlc, "drawable", &value_drawable );
697 var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
698 var_Create( p_vout, "macosx-fill", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
699 var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
700 var_Create( p_vout, "macosx-opaqueness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
701 var_Create( p_vout, "macosx-background", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
702 var_Create( p_vout, "macosx-black", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
703 var_Create( p_vout, "macosx-embedded", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
706 /* We only wait for NSApp to initialise if we're not embedded (as in the
707 * case of the Mozilla plugin). We can tell whether we're embedded or not
708 * by examining the "drawable" value: if it's zero, we're running in the
709 * main Mac intf; if it's non-zero, we're embedded. */
710 if( value_drawable.i_int == 0 )
712 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
713 for( i_timeout = 20 ; i_timeout-- ; )
717 msleep( INTF_IDLE_SLEEP );
723 /* No MacOS X intf, unable to communicate with MT */
724 msg_Err( p_vout, "no MacOS X interface present" );
729 if ( VLCIntf && !(p_vout->b_fullscreen) &&
730 !(var_GetBool( p_real_vout, "macosx-background" )) &&
731 var_GetBool( p_vout, "macosx-embedded") )
733 o_return = [[[VLCMain sharedInstance] getEmbeddedList]
739 /* No embedded vout is available */
740 if( o_return == nil )
743 bzero( &null_rect, sizeof( NSRect ) );
744 o_return = [[VLCDetachedVoutView alloc] initWithFrame: null_rect ];
746 [o_return setVout: p_vout subView: view frame: s_frame];
752 /*****************************************************************************
753 * VLCDetachedVoutView implementation
754 *****************************************************************************/
755 @implementation VLCDetachedVoutView
757 - (id)initWithFrame: (NSRect)frameRect
759 [super initWithFrame: frameRect];
760 i_time_mouse_last_moved = 0;
764 - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
765 frame: (NSRect *) s_arg_frame
767 BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
768 i_time_mouse_last_moved = mdate();
769 o_window = [[VLCWindow alloc] initWithVout: p_arg_vout view: self
772 [view setFrame: [self frame]];
773 [o_window setAcceptsMouseMovedEvents: TRUE];
779 [o_window closeWindow];
780 [o_window setAcceptsMouseMovedEvents: NO];
781 i_time_mouse_last_moved = 0;
785 - (void)mouseMoved:(NSEvent *)o_event
787 i_time_mouse_last_moved = mdate();
788 [super mouseMoved: o_event];
791 - (void)hideMouse:(BOOL)b_hide
795 NSView *o_contents = [o_window contentView];
797 ml = [o_window convertScreenToBase:[NSEvent mouseLocation]];
798 ml = [o_contents convertPoint:ml fromView:nil];
799 b_inside = [o_contents mouse: ml inRect: [o_contents bounds]];
801 if( b_hide && b_inside )
803 [NSCursor setHiddenUntilMouseMoves: YES];
807 [NSCursor setHiddenUntilMouseMoves: NO];
814 if( p_vout->b_fullscreen )
816 if( mdate() - i_time_mouse_last_moved > 3000000 )
818 [self hideMouse: YES];
823 [self hideMouse: NO];
829 /*****************************************************************************
830 * VLCEmbeddedVoutView implementation
831 *****************************************************************************/
833 @implementation VLCEmbeddedVoutView
835 - (id)initWithFrame: (NSRect)frameRect
837 [super initWithFrame: frameRect];
839 [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
843 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
844 frame: (NSRect *) s_arg_frame
848 b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
851 o_window = [self window];
852 [o_window makeKeyAndOrderFront: self];
853 [o_window setAcceptsMouseMovedEvents: TRUE];
854 [view setFrameSize: [self frame].size];
859 - (void)setUsed: (BOOL)b_new_used
872 [o_window setAcceptsMouseMovedEvents: NO];
873 [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
879 @implementation VLCDetachedEmbeddedVoutView
881 - (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
882 frame: (NSRect *) s_arg_frame
884 BOOL b_return = [super setVout: p_arg_vout subView: view frame: s_arg_frame];
888 [o_window setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
890 [self scaleWindowWithFactor: 1.0];
891 [o_window makeKeyAndOrderFront: self];
898 [o_window orderOut: self];
904 /*****************************************************************************
905 * VLCWindow implementation
906 *****************************************************************************/
907 @implementation VLCWindow
909 - (id) initWithVout: (vout_thread_t *) vout view: (VLCVoutView *) view
910 frame: (NSRect *) frame
916 [self performSelectorOnMainThread: @selector(initReal:)
917 withObject: NULL waitUntilDone: YES];
927 - (id)initReal: (id) sender
929 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
930 NSArray *o_screens = [NSScreen screens];
932 vlc_bool_t b_menubar_screen = VLC_FALSE;
935 b_init_ok = VLC_FALSE;
937 p_fullscreen_state = NULL;
938 p_real_vout = [VLCVoutView getRealVout: p_vout];
939 i_device = var_GetInteger( p_real_vout->p_vlc, "video-device" );
941 /* Find out on which screen to open the window */
942 if( i_device <= 0 || i_device > (int)[o_screens count] )
944 /* No preference specified. Use the main screen */
945 o_screen = [NSScreen mainScreen];
946 i_device = [o_screens indexOfObject: o_screen];
947 if( o_screen == [o_screens objectAtIndex: 0] )
948 b_menubar_screen = VLC_TRUE;
953 o_screen = [o_screens objectAtIndex: i_device];
954 b_menubar_screen = ( i_device == 0 );
957 if( p_vout->b_fullscreen )
959 CGDisplayFadeReservationToken token;
960 NSRect screen_rect = [o_screen frame];
961 screen_rect.origin.x = screen_rect.origin.y = 0;
963 /* Creates a window with size: screen_rect on o_screen */
964 [self initWithContentRect: screen_rect
965 styleMask: NSBorderlessWindowMask
966 backing: NSBackingStoreBuffered
967 defer: YES screen: o_screen];
969 if( var_GetBool( p_real_vout, "macosx-black" ) )
971 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
972 CGDisplayFade( token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true );
973 CGReleaseDisplayFadeReservation( token );
975 for( i = 0 ; i < [o_screens count]; i++)
979 CGDirectDisplayID displayID;
980 CGGammaValue redMin, redMax, redGamma,
981 greenMin, greenMax, greenGamma,
982 blueMin, blueMax, blueGamma;
984 CGDisplayCount dspyCnt;
987 if( i == (unsigned int)i_device ) continue;
989 screen_rect = [[o_screens objectAtIndex: i] frame];
991 gPoint.x = screen_rect.origin.x;
992 gPoint.y = screen_rect.origin.y;
993 CGGetDisplaysWithPoint( gPoint, 1, &(dispSettings.displayID), &dspyCnt);
994 CGGetDisplayTransferByFormula(
995 dispSettings.displayID,
996 &dispSettings.redMin, &dispSettings.redMax, &dispSettings.redGamma,
997 &dispSettings.greenMin, &dispSettings.greenMax, &dispSettings.greenGamma,
998 &dispSettings.blueMin, &dispSettings.blueMax, &dispSettings.blueGamma );
999 CGSetDisplayTransferByFormula(
1000 dispSettings.displayID,
1001 dispSettings.redMin, 0, dispSettings.redGamma,
1002 dispSettings.greenMin, 0, dispSettings.greenGamma,
1003 dispSettings.blueMin, 0, dispSettings.blueGamma );
1006 if( b_menubar_screen )
1008 BeginFullScreen( &p_fullscreen_state, NULL, 0, 0,
1009 NULL, NULL, fullScreenAllowEvents );
1011 if( var_GetBool( p_real_vout, "macosx-black" ) )
1013 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1014 CGDisplayFade( token, 2 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1015 CGReleaseDisplayFadeReservation( token);
1018 else if( var_GetBool( p_real_vout, "macosx-background" ) )
1020 NSRect screen_rect = [o_screen frame];
1021 screen_rect.origin.x = screen_rect.origin.y = 0;
1023 /* Creates a window with size: screen_rect on o_screen */
1024 [self initWithContentRect: screen_rect
1025 styleMask: NSBorderlessWindowMask
1026 backing: NSBackingStoreBuffered
1027 defer: YES screen: o_screen];
1029 [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
1033 unsigned int i_stylemask = NSTitledWindowMask |
1034 NSMiniaturizableWindowMask |
1035 NSClosableWindowMask |
1036 NSResizableWindowMask;
1041 s_rect.size.width = p_vout->i_window_width;
1042 s_rect.size.height = p_vout->i_window_height;
1049 [self initWithContentRect: s_rect
1050 styleMask: i_stylemask
1051 backing: NSBackingStoreBuffered
1052 defer: YES screen: o_screen];
1054 [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
1056 if( var_GetBool( p_real_vout, "video-on-top" ) )
1058 [self setLevel: NSStatusWindowLevel];
1067 [self makeKeyAndOrderFront: nil];
1068 [self setReleasedWhenClosed: YES];
1070 /* We'll catch mouse events */
1071 [self makeFirstResponder: o_view];
1073 /* Add the view. It's automatically resized to fit the window */
1074 [self setContentView: o_view];
1078 b_init_ok = VLC_TRUE;
1087 - (void) closeWindow
1089 /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
1091 [self setContentView: NULL];
1092 [self performSelectorOnMainThread: @selector(closeReal:)
1093 withObject: NULL waitUntilDone: NO];
1096 - (id) closeReal: (id) sender
1098 if( p_fullscreen_state )
1099 EndFullScreen( p_fullscreen_state, 0 );
1100 if( var_GetBool( p_vout, "macosx-black" ) )
1102 CGDisplayFadeReservationToken token;
1103 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1104 CGDisplayFade( token, 2, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false );
1105 CGReleaseDisplayFadeReservation( token);
1106 CGDisplayRestoreColorSyncSettings();
1117 - (BOOL)canBecomeKeyWindow
1122 /* Sometimes crashes VLC....
1123 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
1125 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
1128 /* This is actually the same as VLCControls::stop. */
1130 - (BOOL)windowShouldClose:(id)sender
1132 playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1134 if( p_playlist == NULL )
1139 playlist_Stop( p_playlist );
1140 vlc_object_release( p_playlist );
1142 /* The window will be closed by the intf later. */