fix: preserve video aspect ratio while resizing queue window
This commit is contained in:
@@ -4,6 +4,7 @@ import QuartzCore
|
||||
@MainActor
|
||||
final class CompactWindowController: NSObject {
|
||||
var onChange: (() -> Void)?
|
||||
var normalVideoLayout: (() -> (aspect: Double, sidebarWidth: CGFloat)?)?
|
||||
private(set) var isCompact = false
|
||||
private(set) var isTransitioning = false
|
||||
static let transitionDuration: TimeInterval = 0.25
|
||||
@@ -211,6 +212,23 @@ final class CompactWindowController: NSObject {
|
||||
let responds = MainActor.assumeIsolated { original?.responds(to: selector) ?? false }
|
||||
return responds ? original : nil
|
||||
}
|
||||
func windowWillResize(_ sender: NSWindow, to proposedSize: NSSize) -> NSSize {
|
||||
let proposed = original?.windowWillResize?(sender, to: proposedSize) ?? proposedSize
|
||||
guard let owner, !owner.isCompact, !owner.isTransitioning,
|
||||
!sender.styleMask.contains(.fullScreen),
|
||||
let layout = owner.normalVideoLayout?(),
|
||||
layout.aspect.isFinite, layout.aspect > 0 else { return proposed }
|
||||
// The sidebar stays fixed-width; only the video area is aspect-locked.
|
||||
let chrome = sender.frame.height - sender.contentRect(forFrameRect: sender.frame).height
|
||||
let widthDriven = abs(proposed.width - sender.frame.width) >=
|
||||
abs(proposed.height - sender.frame.height) * layout.aspect
|
||||
let minimumHeight = max(sender.minSize.height - chrome,
|
||||
(sender.minSize.width - layout.sidebarWidth) / layout.aspect)
|
||||
let height = max(minimumHeight, widthDriven
|
||||
? (proposed.width - layout.sidebarWidth) / layout.aspect
|
||||
: proposed.height - chrome)
|
||||
return NSSize(width: height * layout.aspect + layout.sidebarWidth, height: height + chrome)
|
||||
}
|
||||
|
||||
func windowDidFailToEnterFullScreen(_ window: NSWindow) {
|
||||
owner?.fullScreenFailed()
|
||||
|
||||
Reference in New Issue
Block a user