summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2018-02-22 23:56:49 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-02-25 22:07:33 -0800
commit4d6601924a4d2df557f78f3192236d84f7a4274e (patch)
treee7d23ec5c041219cf716b7c5fb5f7e99bcc18bab
parent7fff1b6c10e53ba3139eb06a2598d1587c969741 (diff)
downloadmpv-4d6601924a4d2df557f78f3192236d84f7a4274e.tar.bz2
mpv-4d6601924a4d2df557f78f3192236d84f7a4274e.tar.xz
cocoa-cb: fix wrong fullscreen window size
even though the fullscreen animation has a shorter duration than the system wide animation (space sliding effect) there are still cases where it takes longer, eg performance issues (especially on init). furthermore the final size of the animation is usually different than the actual fullscreen size because of spect ratio differences. the actual resize to fullscreen is done automatically by cocoa itself when the actual transition to fullscreen happens (system event). so it could happen that the last animation resize happened after the actual resize to fullscreen leading to a wrongly sized frame after entering fullscreen. to prevent this we cancel the animation when entering fullscreen, we always set the proper frame size when in fullscreen and discard any other frame sizes, and to prevent some performance problems on init we push entering fullscreen to the end of the main queue to execute it when most of the init routines are done. Fixes #5525
-rw-r--r--video/out/cocoa-cb/window.swift28
-rw-r--r--video/out/cocoa_cb_common.swift4
2 files changed, 21 insertions, 11 deletions
diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift
index c93537c03a..869bfb8be6 100644
--- a/video/out/cocoa-cb/window.swift
+++ b/video/out/cocoa-cb/window.swift
@@ -143,13 +143,12 @@ class Window: NSWindow, NSWindowDelegate {
}
func window(_ window: NSWindow, startCustomAnimationToEnterFullScreenWithDuration duration: TimeInterval) {
- var newFrame = targetScreen!.frame
let cRect = contentRect(forFrameRect: frame)
- newFrame.size.height = newFrame.size.height - (frame.size.height - cRect.size.height)
- let intermediateFrame = aspectFit(rect: cRect, in: newFrame)
+ var intermediateFrame = aspectFit(rect: cRect, in: targetScreen!.frame)
+ intermediateFrame = frameRect(forContentRect: intermediateFrame)
NSAnimationContext.runAnimationGroup({ (context) -> Void in
- context.duration = duration-0.1
+ context.duration = duration - 0.05
window.animator().setFrame(intermediateFrame, display: true)
}, completionHandler: { })
}
@@ -158,10 +157,9 @@ class Window: NSWindow, NSWindowDelegate {
let newFrame = calculateWindowPosition(for: targetScreen!, withoutBounds: targetScreen == screen)
let intermediateFrame = aspectFit(rect: newFrame, in: screen!.frame)
setFrame(intermediateFrame, display: true)
- cocoaCB.layer.display()
NSAnimationContext.runAnimationGroup({ (context) -> Void in
- context.duration = duration-0.1
+ context.duration = duration - 0.05
window.animator().setFrame(newFrame, display: true)
}, completionHandler: { })
}
@@ -170,13 +168,13 @@ class Window: NSWindow, NSWindowDelegate {
isInFullscreen = true
cocoaCB.flagEvents(VO_EVENT_FULLSCREEN_STATE)
cocoaCB.updateCusorVisibility()
- endAnimation()
+ endAnimation(frame)
}
func windowDidExitFullScreen(_ notification: Notification) {
isInFullscreen = false
cocoaCB.flagEvents(VO_EVENT_FULLSCREEN_STATE)
- endAnimation()
+ endAnimation(calculateWindowPosition(for: targetScreen!, withoutBounds: targetScreen == screen))
}
func windowDidFailToEnterFullScreen(_ window: NSWindow) {
@@ -191,7 +189,14 @@ class Window: NSWindow, NSWindowDelegate {
endAnimation()
}
- func endAnimation() {
+ func endAnimation(_ newFrame: NSRect = NSZeroRect) {
+ if !NSEqualRects(newFrame, NSZeroRect) {
+ NSAnimationContext.runAnimationGroup({ (context) -> Void in
+ context.duration = 0.01
+ self.animator().setFrame(newFrame, display: true)
+ }, completionHandler: nil )
+ }
+
isAnimating = false
cocoaCB.isShuttingDown = false
}
@@ -275,7 +280,10 @@ class Window: NSWindow, NSWindowDelegate {
}
override func setFrame(_ frameRect: NSRect, display flag: Bool) {
- super.setFrame(frameRect, display: flag)
+ let newFrame = !isAnimating && isInFullscreen ? targetScreen!.frame :
+ frameRect
+ super.setFrame(newFrame, display: flag)
+
if keepAspect {
contentAspectRatio = unfsContentFrame!.size
}
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift
index 0ce06428bd..cd43195a3e 100644
--- a/video/out/cocoa_cb_common.swift
+++ b/video/out/cocoa_cb_common.swift
@@ -114,7 +114,9 @@ class CocoaCB: NSObject {
layer.setVideo(true)
if self.mpv.getBoolProperty("fullscreen") {
- window.toggleFullScreen(nil)
+ DispatchQueue.main.async {
+ self.window.toggleFullScreen(nil)
+ }
} else {
window.isMovableByWindowBackground = true
}