mirror of https://github.com/mpv-player/mpv
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:
parent
7fff1b6c10
commit
4d6601924a
|
@ -143,13 +143,12 @@ class Window: NSWindow, NSWindowDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func window(_ window: NSWindow, startCustomAnimationToEnterFullScreenWithDuration duration: TimeInterval) {
|
func window(_ window: NSWindow, startCustomAnimationToEnterFullScreenWithDuration duration: TimeInterval) {
|
||||||
var newFrame = targetScreen!.frame
|
|
||||||
let cRect = contentRect(forFrameRect: frame)
|
let cRect = contentRect(forFrameRect: frame)
|
||||||
newFrame.size.height = newFrame.size.height - (frame.size.height - cRect.size.height)
|
var intermediateFrame = aspectFit(rect: cRect, in: targetScreen!.frame)
|
||||||
let intermediateFrame = aspectFit(rect: cRect, in: newFrame)
|
intermediateFrame = frameRect(forContentRect: intermediateFrame)
|
||||||
|
|
||||||
NSAnimationContext.runAnimationGroup({ (context) -> Void in
|
NSAnimationContext.runAnimationGroup({ (context) -> Void in
|
||||||
context.duration = duration-0.1
|
context.duration = duration - 0.05
|
||||||
window.animator().setFrame(intermediateFrame, display: true)
|
window.animator().setFrame(intermediateFrame, display: true)
|
||||||
}, completionHandler: { })
|
}, completionHandler: { })
|
||||||
}
|
}
|
||||||
|
@ -158,10 +157,9 @@ class Window: NSWindow, NSWindowDelegate {
|
||||||
let newFrame = calculateWindowPosition(for: targetScreen!, withoutBounds: targetScreen == screen)
|
let newFrame = calculateWindowPosition(for: targetScreen!, withoutBounds: targetScreen == screen)
|
||||||
let intermediateFrame = aspectFit(rect: newFrame, in: screen!.frame)
|
let intermediateFrame = aspectFit(rect: newFrame, in: screen!.frame)
|
||||||
setFrame(intermediateFrame, display: true)
|
setFrame(intermediateFrame, display: true)
|
||||||
cocoaCB.layer.display()
|
|
||||||
|
|
||||||
NSAnimationContext.runAnimationGroup({ (context) -> Void in
|
NSAnimationContext.runAnimationGroup({ (context) -> Void in
|
||||||
context.duration = duration-0.1
|
context.duration = duration - 0.05
|
||||||
window.animator().setFrame(newFrame, display: true)
|
window.animator().setFrame(newFrame, display: true)
|
||||||
}, completionHandler: { })
|
}, completionHandler: { })
|
||||||
}
|
}
|
||||||
|
@ -170,13 +168,13 @@ class Window: NSWindow, NSWindowDelegate {
|
||||||
isInFullscreen = true
|
isInFullscreen = true
|
||||||
cocoaCB.flagEvents(VO_EVENT_FULLSCREEN_STATE)
|
cocoaCB.flagEvents(VO_EVENT_FULLSCREEN_STATE)
|
||||||
cocoaCB.updateCusorVisibility()
|
cocoaCB.updateCusorVisibility()
|
||||||
endAnimation()
|
endAnimation(frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
func windowDidExitFullScreen(_ notification: Notification) {
|
func windowDidExitFullScreen(_ notification: Notification) {
|
||||||
isInFullscreen = false
|
isInFullscreen = false
|
||||||
cocoaCB.flagEvents(VO_EVENT_FULLSCREEN_STATE)
|
cocoaCB.flagEvents(VO_EVENT_FULLSCREEN_STATE)
|
||||||
endAnimation()
|
endAnimation(calculateWindowPosition(for: targetScreen!, withoutBounds: targetScreen == screen))
|
||||||
}
|
}
|
||||||
|
|
||||||
func windowDidFailToEnterFullScreen(_ window: NSWindow) {
|
func windowDidFailToEnterFullScreen(_ window: NSWindow) {
|
||||||
|
@ -191,7 +189,14 @@ class Window: NSWindow, NSWindowDelegate {
|
||||||
endAnimation()
|
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
|
isAnimating = false
|
||||||
cocoaCB.isShuttingDown = false
|
cocoaCB.isShuttingDown = false
|
||||||
}
|
}
|
||||||
|
@ -275,7 +280,10 @@ class Window: NSWindow, NSWindowDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func setFrame(_ frameRect: NSRect, display flag: Bool) {
|
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 {
|
if keepAspect {
|
||||||
contentAspectRatio = unfsContentFrame!.size
|
contentAspectRatio = unfsContentFrame!.size
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,9 @@ class CocoaCB: NSObject {
|
||||||
layer.setVideo(true)
|
layer.setVideo(true)
|
||||||
|
|
||||||
if self.mpv.getBoolProperty("fullscreen") {
|
if self.mpv.getBoolProperty("fullscreen") {
|
||||||
window.toggleFullScreen(nil)
|
DispatchQueue.main.async {
|
||||||
|
self.window.toggleFullScreen(nil)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
window.isMovableByWindowBackground = true
|
window.isMovableByWindowBackground = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue