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
This commit is contained in:
Akemi 2018-02-22 23:56:49 +01:00 committed by Kevin Mitchell
parent 7fff1b6c10
commit 4d6601924a
2 changed files with 21 additions and 11 deletions

View File

@ -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
}

View File

@ -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
}