Commit dee3bc7b authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

macosx: Fix the detached window. Fix fullscreen. Use a borderless window.

The borderless window is nicer IMO. Feel free to object, but this also saves some overhead with fullscreen changing.
parent bd4bd54d
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#import "misc.h"
/***************************************************************************** /*****************************************************************************
* VLCEmbeddedList interface * VLCEmbeddedList interface
*****************************************************************************/ *****************************************************************************/
...@@ -110,26 +111,21 @@ ...@@ -110,26 +111,21 @@
/***************************************************************************** /*****************************************************************************
* VLCVoutWindow interface * VLCVoutWindow interface
*****************************************************************************/ *****************************************************************************/
@interface VLCVoutWindow : NSWindow @interface VLCVoutWindow : VLCWindow
{ {
vout_thread_t * p_vout; vout_thread_t * p_vout;
VLCVoutView * o_view; VLCVoutView * o_view;
NSRect * s_frame; NSRect * s_frame;
vout_thread_t * p_real_vout;
bool b_init_ok; bool b_init_ok;
bool b_black; BOOL fullscreen;
bool b_embedded; NSRect initialFrame;
} }
- (id) initWithVout: (vout_thread_t *) p_vout view: (VLCVoutView *) view - (id) initWithVout: (vout_thread_t *) p_vout view: (VLCVoutView *) view
frame: (NSRect *) s_frame; frame: (NSRect *) s_frame;
- (id)initMainThread: (id) sender; - (id)initMainThread: (id) sender;
- (void)close; - (void)leaveFullscreen;
- (void)closeWindow; - (void)enterFullscreen;
- (id)closeMainThread: (id) sender;
- (id)getVoutView; - (id)getVoutView;
- (BOOL)windowShouldClose:(id)sender;
@end @end
...@@ -513,7 +513,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -513,7 +513,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
- (void)mouseDown:(NSEvent *)o_event - (void)mouseDown:(NSEvent *)o_event
{ {
vlc_value_t val; vlc_value_t val;
NSLog(@"Down");
if( p_vout ) if( p_vout )
{ {
if( ( [o_event type] == NSLeftMouseDown ) && if( ( [o_event type] == NSLeftMouseDown ) &&
...@@ -801,6 +801,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -801,6 +801,11 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
return self; return self;
} }
- (BOOL)mouseDownCanMoveWindow
{
return YES;
}
- (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view - (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
frame: (NSRect *) s_arg_frame frame: (NSRect *) s_arg_frame
{ {
...@@ -808,22 +813,19 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -808,22 +813,19 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
i_time_mouse_last_moved = mdate(); i_time_mouse_last_moved = mdate();
o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self o_window = [[VLCVoutWindow alloc] initWithVout: p_arg_vout view: self
frame: s_arg_frame]; frame: s_arg_frame];
[self updateTitle]; [self updateTitle];
[view setFrame: [self frame]]; if([self isFullscreen])
[o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: YES];
if( var_GetBool( p_real_vout, "video-on-top" ) ) else
{ [view setFrame: [self frame]];
[o_window setLevel: NSStatusWindowLevel];
}
[o_window setAcceptsMouseMovedEvents: TRUE];
return b_return; return b_return;
} }
- (void)closeVout - (void)closeVout
{ {
[o_window closeWindow]; [o_window performSelectorOnMainThread: @selector(close) withObject: NULL waitUntilDone: YES];
[o_window setAcceptsMouseMovedEvents: NO];
i_time_mouse_last_moved = 0; i_time_mouse_last_moved = 0;
[super closeVout]; [super closeVout];
} }
...@@ -876,27 +878,14 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -876,27 +878,14 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
- (void)enterFullscreen - (void)enterFullscreen
{ {
[super enterFullscreen]; [super enterFullscreen];
[o_window performSelectorOnMainThread: @selector(enterFullscreen) withObject: NULL waitUntilDone: NO];
if( var_GetBool( p_real_vout, "video-on-top" ) )
{
[o_window setLevel: NSNormalWindowLevel];
}
[[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
[[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
} }
- (void)leaveFullscreen - (void)leaveFullscreen
{ {
[super leaveFullscreen]; [super leaveFullscreen];
[o_window performSelectorOnMainThread: @selector(leaveFullscreen) withObject: NULL waitUntilDone: NO];
if( var_GetBool( p_real_vout, "video-on-top" ) )
{
[o_window setLevel: NSStatusWindowLevel];
}
[[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
[[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
} }
@end @end
...@@ -1035,208 +1024,123 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -1035,208 +1024,123 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
p_vout = vout; p_vout = vout;
o_view = view; o_view = view;
s_frame = frame; s_frame = frame;
b_init_ok = NO;
[self performSelectorOnMainThread: @selector(initMainThread:) [self performSelectorOnMainThread: @selector(initMainThread:)
withObject: NULL waitUntilDone: YES]; withObject: NULL waitUntilDone: YES];
if( !b_init_ok ) return b_init_ok ? self : nil;
{
return NULL;
}
return self;
} }
- (id)initMainThread: (id) sender - (id)initMainThread: (id) sender
{ {
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init]; NSRect rect;
NSArray *o_screens = [NSScreen screens]; rect.size.height = p_vout->i_window_height;
NSScreen *o_screen; rect.size.width = p_vout->i_window_width;
bool b_menubar_screen = false; rect.origin.x = rect.origin.y = 70.;
int i_device;
b_init_ok = false;
p_real_vout = [VLCVoutView getRealVout: p_vout];
i_device = var_GetInteger( p_real_vout->p_libvlc, "video-device" );
b_black = NO;
b_embedded = var_GetBool( p_vout, "embedded-video" );
/* Find out on which screen to open the window */
o_screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
if( !o_screen )
o_screen = [NSScreen mainScreen];
if( [o_screen isMainScreen] ) if( self = [super initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])
b_menubar_screen = true;
if( p_vout->b_fullscreen )
{ {
CGDisplayFadeReservationToken token; [self setBackgroundColor:[NSColor blackColor]];
NSRect screen_rect = [o_screen frame]; [self setHasShadow:YES];
screen_rect.origin.x = screen_rect.origin.y = 0; [self setMovableByWindowBackground: YES];
[self center];
b_black = var_GetBool( p_vout, "macosx-black" ); [self makeKeyAndOrderFront: self];
[self setReleasedWhenClosed: YES];
/* move the FSPanel to front in case that it is currently shown
* this won't and is not supposed to work when it's fading right now */ /* We'll catch mouse events */
if( [[[[VLCMain sharedInstance] getControls] getFSPanel] isDisplayed] ) [self makeFirstResponder: o_view];
[[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil]; [self setCanBecomeKeyWindow: YES];
/* tell the fspanel to move itself to front next time it's triggered */ if( var_GetBool( p_vout, "macosx-background" ) )
[[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
/* Creates a window with size: screen_rect on o_screen */
[self initWithContentRect: screen_rect
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered
defer: YES screen: o_screen];
if( b_menubar_screen )
{
SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
}
if( b_black == true )
{ {
CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token); int i_device = var_GetInteger( p_vout->p_libvlc, "video-device" );
CGDisplayFade( token, 0.6 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
[o_screen blackoutOtherScreens]; /* Find out on which screen to open the window */
NSScreen * screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
CGDisplayFade( token, 0.3 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO ); if( !screen ) screen = [NSScreen mainScreen];
CGReleaseDisplayFadeReservation( token);
}
}
else if( var_GetBool( p_vout, "macosx-background" ) )
{
NSRect screen_rect = [o_screen frame];
screen_rect.origin.x = screen_rect.origin.y = 0;
/* Creates a window with size: screen_rect on o_screen */ NSRect screen_rect = [screen frame];
[self initWithContentRect: screen_rect screen_rect.origin.x = screen_rect.origin.y = 0;
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered
defer: YES screen: o_screen];
[self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; /* Creates a window with size: screen_rect on o_screen */
} [self setFrame: screen_rect display: NO];
else
{
unsigned int i_stylemask = NSTitledWindowMask |
NSMiniaturizableWindowMask |
NSClosableWindowMask |
NSResizableWindowMask;
NSRect s_rect; [self setLevel: CGWindowLevelForKey(kCGDesktopWindowLevelKey)];
if( !s_frame ) [self setMovableByWindowBackground: NO];
{
s_rect.size.width = p_vout->i_window_width;
s_rect.size.height = p_vout->i_window_height;
} }
else if( var_GetBool( p_vout, "video-on-top" ) )
{ {
s_rect = *s_frame; [self setLevel: NSStatusWindowLevel];
} }
[self initWithContentRect: s_rect
styleMask: i_stylemask
backing: NSBackingStoreBuffered
defer: YES screen: o_screen];
[self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )]; [self setAlphaValue: var_GetFloat( p_vout, "macosx-opaqueness" )];
if( !s_frame ) /* Add the view. It's automatically resized to fit the window */
{ [self setContentView: o_view];
[self center];
}
}
[self makeKeyAndOrderFront: nil]; b_init_ok = YES;
[self setReleasedWhenClosed: YES]; }
/* We'll catch mouse events */
[self makeFirstResponder: o_view];
/* Add the view. It's automatically resized to fit the window */
[self setContentView: o_view];
[o_pool release];
b_init_ok = true;
return self; return self;
} }
- (void)close - (void)enterFullscreen
{ {
[o_view closeVout]; if( fullscreen ) return;
}
- (void)closeWindow NSScreen *screen;
{ int i_device;
/* XXX waitUntilDone = NO to avoid a possible deadlock when hitting BOOL b_black = NO;
Command-Q */
[self performSelectorOnMainThread: @selector(closeMainThread:)
withObject: NULL waitUntilDone: NO];
}
- (id)closeMainThread:(id)sender i_device = var_GetInteger( p_vout->p_libvlc, "video-device" );
{ b_black = var_GetBool( p_vout, "macosx-black" );
if( b_black == true )
/* Find out on which screen to open the window */
screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
if( !screen ) screen = [self screen];
if( b_black && [[NSScreen screens] count] > 1)
{ {
CGDisplayFadeReservationToken token; CGDisplayFadeReservationToken token;
CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token); CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
CGDisplayFade( token, 0.3 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES ); CGDisplayFade( token, 0.2 , kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES );
[self disableScreenUpdatesUntilFlush]; [screen blackoutOtherScreens];
[self orderOut: self];
CGDisplayFade( token, 0.6 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, YES ); CGDisplayFade( token, 0.1 , kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO );
CGReleaseDisplayFadeReservation( token); CGReleaseDisplayFadeReservation( token);
CGDisplayRestoreColorSyncSettings();
} }
[NSScreen unblackoutScreens];
SetSystemUIMode( kUIModeNormal, 0); [self setMovableByWindowBackground: NO];
[super close];
/* this does only work in embedded mode */
if( b_embedded == true )
[[[[VLCMain sharedInstance] getControls] getFSPanel] orderOut: self];
return NULL; /* tell the fspanel to move itself to front next time it's triggered */
} [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
[[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
- (id)getVoutView if( [screen isMainScreen] )
{ SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar);
return o_view;
}
- (BOOL)canBecomeKeyWindow initialFrame = [self frame];
{ [self setFrame:[screen frame] display:YES animate:YES];
return YES; fullscreen = YES;
} }
/* Sometimes crashes VLC.... - (void)leaveFullscreen
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
{ {
return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event]; if( !fullscreen ) return;
}*/ fullscreen = NO;
/* This is actually the same as VLCControls::stop. */ [NSScreen unblackoutScreens];
- (BOOL)windowShouldClose:(id)sender
{
playlist_t * p_playlist = pl_Yield( p_vout );
if( p_playlist == NULL )
{
return NO;
}
playlist_Stop( p_playlist ); [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
vlc_object_release( p_playlist ); SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
[self setFrame:initialFrame display:YES animate:YES];
[self setMovableByWindowBackground: YES];
}
/* The window will be closed by the intf later. */ - (id)getVoutView // FIXME Naming scheme!
return NO; {
return o_view;
} }
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment