Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160import ParcelAnimationimport ParcelCoreimport Testing
@testable import ParcelEngine
extension ParcelEngineMotionTests { @Test func explicitFloatReadbacksSurviveEngineEchoesWhileAnotherWindowIsHeld() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1]) try harness.add([2], app: secondEngineApp) try harness.finishMotion() let window = WindowID(rawValue: 1) let other = WindowID(rawValue: 2) harness.engine.send(.focusChanged(window)) try harness.scheduler.runReady() harness.world.behaviors[engineApp] = .init(minimumSize: Size(width: 1000, height: 620)) harness.world.deferWrites = true harness.world.emitsEngineEchoes = true let baseline = harness.world.writes(for: window).count harness.engine.send(.commandIssued(.toggleFloat)) try harness.scheduler.runReady() try harness.finishMotion() let initialReceipts = harness.world.pendingWriteCount #expect(initialReceipts > 0) harness.engine.pointerIsDown = true harness.engine.dragging.insert(other) for _ in 0..<initialReceipts { try harness.world.completeNextWrite() } #expect(harness.engine.explicitFloatPlacements[window] != nil) #expect(harness.engine.manualCommandFrames[window] == Rect(x: 100, y: 90, width: 1000, height: 620)) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.pendingWriteCount == 1) try harness.world.completeNextWrite() try harness.scheduler.runReady() let expected = Rect(x: 100, y: 90, width: 1000, height: 620) #expect(harness.engine.snapshot.state.frames[window] == expected) #expect(harness.engine.snapshot.state.observedFrames[window] == expected) #expect(harness.world.frames[window] == expected) #expect(harness.world.writes(for: window).count - baseline == 2) #expect(harness.engine.explicitFloatPlacements[window] == nil) #expect(harness.engine.pointerIsDown && harness.engine.dragging.contains(other)) harness.engine.pointerIsDown = false harness.engine.dragging.remove(other) await harness.engine.stop() }
@Test(arguments: [true, false]) func explicitFloatCentersAnUnknownAcceptedMinimumOnlyAfterReadback(automatic: Bool) async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1]) try harness.finishMotion() let window = WindowID(rawValue: 1) harness.engine.send(.focusChanged(window)) try harness.scheduler.runReady() let before = try #require(harness.engine.snapshot.state.frames[window]) let observedBefore = try #require(harness.engine.snapshot.state.observedFrames[window]) let undoCount = harness.engine.snapshot.state.undoHistory?.count(for: window) ?? 0 harness.engine.setAutomaticTilingEnabled(automatic) harness.world.behaviors[engineApp] = .init(minimumSize: Size(width: 1000, height: 620)) harness.world.deferWrites = true let baselineWrites = harness.world.writes(for: window).count harness.engine.send(.commandIssued(.toggleFloat)) try harness.scheduler.runReady() try harness.finishMotion() let requested = try #require(harness.engine.snapshot.state.frames[window]) #expect(harness.world.pendingWriteCount == 1) #expect(harness.engine.snapshot.state.observedFrames[window] == observedBefore) try harness.world.completeNextWrite() let firstAccepted = try #require(harness.world.frames[window]) let centered = Rect(x: 100, y: 90, width: 1000, height: 620) #expect(firstAccepted.size == centered.size && firstAccepted.origin == requested.origin) #expect(harness.engine.manualCommandFrames[window] == centered) #expect(harness.engine.snapshot.state.frames[window] == requested) #expect(harness.engine.snapshot.state.observedFrames[window] == observedBefore) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.pendingWriteCount == 1) #expect(harness.world.writes(for: window).last?.frame == centered) #expect(harness.engine.snapshot.state.frames[window] == requested) try harness.world.completeNextWrite() #expect(harness.engine.snapshot.state.frames[window] == requested) #expect(harness.engine.manualCommandFrames[window] == centered) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.frames[window] == centered) #expect(harness.engine.snapshot.state.observedFrames[window] == centered) #expect(harness.engine.manualCommandFrames[window] == nil) #expect(harness.engine.explicitFloatPlacements[window] == nil) #expect(harness.world.writes(for: window).count - baselineWrites == 2) #expect(harness.engine.snapshot.state.undoHistory?.count(for: window) == undoCount + 1) #expect(harness.engine.isAutomaticTilingEnabled == automatic) harness.world.deferWrites = false harness.engine.send(.commandIssued(.undo)) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.engine.snapshot.state.windows[window]?.isFloating == false) #expect(harness.engine.snapshot.state.frames[window] == before) #expect(harness.world.frames[window] == before) await harness.engine.stop() }
@Test func explicitFloatAdoptsARefusedCenterAfterOneCorrection() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1]) try harness.finishMotion() let window = WindowID(rawValue: 1) harness.engine.send(.focusChanged(window)) try harness.scheduler.runReady() harness.world.behaviors[engineApp] = .init( minimumSize: Size(width: 1000, height: 620), positionOffset: Point(x: 25, y: 10)) let baseline = harness.world.writes(for: window).count harness.engine.send(.commandIssued(.toggleFloat)) try harness.scheduler.runReady() try harness.finishMotion() try harness.finishMotion() let accepted = Rect(x: 125, y: 100, width: 1000, height: 620) #expect(harness.engine.snapshot.state.frames[window] == accepted) #expect(harness.engine.snapshot.state.observedFrames[window] == accepted) #expect(harness.world.frames[window] == accepted) #expect(harness.world.writes(for: window).count - baseline == 2) #expect(harness.engine.explicitFloatPlacements[window] == nil) #expect(harness.engine.manualCommandFrames[window] == nil) let settledWrites = harness.world.writes.count try harness.finishMotion() #expect(harness.world.writes.count == settledWrites) await harness.engine.stop() }
@Test func userDragCancelsExplicitFloatRecenteringAndLateReceipt() async throws { let harness = try EngineHarness() try await harness.start() try harness.add([1]) try harness.finishMotion() let window = WindowID(rawValue: 1) harness.engine.send(.focusChanged(window)) try harness.scheduler.runReady() harness.world.deferWrites = true harness.engine.send(.commandIssued(.toggleFloat)) try harness.scheduler.runReady() try harness.finishMotion() #expect(harness.world.pendingWriteCount == 1) let oldTarget = try #require(harness.engine.snapshot.state.frames[window]) let userFrame = Rect(x: 80, y: 100, width: 500, height: 400) harness.world.userFrame(window, frame: userFrame) try harness.scheduler.runReady() #expect(harness.engine.explicitFloatPlacements[window] == nil) #expect(harness.engine.manualCommandFrames[window] == nil) try harness.world.completeNextWrite( receipt: EngineWriteReceipt(frames: [WindowFrame(window: window, frame: oldTarget)], duration: 0.001)) try harness.scheduler.runReady() #expect(harness.engine.snapshot.state.frames[window] == userFrame) #expect(harness.engine.snapshot.state.observedFrames[window] == userFrame) #expect(harness.world.frames[window] == userFrame) await harness.engine.stop() }}