Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113import AppKitimport Foundationimport ParcelCoreimport Testing
@testable import ParcelTestSupport
extension RealAppEndToEndTests { @Test func pointerOpenedMenuCountTwoRetilesFixtureThroughTheMenuAction() async throws { try await withSession { session in let (fixture, _) = try await session.addFixture(arguments: [ "--windows", "3", "--title", "Menu Count Fixture", ]) try await session.startApp() let before = try await session.settledWindows(for: fixture, count: 3) let workspace = try await session.workspace(for: before) let usable = try E2EScreenGeometry.visibleFrame(displayID: workspace.id.display) try await session.command("e2e-menu", workspace.id.display, "2") if ProcessInfo.processInfo.environment["PARCEL_E2E_CAPTURE_MENU"] == "1" { let screenshot = session.directory.appendingPathComponent("menu.png") let png = try Data(contentsOf: screenshot) let bitmap = try #require(NSBitmapImageRep(data: png)) #expect(bitmap.pixelsWide > 200 && bitmap.pixelsHigh > 200) let evidence = FileManager.default.temporaryDirectory.appendingPathComponent( "parcel-menu-\(UUID()).png") try png.write(to: evidence, options: .atomic) try FileHandle.standardError.write(contentsOf: Data("Native menu screenshot: \(evidence.path)\n".utf8)) } try await waitUntil("menu count two arranges two fixture tiles") { let windows = try await session.windows(for: fixture) let result = try await session.workspace(for: windows) let frames = try session.frames(for: fixture) return result.tiles?.tileCount == 2 && frames.count == 3 && menuHasTwoTiles(frames, in: usable) } } }
@Test func pointerOpenedMenuChangesOnlyItsDisplayWhileAnotherDisplayIsFocused() async throws { guard NSScreen.screens.count >= 2 else { try FileHandle.standardError.write( contentsOf: Data("Skipped multi-display menu e2e: connect a second display.\n".utf8)) return } let otherScreen = NSScreen.screens[1] let otherBounds = E2EScreenGeometry.windowServerFrame( otherScreen.visibleFrame, mainDisplayHeight: CGDisplayBounds(CGMainDisplayID()).height) try await withSession { session in let (target, _) = try await session.addFixture(arguments: [ "--windows", "3", "--title", "Pointer Target Fixture", ]) let (other, ready) = try await session.addFixture(arguments: [ "--windows", "3", "--title", "Focused Display Fixture", ]) for window in ready.windows { _ = try await other.control( FixtureControl( action: "frame", window: window.index, x: otherBounds.minX + 80 + Double(window.index * 10), y: otherBounds.minY + 80, width: 360, height: 240)) } try await session.startApp() let targetWindows = try await session.settledWindows(for: target, count: 3) let otherWindows = try await session.settledWindows(for: other, count: 3) let targetWorkspace = try await session.workspace(for: targetWindows) let otherWorkspace = try await session.workspace(for: otherWindows) #expect(targetWorkspace.id.display != otherWorkspace.id.display) let focused = try #require(ready.windows.first) _ = try await other.control(FixtureControl(action: "focus", window: focused.index)) try await waitUntil("other display owns the focused fixture window") { try await session.windows(for: other).contains { $0.id == UInt32(focused.number) && $0.focused } } let unchangedFrames = try session.frames(for: other) let usable = try E2EScreenGeometry.visibleFrame(displayID: targetWorkspace.id.display) try await session.command("e2e-menu", targetWorkspace.id.display, "2") try await waitUntil("real pointer activation changes only the clicked workspace") { let windows = try await session.windows(for: target) let workspace = try await session.workspace(for: windows) let frames = try session.frames(for: target) return workspace.tiles?.tileCount == 2 && frames.count == 3 && menuHasTwoTiles(frames, in: usable) } #expect(try session.frames(for: other) == unchangedFrames) let afterOther = try await session.workspace(for: session.windows(for: other)) #expect(afterOther.layout == otherWorkspace.layout) #expect(afterOther.tiles == otherWorkspace.tiles) #expect(afterOther.windows == otherWorkspace.windows) #expect(try await session.windows(for: other).contains { $0.id == UInt32(focused.number) && $0.focused }) } }}
private func menuHasTwoTiles(_ observed: [UInt32: Rect], in usable: Rect) -> Bool { let distinct = observed.values.reduce(into: [Rect]()) { frames, frame in if !frames.contains(where: { framesMatch($0, frame) }) { frames.append(frame) } } guard distinct.count == 2 else { return false } let x = usable.minX + 20 let y = usable.minY + 20 let width = usable.size.width - 40 let height = usable.size.height - 40 if usable.size.height > usable.size.width { let frames = distinct.sorted { $0.minY < $1.minY } let first = frames[0].size.height return framesMatch(frames[0], Rect(x: x, y: y, width: width, height: first)) && framesMatch(frames[1], Rect(x: x, y: y + first + 12, width: width, height: height - first - 12)) } let frames = distinct.sorted { $0.minX < $1.minX } let first = frames[0].size.width return framesMatch(frames[0], Rect(x: x, y: y, width: first, height: height)) && framesMatch(frames[1], Rect(x: x + first + 12, y: y, width: width - first - 12, height: height))}