Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import AppKitimport CoreGraphicsimport Foundationimport ParcelCoreimport ParcelPlatformimport ParcelTestSupportimport Synchronizationimport Testing
@testable import ParcelEngine
extension AppKitTestSuite { @MainActor struct NativeMouseDisplayTests { @Test(arguments: [false, true], ["menu", "application"]) func nativeTrackingReleasesOnlyAnActuallyReleasedLegacyPointer(buttonStillDown: Bool, update: String) async throws { _ = NSApplication.shared let harness = try EngineHarness() try await harness.start() try harness.add([1, 2, 3]) let focused = try #require(harness.engine.snapshot.focusedWindow) let before = try #require(harness.world.frames[focused]) let pressed = Mutex(true) let notifications = NotificationCenter() let monitor = EnginePointerMonitor( notifications: notifications, buttonIsDown: { pressed.withLock { $0 } }) defer { monitor.stop() } try monitor.start { harness.world.emit(.pointerButton(isDown: $0)) } pressed.withLock { $0 = buttonStillDown } notifications.post( name: update == "menu" ? NSMenu.didBeginTrackingNotification : NSApplication.didUpdateNotification, object: nil) harness.engine.send(.commandIssued(.setWindowCap(2))) try harness.scheduler.runReady() try harness.finishMotion() let target = try #require(harness.engine.snapshot.state.frames[focused]) #expect(target != before) if buttonStillDown { #expect(harness.world.frames[focused] == before) pressed.withLock { $0 = false } notifications.post( name: update == "menu" ? NSMenu.didEndTrackingNotification : NSApplication.didUpdateNotification, object: nil) try harness.finishMotion() } #expect(harness.world.frames[focused] == target) #expect(harness.engine.dragging.isEmpty && !harness.engine.pointerIsDown) await harness.engine.stop() }
@Test func applicationUpdatesEmitOnlyOneReleaseAfterTrackingConsumesMouseUp() throws { _ = NSApplication.shared let pressed = Mutex(true) let notifications = NotificationCenter() let monitor = EnginePointerMonitor( notifications: notifications, buttonIsDown: { pressed.withLock { $0 } }) defer { monitor.stop() } var observed: [Bool] = [] try monitor.start { observed.append($0) } notifications.post(name: NSApplication.didUpdateNotification, object: nil) #expect(observed == [true]) pressed.withLock { $0 = false } for _ in 0..<3 { notifications.post(name: NSApplication.didUpdateNotification, object: nil) } #expect(observed == [true, false]) monitor.stop() notifications.post(name: NSApplication.didUpdateNotification, object: nil) #expect(observed == [true, false]) }
@Test func physicalAndUsableDisplayBoundsAreConvertedIndependently() throws { let uuid = UUID() let screen = ParcelPlatform.Display( id: uuid, frame: CGRect(x: -1200, y: 0, width: 1200, height: 800), visibleFrame: CGRect(x: -1200, y: 40, width: 1200, height: 735), scale: 2, isBuiltIn: false) let converted = try #require(SystemNativeEngineBackend.coreDisplays([screen]).first) let origin = CGDisplayBounds(CGMainDisplayID()).height #expect(converted.id.rawValue == uuid.uuidString) #expect(converted.frame == Rect(x: -1200, y: origin - 775, width: 1200, height: 735)) #expect(converted.physicalFrame == Rect(x: -1200, y: origin - 800, width: 1200, height: 800)) #expect(converted.isValid) } }}