Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178import Foundationimport ParcelConfigimport ParcelCoreimport Testing
@Suite("Snap motion")@MainActorstruct SnapMotionTests { @Test(arguments: [false, true]) func snapUsesMotionUnlessReduced(reduceMotion: Bool) async throws { let harness = try EngineHarness(configuration: engineConfiguration(glide: true)) try await harness.start() try harness.add([1, 2]) try harness.finishMotion() harness.engine.setReduceMotion(reduceMotion)
let focused = try #require(harness.engine.snapshot.state.focusedWindow) let before = try #require(harness.engine.snapshot.state.frames[focused]) harness.engine.send(.commandIssued(.snap(.almostMaximize))) try harness.scheduler.runReady() let target = try #require(harness.engine.snapshot.state.frames[focused]) #expect(target != before) #expect(harness.links.runningCount == (reduceMotion ? 0 : 1)) if !reduceMotion { try harness.finishMotion() } try harness.scheduler.advance(by: 0.1) #expect(harness.world.frames[focused] == target) await harness.engine.stop() }
@Test(arguments: [false, true]) func floatingSnapAdjustmentsNeverStartTileMinimumProbes(clampsUp: Bool) async throws { let harness = try EngineHarness() try await harness.start() let window = engineWindow(1, floating: true) harness.world.appear(window) try harness.scheduler.runReady() harness.world.behaviors[engineApp] = clampsUp ? .init(minimumSize: Size(width: 650, height: 200)) : .init(widthMultiple: 7) harness.engine.send(.commandIssued(.snap(.leftHalf))) try harness.scheduler.runReady() let writes = harness.world.writes.count #expect(harness.engine.snapshot.state.windows[window.id]?.minimum == nil) #expect(harness.engine.learnedMinimums.isEmpty) #expect(harness.engine.isIdle) #expect(harness.scheduler.pendingCount == 0) try harness.scheduler.advance(by: 1) #expect(harness.world.writes.count == writes) #expect(harness.engine.learnedMinimums.isEmpty) await harness.engine.stop() }
@Test(arguments: [false, true]) func snapCyclesAndRestoresThroughAppClampsAndLateNotifications(clampsUp: Bool) async throws { let harness = try EngineHarness() try await harness.start() let window = engineWindow(1, floating: true) harness.world.appear(window) try harness.scheduler.runReady() let original = try #require(harness.engine.snapshot.state.frames[window.id]) harness.world.behaviors[engineApp] = clampsUp ? FakeEngineWorld.Behavior(minimumSize: Size(width: 650, height: 200)) : FakeEngineWorld.Behavior(widthMultiple: 7) harness.world.emitsEngineEchoes = true
for width in [600.0, 800, 400] { harness.engine.send(.commandIssued(.snap(.leftHalf))) try harness.scheduler.runReady() let target = Rect(width: width, height: 800) #expect(harness.engine.snapshot.state.frames[window.id] == target) let accepted = try #require(harness.world.frames[window.id]) let expectedWidth = clampsUp ? max(650, width) : (width / 7).rounded(.down) * 7 #expect(accepted == Rect(width: expectedWidth, height: 800)) let history = harness.engine.snapshot.state.snapHistory #expect(history?[window.id]?.previousFrame == original)
let revision = harness.engine.snapshot.revision harness.world.userFrame(window.id, frame: accepted, resized: true, origin: .unknown) try harness.scheduler.runReady() #expect(harness.engine.snapshot.revision == revision) #expect(harness.engine.snapshot.state.snapHistory == history)
try harness.scheduler.advance(by: 0.6) let lateAdjustment = Rect(width: accepted.size.width + 7, height: 800) harness.world.userFrame(window.id, frame: lateAdjustment, resized: true, origin: .unknown) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.observedFrames[window.id] == lateAdjustment) #expect(harness.engine.snapshot.state.frames[window.id] == lateAdjustment) #expect(harness.engine.snapshot.state.snapHistory == history) } harness.engine.send(.commandIssued(.snap(.restore))) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.frames[window.id] == original) #expect(harness.world.writes(for: window.id).last?.frame == original) #expect(harness.engine.snapshot.state.snapHistory?[window.id] == nil) #expect(!harness.log.reports.contains(.noSnapHistory)) #expect(harness.log.platformFailures.isEmpty) await harness.engine.stop() }
@Test(arguments: [false, true]) func snapRestoreAfterRealUserMoveKeepsTiledOriginWindowFloating(resized: Bool) async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1, 2]) let focused = try #require(harness.engine.snapshot.focusedWindow) let original = try #require(harness.engine.snapshot.state.frames[focused]) harness.engine.send(.commandIssued(.snap(.leftHalf))) try harness.scheduler.advance(by: 0.1) #expect(harness.world.frames[focused] == Rect(width: 600, height: 800)) let history = harness.engine.snapshot.state.snapHistory let moved = Rect(x: 300, y: 200, width: resized ? 500 : 600, height: resized ? 300 : 800) harness.world.userFrame(focused, frame: moved, resized: resized) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.frames[focused] == moved) #expect(harness.engine.snapshot.state.snapHistory == history) harness.engine.send(.commandIssued(.snap(.restore))) try harness.scheduler.advance(by: 0.1) #expect(harness.engine.snapshot.state.frames[focused] == original) #expect(harness.world.frames[focused] == original) #expect(harness.engine.snapshot.state.windows[focused]?.isFloating == true) #expect(harness.engine.snapshot.state.workspaces[engineWorkspace]?.tree?.windows.contains(focused) == false) #expect(!harness.log.reports.contains(.noSnapHistory)) await harness.engine.stop() }
@Test(arguments: [SnapAction.nextDisplay, .previousDisplay, .restore]) func snapMaterializesConfiguredMissingDestinationWorkspace(action: SnapAction) async throws { let secondSpace = SpaceID(rawValue: 2) let secondKey = WorkspaceKey(display: secondEngineDisplay, space: secondSpace) let secondFrame = Rect(x: 1200, y: 100, width: 900, height: 600) var initial = engineInitialState() initial.activeSpaces[secondEngineDisplay] = secondSpace if action == .restore { initial.snapHistory = [ WindowID(rawValue: 1): SnapHistory( previousFrame: Rect(x: 1210, y: 110, width: 300, height: 200), previousWorkspace: secondKey, previousDisplayFrame: secondFrame) ] } var configuration = engineConfiguration() let uuid = try #require(UUID(uuidString: secondEngineDisplay.rawValue)) configuration.layout.displays[uuid] = LayoutValues( defaultLayout: .rows, ratio: 0.7, gaps: LayoutGaps(inner: 20, outer: 10), reserved: ReservedEdges(top: 30, right: 60, bottom: 50, left: 40), windowCap: 3) let harness = try EngineHarness(configuration: configuration, initialState: initial) try await harness.start() let window = engineWindow(1, floating: true) harness.world.appear(window, frame: Rect(x: 100, y: 100, width: 300, height: 200)) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.workspaces[secondKey] == nil) harness.world.emit( .observed( .displaySetChanged([ Display(id: engineDisplay, frame: engineScreen), Display(id: secondEngineDisplay, frame: secondFrame), ]))) harness.engine.send(.commandIssued(.snap(action))) try harness.scheduler.runReady() let workspace = try #require(harness.engine.snapshot.state.workspaces[secondKey]) #expect(workspace.layout == .rows) #expect(workspace.ratio == MainRatio(0.7)) #expect(workspace.windowCap == 3) #expect(workspace.gaps == Gaps(inner: 20, outer: Insets(10))) #expect(workspace.reservedEdges == Insets(top: 30, left: 40, bottom: 50, right: 60)) #expect(harness.engine.snapshot.state.workspace(containing: window.id) == secondKey) let expected = action == .restore ? Rect(x: 1250, y: 140, width: 300, height: 200) : Rect(x: 1303, y: 190, width: 300, height: 200) #expect(harness.engine.snapshot.state.frames[window.id] == expected) #expect(harness.world.frames[window.id] == expected) #expect(harness.log.reports.isEmpty) await harness.engine.stop() }}