Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import AppKitimport CoreGraphicsimport Foundationimport ParcelCoreimport ParcelPlatform
@MainActorenum AppFixtureBusyInput { static func post(arguments: [String], state: State) async throws { guard arguments.count == 3, arguments.allSatisfy({ $0.utf8.count <= 32 }), let number = UInt32(arguments[0]), let x = Double(arguments[1]), let y = Double(arguments[2]), x.isFinite, y.isFinite else { throw AppFixtureDrag.rejected("Busy input needs a fixture window and a bounded point") } let point = CGPoint(x: x, y: y) let geometry = try AppFixtureMouseGeometry(window: number, point: point, state: state) guard let application = NSRunningApplication(processIdentifier: geometry.pid), !application.isTerminated, application.executableURL?.lastPathComponent == "FixtureApp", NSWorkspace.shared.frontmostApplication?.processIdentifier == geometry.pid, CGPreflightPostEventAccess(), !CGEventSource.buttonState(.combinedSessionState, button: .left), CGEventSource.flagsState(.combinedSessionState).intersection( [.maskControl, .maskAlternate, .maskCommand, .maskShift]).isEmpty, try DragWindowLookup.window(at: point) == DragWindow(pid: geometry.pid, windowNumber: number), let cursor = CGEvent(source: nil)?.location else { throw AppFixtureDrag.rejected("Busy input must target the frontmost unobstructed FixtureApp") } let pid = geometry.pid let posting = Task.detached { try await Task.sleep(for: .milliseconds(150)) guard let source = CGEventSource(stateID: .privateState) else { throw AppFixtureDrag.rejected("Could not create the busy fixture event source") } for type: CGEventType in [.leftMouseDown, .leftMouseUp] { guard let event = CGEvent( mouseEventSource: source, mouseType: type, mouseCursorPosition: point, mouseButton: .left) else { throw AppFixtureDrag.rejected("Could not create busy fixture input") } event.flags = [] event.setIntegerValueField(.eventTargetUnixProcessID, value: Int64(pid)) event.setIntegerValueField(.mouseEventWindowUnderMousePointer, value: Int64(number)) event.setIntegerValueField( .mouseEventWindowUnderMousePointerThatCanHandleThisEvent, value: Int64(number)) event.setIntegerValueField(.mouseEventClickState, value: 1) event.post(tap: .cgSessionEventTap) } guard CGWarpMouseCursorPosition(cursor) == .success else { throw AppFixtureDrag.rejected("Could not restore the busy fixture cursor") } } stall() try await posting.value }
private static func stall() { Thread.sleep(forTimeInterval: 0.9) }}