diff options
Diffstat (limited to 'video/out/cocoa/window.m')
-rw-r--r-- | video/out/cocoa/window.m | 87 |
1 files changed, 63 insertions, 24 deletions
diff --git a/video/out/cocoa/window.m b/video/out/cocoa/window.m index 68e5222a03..1ff57acde9 100644 --- a/video/out/cocoa/window.m +++ b/video/out/cocoa/window.m @@ -49,20 +49,22 @@ styleMask:(NSUInteger)style_mask backing:(NSBackingStoreType)buffering_type defer:(BOOL)flag + screen:(NSScreen *)screen { if (self = [super initWithContentRect:content_rect styleMask:style_mask backing:buffering_type - defer:flag]) { + defer:flag + screen:screen]) { [self setBackgroundColor:[NSColor blackColor]]; [self setMinSize:NSMakeSize(50,50)]; [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary]; - self.targetScreen = [self screen]; - self.currentScreen = [self screen]; + self.targetScreen = screen; + self.currentScreen = screen; _is_animating = 0; _unfs_content_frame = [self convertRectToScreen:[[self contentView] frame]]; - _unfs_screen_frame = [[self screen] frame]; + _unfs_screen_frame = [screen frame]; } return self; } @@ -97,18 +99,28 @@ [super toggleFullScreen:sender]; if (![self.adapter isInFullScreenMode]) { - [self setStyleMask:([self styleMask] | NSWindowStyleMaskFullScreen)]; - NSRect frame = [[self targetScreen] frame]; - [self setFrame:frame display:YES]; + [self setToFullScreen]; } else { - [self setStyleMask:([self styleMask] & ~NSWindowStyleMaskFullScreen)]; - NSRect frame = [self calculateWindowPositionForScreen:[self targetScreen]]; - [self setFrame:frame display:YES]; - [self setContentAspectRatio:_unfs_content_frame.size]; - [self setCenteredContentSize:_unfs_content_frame.size]; + [self setToWindow]; } } +- (void)setToFullScreen +{ + [self setStyleMask:([self styleMask] | NSWindowStyleMaskFullScreen)]; + NSRect frame = [[self targetScreen] frame]; + [self setFrame:frame display:YES]; +} + +- (void)setToWindow +{ + [self setStyleMask:([self styleMask] & ~NSWindowStyleMaskFullScreen)]; + NSRect frame = [self calculateWindowPositionForScreen:[self targetScreen]]; + [self setFrame:frame display:YES]; + [self setContentAspectRatio:_unfs_content_frame.size]; + [self setCenteredContentSize:_unfs_content_frame.size]; +} + - (NSArray *)customWindowsToEnterFullScreenForWindow:(NSWindow *)window { return [NSArray arrayWithObject:window]; @@ -139,11 +151,13 @@ - (void)windowDidFailToEnterFullScreen:(NSWindow *)window { _is_animating = 0; + [self setToWindow]; } - (void)windowDidFailToExitFullScreen:(NSWindow *)window { _is_animating = 0; + [self setToFullScreen]; } - (void)windowDidChangeBackingProperties:(NSNotification *)notification @@ -159,8 +173,10 @@ if (!_is_animating && ![[self currentScreen] isEqual:[self screen]]) { self.previousScreen = [self screen]; } + if (![[self currentScreen] isEqual:[self screen]]) { + [self.adapter windowDidChangeScreen:notification]; + } self.currentScreen = [self screen]; - [self.adapter windowDidChangeScreen:notification]; } - (void)windowDidChangeScreenProfile:(NSNotification *)notification @@ -212,6 +228,34 @@ [self.adapter putCommand:cmd]; } +- (void)updateBorder:(int)border +{ + int borderStyle = NSWindowStyleMaskTitled|NSWindowStyleMaskClosable| + NSWindowStyleMaskMiniaturizable; + if (border) { + int window_mask = [self styleMask] & ~NSWindowStyleMaskBorderless; + window_mask |= borderStyle; + [self setStyleMask:window_mask]; + } else { + int window_mask = [self styleMask] & ~borderStyle; + window_mask |= NSWindowStyleMaskBorderless; + [self setStyleMask:window_mask]; + } + + if (![self.adapter isInFullScreenMode]) { + // XXX: workaround to force redrawing of window decoration + if (border) { + NSRect frame = [self frame]; + frame.size.width += 1; + [self setFrame:frame display:YES]; + frame.size.width -= 1; + [self setFrame:frame display:YES]; + } + + [self setContentAspectRatio:_unfs_content_frame.size]; + } +} + - (NSRect)frameRect:(NSRect)f forCenteredContentSize:(NSSize)ns { NSRect cr = [self contentRectForFrameRect:f]; @@ -259,11 +303,12 @@ - (NSRect)constrainFrameRect:(NSRect)nf toScreen:(NSScreen *)screen { - if (_is_animating) - screen = [self targetScreen]; + if (_is_animating && ![self.adapter isInFullScreenMode]) + return nf; + screen = screen ?: self.screen ?: [NSScreen mainScreen]; NSRect of = [self frame]; - NSRect vf = [screen ?: self.screen ?: [NSScreen mainScreen] visibleFrame]; + NSRect vf = [_is_animating ? [self targetScreen] : screen visibleFrame]; NSRect ncf = [self contentRectForFrameRect:nf]; // Prevent the window's titlebar from exiting the screen on the top edge. @@ -304,11 +349,6 @@ display:NO]; } -- (void)updateWindowFrame:(NSSize)newSize -{ - _unfs_content_frame = [self frameRect:_unfs_content_frame forCenteredContentSize:newSize]; -} - - (void)tryDequeueSize { if (_queued_video_size.width <= 0.0 || _queued_video_size.height <= 0.0) @@ -321,9 +361,8 @@ - (void)queueNewVideoSize:(NSSize)newSize { - if ([self.adapter isInFullScreenMode]) { - [self updateWindowFrame:newSize]; - } else { + _unfs_content_frame = [self frameRect:_unfs_content_frame forCenteredContentSize:newSize]; + if (![self.adapter isInFullScreenMode]) { if (NSEqualSizes(_queued_video_size, newSize)) return; _queued_video_size = newSize; |