feat: remember manually resized compact window width

This commit is contained in:
2026-10-12 16:52:47 +02:00
parent 750c20507c
commit 1f12660936
4 changed files with 68 additions and 14 deletions
+14 -6
View File
@@ -57,13 +57,16 @@ final class CompactWindowController: NSObject {
private var videoAspect = 16.0 / 9.0
private var fittedAspect: Double?
private let reduceMotion: () -> Bool
private let defaults: UserDefaults
private static let widthKey = "compactWindowWidth"
private var frameAnimating = false
private var frameAnimationGeneration: UInt64 = 0
init(snappingEnabled: Bool = true,
init(snappingEnabled: Bool = true, defaults: UserDefaults = .standard,
reduceMotion: @escaping () -> Bool = { NSWorkspace.shared.accessibilityDisplayShouldReduceMotion }) {
self.snappingEnabled = snappingEnabled
self.reduceMotion = reduceMotion
self.defaults = defaults
super.init()
}
@@ -91,7 +94,7 @@ final class CompactWindowController: NSObject {
window.delegate = proxy
for name in [NSWindow.willEnterFullScreenNotification, NSWindow.didEnterFullScreenNotification,
NSWindow.willExitFullScreenNotification, NSWindow.didExitFullScreenNotification,
NSWindow.willCloseNotification] {
NSWindow.willCloseNotification, NSWindow.didEndLiveResizeNotification] {
NotificationCenter.default.addObserver(self, selector: #selector(windowNotification(_:)),
name: name, object: window)
}
@@ -137,6 +140,10 @@ final class CompactWindowController: NSObject {
@objc private func windowNotification(_ notification: Notification) {
switch notification.name {
case NSWindow.didEndLiveResizeNotification:
guard isCompact, !isTransitioning, let window,
window.frame.width.isFinite, window.frame.width > 0 else { return }
defaults.set(Double(window.frame.width), forKey: Self.widthKey)
case NSWindow.willEnterFullScreenNotification:
fullScreenTransition = .entering
setState(compact: isCompact, transitioning: true)
@@ -366,9 +373,10 @@ final class CompactWindowController: NSObject {
let visibleFrame = visibleFrame(for: window)
let usable = Self.usableFrame(visibleFrame)
let aspect = videoAspect
var frame = Self.initialFrame(aspect: videoAspect, visibleFrame: visibleFrame)
let savedWidth = initial ? defaults.double(forKey: Self.widthKey) : Double(window.frame.width)
let width = savedWidth.isFinite && savedWidth > 0 ? CGFloat(savedWidth) : 320
var frame = Self.initialFrame(aspect: videoAspect, visibleFrame: visibleFrame, width: width)
if !initial {
frame.size = Self.compactSize(aspect: videoAspect, width: window.frame.width, available: usable.size)
frame.origin.x = min(max(window.frame.minX, usable.minX), usable.maxX - frame.width)
frame.origin.y = min(max(window.frame.minY, usable.minY), usable.maxY - frame.height)
}
@@ -383,9 +391,9 @@ final class CompactWindowController: NSObject {
}
}
nonisolated static func initialFrame(aspect: Double, visibleFrame: NSRect) -> NSRect {
nonisolated static func initialFrame(aspect: Double, visibleFrame: NSRect, width: CGFloat) -> NSRect {
let usable = usableFrame(visibleFrame)
let size = compactSize(aspect: aspect, width: 320, available: usable.size)
let size = compactSize(aspect: aspect, width: width, available: usable.size)
return NSRect(x: usable.maxX - size.width, y: usable.maxY - size.height, width: size.width, height: size.height)
}