Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230import AppKitimport Foundationimport ParcelConfigimport ParcelUIimport Testing
@testable import ParcelCore@testable import ParcelTestSupport
extension RealAppEndToEndTests { @Test func guidedKeyboardStepsWaitForFixtureWindowEffects() async throws { try await withSession { session in let (fixture, _) = try await session.addFixture(arguments: ["--windows", "3", "--title", "Tour Fixture"]) try await session.startApp() var state = try await liveLearningState(session, fixture: fixture) var tour = GuidedTour() tour.start(track: .keyboard, state: state, configuration: .defaults) for step in TourStep.allCases { #expect(tour.step == step) for _ in 0..<6 where tour.progress.phase == .running { let command = try #require(tour.command(state: state, configuration: .defaults)) tour.performed(.keyboard(command)) let unchanged = tour.receive(state, configuration: .defaults) #expect(!unchanged) try await session.command(command.rawValue) state = try await liveLearningState(session, fixture: fixture) let actual = try await fixture.snapshot() if let index = actual.focusedWindow, let window = actual.windows.first(where: { $0.index == index }) { tour.confirmFocus(WindowID(rawValue: window.number)) } _ = tour.receive(state, configuration: .defaults) } #expect(tour.progress.phase == .celebrating) let committed = try session.frames(for: fixture) tour.continueAfterWin(state: state, configuration: .defaults) let after = try session.frames(for: fixture) #expect(after == committed) } #expect(tour.progress.phase == .completed) } }
@Test func stackChipPanelsUseOnlyGapsAndFollowFixtureFocus() async throws { try await withSession { session in let (fixture, reply) = try await session.addFixture(arguments: [ "--windows", "3", "--title", "Chip Fixture", ]) try await session.startApp() _ = try await session.settledWindows(for: fixture, count: 3) try await session.command("set-window-cap", "1") let before = try await liveLearningState(session, fixture: fixture) let group = try #require(StackChips.groups(in: before).first) let pid = try #require(session.app).processIdentifier try await waitUntil("stack chips are in the gap") { try serverWindows().contains { panel in panel.pid == pid && panel.layer == NSWindow.Level.floating.rawValue && framesMatch( panel.bounds.frame, Rect( x: group.frame.minX, y: group.frame.minY, width: group.frame.width, height: group.frame.height)) } } let target = try #require(reply.windows.first { WindowID(rawValue: $0.number) != before.focusedWindow }) _ = try await fixture.control(FixtureControl(action: "focus", window: target.index)) try await waitUntil("fixture focus selects its chip") { let windows: [AppWindow] = try await session.query("windows") return windows.contains { $0.id == target.number && $0.focused } } let state = try await liveLearningState(session, fixture: fixture) let selectedChip = StackChips.groups(in: state).first?.chips.first(where: { $0.selected }) let selected = try #require(selectedChip) #expect(selected.window == WindowID(rawValue: target.number)) let committed = try session.frames(for: fixture) try await session.command("toggle-automatic-tiling") try await remainTrue( "Automatic tiling off keeps explicit stack controls and real frames", duration: .milliseconds(400) ) { try serverWindows().contains { panel in panel.pid == pid && panel.layer == NSWindow.Level.floating.rawValue && framesMatch( panel.bounds.frame, Rect( x: group.frame.minX, y: group.frame.minY, width: group.frame.width, height: group.frame.height)) } && session.frames(for: fixture) == committed } } }
@Test(arguments: [true, false]) func middleClickClosesOnlyItsFixtureWindowWithoutATour(automaticTiling: Bool) async throws { var configuration = E2EConfiguration() configuration.outerGap = 20 try await withSession(configuration: configuration) { session in let (fixture, _) = try await session.addFixture(arguments: ["--windows", "3", "--title", "Close Fixture"]) try await session.startApp() _ = try await session.settledWindows(for: fixture, count: 3) try await session.command("set-window-cap", "1") let before = try await liveLearningState(session, fixture: fixture) let group = try #require(StackChips.groups(in: before).first) let target = try #require(group.chips.last) if !automaticTiling { try await session.command("toggle-automatic-tiling") } try await session.command("e2e-chip-middle-click", String(target.window.rawValue)) try await waitUntil("middle click closes its fixture window") { let reply = try await fixture.snapshot() return reply.windows.count == 2 && !reply.windows.contains { $0.number == target.window.rawValue } } let after = try await session.settledWindows(for: fixture, count: 2) #expect(!after.contains { $0.id == target.window.rawValue }) } }
@Test func nativeTopGripDragCommitsOnceAndEscapeKeepsFixtureFrames() async throws { var configuration = E2EConfiguration() configuration.windowCap = 2 configuration.outerGap = 24 try await withSession(configuration: configuration) { session in let (fixture, _) = try await session.addFixture(arguments: [ "--windows", "3", "--title", "Top Grip Drag Fixture", ]) try await session.startApp() let windows = try await session.settledWindows(for: fixture, count: 3) let workspace = try await session.workspace(for: windows) let tree = try #require(workspace.tiles) let stack = try #require(tree.stacks.first { $0.windows.count == 2 }) let destination = try #require(tree.stacks.first { $0.windows.count == 1 }) let source = stack.visible let target = destination.visible let native = try await fixture.snapshot() let active = try #require(native.windows.first { $0.number == source.rawValue }) _ = try await fixture.control(FixtureControl(action: "focus", window: active.index)) try await waitUntil("the source fixture owns focus before native top-grip dragging") { let snapshot = try await fixture.snapshot() return try await session.windows(for: fixture).first(where: \.focused)?.id == source.rawValue && snapshot.windows.first { $0.number == source.rawValue }?.index == snapshot.focusedWindow && NSWorkspace.shared.frontmostApplication?.processIdentifier == fixture.process.processIdentifier } let before = try session.frames(for: fixture) let targetFrame = try #require(before[target.rawValue]) try await session.command( "e2e-hover-click", String(source.rawValue), "grip-cancel-drag", String(target.rawValue)) try await remainTrue( "Escape and the late native mouse-up preserve top-grip membership and frames", duration: .milliseconds(400) ) { let actual = try await session.workspace(for: session.windows(for: fixture)) return try actual.tiles == tree && session.frames(for: fixture) == before && NSWorkspace.shared.frontmostApplication?.processIdentifier == fixture.process.processIdentifier } try await session.command("e2e-hover-click", String(source.rawValue), "grip-drag", String(target.rawValue)) let remaining = stack.windows.filter { $0 != source } try await waitUntil("a native top-grip drag joins the chosen tile with independent native frame readback") { let actual = try await session.workspace(for: session.windows(for: fixture)) let frames = try session.frames(for: fixture) guard let stacks = actual.tiles?.stacks, let joined = stacks.first(where: { Set($0.windows) == Set(destination.windows + [source]) }), stacks.contains(where: { $0.windows == remaining }), let moved = frames[source.rawValue] else { return false } return stacks.count == 2 && joined.visible == source && framesMatch(moved, targetFrame) && remaining.allSatisfy { frames[$0.rawValue] == before[$0.rawValue] } && destination.windows.allSatisfy { frames[$0.rawValue] == before[$0.rawValue] } && NSWorkspace.shared.frontmostApplication?.processIdentifier == fixture.process.processIdentifier } try await session.command("undo") try await waitUntil("one Undo restores the top-grip drag membership and native frames") { let actual = try await session.workspace(for: session.windows(for: fixture)) return try actual.tiles == tree && session.frames(for: fixture) == before } } }
@Test func hoverDwellUsesRealTiledFramesWithoutWritingThem() async throws { try await withSession { session in let (fixture, _) = try await session.addFixture(arguments: ["--windows", "2", "--title", "Hover Fixture"]) try await session.startApp() let state = try await liveLearningState(session, fixture: fixture) let id = try #require(state.focusedWindow) let frame = try #require(state.frames[id]) let target = try #require( HoverBarModel.target(at: CGPoint(x: frame.minX + 4, y: frame.minY + 4), state: state)) let committed = try session.frames(for: fixture) var hover = HoverBarModel() hover.receive(target, at: 0, configuration: .init(delay: 0.6)) #expect(hover.phase == .pending) hover.receive(target, at: 0.6, configuration: .init(delay: 0.6)) #expect(hover.phase == .visible) #expect(try session.frames(for: fixture) == committed) hover.receive(nil, at: 0.7, configuration: .init()) #expect(hover.phase == .hidden) } }}
@MainActorprivate func liveLearningState(_ session: E2ESession, fixture: FixtureProcess) async throws -> State { let windows = try await session.settledWindows(for: fixture, count: (try await fixture.snapshot()).windows.count) let workspace = try await session.workspace(for: windows) let displays: [AppDisplay] = try await session.query("displays") let space = try #require(UInt64(workspace.id.space)) let key = WorkspaceKey(display: DisplayID(rawValue: workspace.id.display), space: SpaceID(rawValue: space)) let focused = windows.first(where: \.focused).map { WindowID(rawValue: $0.id) } var model = Workspace( key: key, layout: workspace.layout, ratio: MainRatio(workspace.ratio), gaps: Gaps( inner: session.configuration.innerGap, outer: Insets( top: session.configuration.outerGap, left: session.configuration.outerGap, bottom: session.configuration.outerGap, right: session.configuration.outerGap)), order: workspace.windows.map { WindowID(rawValue: $0) }, focus: focused) model.tree = workspace.tiles let managed = windows.map { ManagedWindow( id: WindowID(rawValue: $0.id), app: AppID(pid: $0.pid, bundleID: "fixture"), title: $0.title, isFloating: $0.floating) } var state = State( displays: displays.map { Display(id: DisplayID(rawValue: $0.id), frame: $0.frame) }, activeSpaces: [key.display: key.space], workspaces: [key: model], windows: Dictionary(uniqueKeysWithValues: managed.map { ($0.id, $0) }), focusedWindow: focused) state.activeDisplay = key.display state.frames = Dictionary( uniqueKeysWithValues: windows.compactMap { window in window.frame.map { (WindowID(rawValue: window.id), $0) } }) state.observedFrames = Dictionary( uniqueKeysWithValues: try session.frames(for: fixture).map { (WindowID(rawValue: $0.key), $0.value) }) return state}