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
+50 -4
View File
@@ -69,14 +69,14 @@ struct CompactWindowChecks {
"overlapping magnetic zones choose the closest edge, not first edge")
let usableScreen = NSRect(x: -1_200, y: 50, width: 1_200, height: 800)
let landscape = CompactWindowController.initialFrame(aspect: 16.0 / 9.0, visibleFrame: usableScreen)
let landscape = CompactWindowController.initialFrame(aspect: 16.0 / 9.0, visibleFrame: usableScreen, width: 320)
try require(sameFrame(landscape, NSRect(x: -336, y: 654, width: 320, height: 180)),
"16:9 enters at top right with 320pt width and 16pt inset")
let portrait = CompactWindowController.initialFrame(aspect: 9.0 / 16.0, visibleFrame: usableScreen)
let portrait = CompactWindowController.initialFrame(aspect: 9.0 / 16.0, visibleFrame: usableScreen, width: 320)
try require(sameFrame(portrait, NSRect(x: -336, y: 834 - 5_120.0 / 9.0, width: 320, height: 5_120.0 / 9.0)),
"portrait preserves exact aspect when it fits")
for aspect in [16.0 / 9.0, 9.0 / 16.0, 100.0, 0.01] {
let frame = CompactWindowController.initialFrame(aspect: aspect, visibleFrame: usableScreen)
let frame = CompactWindowController.initialFrame(aspect: aspect, visibleFrame: usableScreen, width: 320)
try require(frame.origin.x.isFinite && frame.origin.y.isFinite
&& frame.width.isFinite && frame.height.isFinite,
"initial geometry is finite for aspect \(aspect)")
@@ -89,7 +89,7 @@ struct CompactWindowChecks {
"aspect \(aspect) stays anchored top right")
}
let smallScreen = NSRect(x: 0, y: 0, width: 300, height: 400)
let bounded = CompactWindowController.initialFrame(aspect: 16.0 / 9.0, visibleFrame: smallScreen)
let bounded = CompactWindowController.initialFrame(aspect: 16.0 / 9.0, visibleFrame: smallScreen, width: 320)
try require(sameFrame(bounded, NSRect(x: 16, y: 233.25, width: 268, height: 150.75)),
"target width shrinks to usable bounds without distorting ordinary aspect")
}
@@ -404,6 +404,51 @@ struct CompactWindowChecks {
try replacement.restored()
}
static func rememberedSize() throws {
let suite = "terebi.compact-size-check.\(UUID().uuidString)"
let defaults = UserDefaults(suiteName: suite)!
defer { defaults.removePersistentDomain(forName: suite) }
let fixture = try WindowFixture()
let controller = CompactWindowController(defaults: defaults, reduceMotion: { true })
defer {
controller.restore(resumeFullScreen: false, animated: false)
fixture.window.close()
}
controller.attach(fixture.window)
controller.toggle(aspect: 16.0 / 9.0)
var resized = fixture.window.frame
resized.size = NSSize(width: 240, height: 135)
fixture.window.setFrame(resized, display: false)
NotificationCenter.default.post(name: NSWindow.didEndLiveResizeNotification, object: fixture.window)
controller.restore(resumeFullScreen: false)
try fixture.restored()
controller.toggle(aspect: 16.0 / 9.0)
try require(close(fixture.window.frame.width, 240) && close(fixture.window.frame.height, 135),
"reentering compact restores the manually chosen size")
// Programmatic fitting and ordinary-window resizing must not replace the preference.
resized.size = NSSize(width: 320, height: 180)
fixture.window.setFrame(resized, display: false)
controller.updateAspect(4.0 / 3.0)
controller.restore(resumeFullScreen: false)
try fixture.restored()
NotificationCenter.default.post(name: NSWindow.didEndLiveResizeNotification, object: fixture.window)
let replacement = try WindowFixture()
let reloaded = CompactWindowController(defaults: UserDefaults(suiteName: suite)!, reduceMotion: { true })
defer {
reloaded.restore(resumeFullScreen: false, animated: false)
replacement.window.close()
}
reloaded.attach(replacement.window)
reloaded.toggle(aspect: 4.0 / 3.0)
try require(close(replacement.window.frame.width, 240) && close(replacement.window.frame.height, 180),
"a recreated controller restores preferred width with the new video's aspect")
try replacement.compact(aspect: 4.0 / 3.0)
reloaded.restore(resumeFullScreen: false)
try replacement.restored()
}
static func reducedMotion() throws {
let fixture = try WindowFixture()
let controller = CompactWindowController(reduceMotion: { true })
@@ -431,6 +476,7 @@ struct CompactWindowChecks {
try geometry()
try windowBehavior()
try reducedMotion()
try rememberedSize()
print("Compact window checks passed")
}
}