fix: persist window centers and preserve them across tool size changes
This commit is contained in:
@@ -48,17 +48,21 @@ func launcherAlignmentKeepsFractionalDisplayCentersOnAStableWindowGrid() {
|
||||
}
|
||||
|
||||
@Test
|
||||
func launcherPositionRestoresVisibleOriginsAndFallsBackForMissingOrOffscreenPositions() {
|
||||
func launcherPositionRestoresCentersAcrossSizesAndFallsBackForMissingOrOffscreenPositions() {
|
||||
let display = CGRect(x: -1920, y: 40, width: 1920, height: 1040)
|
||||
let size = CGSize(width: 750, height: 474)
|
||||
let origin = CGPoint(x: -1500, y: 450)
|
||||
#expect(LauncherAlignment.restoredFrame(savedOrigin: origin, windowSize: size, visibleFrame: display)
|
||||
== CGRect(origin: origin, size: size))
|
||||
for invalid: CGPoint? in [nil, CGPoint(x: 0, y: 450), CGPoint(x: -1500, y: 39), CGPoint(x: CGFloat.nan, y: 450)] {
|
||||
#expect(LauncherAlignment.restoredFrame(savedOrigin: invalid, windowSize: size, visibleFrame: display)
|
||||
let center = CGPoint(x: -1125, y: 687)
|
||||
for windowSize in [size, CGSize(width: 570, height: 404), CGSize(width: 840, height: 620)] {
|
||||
let frame = LauncherAlignment.restoredFrame(savedCenter: center, windowSize: windowSize, visibleFrame: display)
|
||||
#expect(CGPoint(x: frame.midX, y: frame.midY) == center)
|
||||
#expect(frame.size == windowSize)
|
||||
}
|
||||
for invalid: CGPoint? in [nil, CGPoint(x: 0, y: 687), CGPoint(x: -1125, y: 276),
|
||||
CGPoint(x: CGFloat.nan, y: 687), CGPoint(x: -1125, y: CGFloat.infinity)] {
|
||||
#expect(LauncherAlignment.restoredFrame(savedCenter: invalid, windowSize: size, visibleFrame: display)
|
||||
== CGRect(x: -1335, y: 398, width: 750, height: 474))
|
||||
}
|
||||
let small = CGRect(x: 0, y: 40, width: 800, height: 500)
|
||||
#expect(LauncherAlignment.restoredFrame(savedOrigin: nil, windowSize: size, visibleFrame: small)
|
||||
#expect(LauncherAlignment.restoredFrame(savedCenter: nil, windowSize: size, visibleFrame: small)
|
||||
== CGRect(x: 25, y: 40, width: 750, height: 474))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user