feat: snap launcher to stippled edge alignment guides

This commit is contained in:
2026-10-12 12:25:18 +02:00
parent 97420f51e1
commit dc7cf07204
4 changed files with 101 additions and 12 deletions
@@ -0,0 +1,48 @@
import ConjureKit
import Foundation
import Testing
@Test
func launcherAlignmentCentersWindowEdgesOnOffsetDisplaysAndTracksWindowSize() {
let display = CGRect(x: -1920, y: 40, width: 1920, height: 1040)
let window = CGRect(x: -1500, y: 400, width: 750, height: 474)
let alignment = LauncherAlignment(windowFrame: window, visibleFrame: display)
#expect(alignment.targetFrame == CGRect(x: -1335, y: 323, width: 750, height: 474))
#expect(alignment.snappedOrigin == window.origin)
let resized = LauncherAlignment(windowFrame: CGRect(x: -1500, y: 400, width: 840, height: 500), visibleFrame: display)
#expect(resized.targetFrame == CGRect(x: -1380, y: 310, width: 840, height: 500))
}
@Test
func launcherAlignmentSnapsAxesIndependentlyAtBothThresholdBoundaries() {
let display = CGRect(x: 0, y: 0, width: 1500, height: 1000)
let target = CGPoint(x: 375, y: 263)
for offset: CGFloat in [-12, 12] {
let horizontal = LauncherAlignment(windowFrame: CGRect(x: target.x + offset, y: target.y + 40, width: 750, height: 474), visibleFrame: display)
#expect(horizontal.snappedOrigin == CGPoint(x: target.x, y: target.y + 40))
let vertical = LauncherAlignment(windowFrame: CGRect(x: target.x + 40, y: target.y + offset, width: 750, height: 474), visibleFrame: display)
#expect(vertical.snappedOrigin == CGPoint(x: target.x + 40, y: target.y))
}
let both = LauncherAlignment(windowFrame: CGRect(x: target.x - 6, y: target.y + 9, width: 750, height: 474), visibleFrame: display)
#expect(both.snappedOrigin == target)
}
@Test
func launcherAlignmentReleasesOutsideEitherSideOfTheSnapThreshold() {
let display = CGRect(x: 0, y: 0, width: 1500, height: 1000)
for offset: CGFloat in [-12.01, 12.01] {
let window = CGRect(x: 375 + offset, y: 263 + offset, width: 750, height: 474)
#expect(LauncherAlignment(windowFrame: window, visibleFrame: display).snappedOrigin == window.origin)
}
}
@Test
func launcherAlignmentKeepsFractionalDisplayCentersOnAStableWindowGrid() {
let display = CGRect(x: 0, y: 0, width: 1512, height: 949)
let window = CGRect(x: 390, y: 230, width: 750, height: 474)
let alignment = LauncherAlignment(windowFrame: window, visibleFrame: display)
#expect(alignment.targetFrame == CGRect(x: 381, y: 237, width: 750, height: 474))
#expect(alignment.snappedOrigin == CGPoint(x: 381, y: 237))
let placed = CGRect(origin: alignment.snappedOrigin, size: window.size)
#expect(LauncherAlignment(windowFrame: placed, visibleFrame: display).snappedOrigin == placed.origin)
}