Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import AppKitimport ParcelConfigimport ParcelCoreimport ParcelIPC
@MainActorfinal class AppFixtureHoverPointerInput { private let original = NSEvent.mouseLocation
func post(arguments: [String], state: State) throws { guard ProcessInfo.processInfo.environment["PARCEL_E2E"] == "1" else { throw AppFixtureDrag.rejected("Fixture hover pointer input requires e2e mode") } if arguments == ["restore"] { try move(to: CGPoint(x: original.x, y: (NSScreen.screens.first?.frame.maxY ?? 0) - original.y)) return } guard arguments.count == 2, ["move", "type"].contains(arguments[0]), let number = UInt32(arguments[1]), let window = state.windows[WindowID(rawValue: number)], NSRunningApplication(processIdentifier: window.app.pid)?.executableURL?.lastPathComponent == "FixtureApp", let key = state.workspace(containing: window.id), state.isActive(key), state.visibleWindows.contains(window.id), let frame = state.observedFrames[window.id] ?? state.frames[window.id] else { throw AppFixtureDrag.rejected("Fixture hover pointer input needs a visible fixture window") } guard NSEvent.pressedMouseButtons == 0, NSEvent.modifierFlags.intersection([.control, .option, .command, .shift, .function]).isEmpty else { throw AppFixtureDrag.rejected("Release mouse buttons and modifiers before fixture hover input") } if arguments[0] == "move" { try move(to: CGPoint(x: frame.center.xCoordinate, y: frame.center.yCoordinate)) } else { guard NSWorkspace.shared.frontmostApplication?.processIdentifier == window.app.pid, let source = CGEventSource(stateID: .privateState), let down = CGEvent(keyboardEventSource: source, virtualKey: ANSIKey.a.keyCode, keyDown: true), let up = CGEvent(keyboardEventSource: source, virtualKey: ANSIKey.a.keyCode, keyDown: false) else { throw AppFixtureDrag.rejected("Typing needs the fixture app in front") } down.post(tap: .cghidEventTap) up.post(tap: .cghidEventTap) } }
private func move(to point: CGPoint) throws { guard let event = CGEvent( mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left) else { throw AppFixtureDrag.rejected("Could not post fixture pointer movement") } event.post(tap: .cghidEventTap) }}