feat: snap launcher on release at upper-third alignment
This commit is contained in:
@@ -3,20 +3,20 @@ import Foundation
|
||||
import Testing
|
||||
|
||||
@Test
|
||||
func launcherAlignmentCentersWindowEdgesOnOffsetDisplaysAndTracksWindowSize() {
|
||||
func launcherAlignmentPositionsWindowEdgesOnOffsetDisplaysAndTracksWindowSize() {
|
||||
let display = CGRect(x: -1920, y: 40, width: 1920, height: 1040)
|
||||
let window = CGRect(x: -1500, y: 400, width: 750, height: 474)
|
||||
let window = CGRect(x: -1500, y: 450, 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.targetFrame == CGRect(x: -1335, y: 398, 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))
|
||||
#expect(resized.targetFrame == CGRect(x: -1380, y: 372, 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)
|
||||
let target = CGPoint(x: 375, y: 326)
|
||||
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))
|
||||
@@ -31,7 +31,7 @@ func launcherAlignmentSnapsAxesIndependentlyAtBothThresholdBoundaries() {
|
||||
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)
|
||||
let window = CGRect(x: 375 + offset, y: 326 + offset, width: 750, height: 474)
|
||||
#expect(LauncherAlignment(windowFrame: window, visibleFrame: display).snappedOrigin == window.origin)
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ func launcherAlignmentReleasesOutsideEitherSideOfTheSnapThreshold() {
|
||||
@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 window = CGRect(x: 390, y: 280, 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))
|
||||
#expect(alignment.targetFrame == CGRect(x: 381, y: 285, width: 750, height: 474))
|
||||
#expect(alignment.snappedOrigin == CGPoint(x: 381, y: 285))
|
||||
let placed = CGRect(origin: alignment.snappedOrigin, size: window.size)
|
||||
#expect(LauncherAlignment(windowFrame: placed, visibleFrame: display).snappedOrigin == placed.origin)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user