Files

extras

Goal

The remaining PowerToys behaviours that are neither input routing nor clipboard: keeping the other machines' screens awake while the user is active here (BlockScreenSaverOnOtherMachines), not switching away by edge while a fullscreen app has the foreground (DisableEasyMouseWhenForegroundWindowIsFullscreen + excluded apps), drawing a cursor on a controlled Mac so the user can see where the remote pointer is (DrawMouseCursor/DrawMouseEx), plus finishing two paths that exist but were never verified end-to-end (BlockMouseAtScreenCorners, MoveMouseRelatively with NextMachine) and the clipboard-transfer notifications app-ui still owes. This lane ends at CP3, after which the app is feature-complete against the PowerToys module minus README D6.

Assumptions

Confirmed against the Windows source while porting; anything that turned out differently is in the Work log and in docs/protocol.md §10.8.

  • Awake (Receiver.cs:244-249 → Common.HumanBeingDetected, Common.cs:561-572, which runs PokeMyself, :574-591). On Windows the receiver jiggles its own mouse ±9 px ten times to reset the idle timer. The port cannot: CLAUDE.md invariant 5 forbids posting input. Each Awake (21) instead renews an IOPMAssertionTypePreventUserIdleDisplaySleep assertion with a 90 s kIOPMAssertionTimeoutKey and kIOPMAssertionTimeoutActionRelease, so the display stays on while the remote user is active and the assertion lapses on its own when the beats stop (60 s cadence, §3.3). A plain Heartbeat does not renew it. Confirmed: Windows applies the sender's BlockScreenSaver (it decides whether Awake is sent at all, Common.cs:547); the receiver checks no setting, and neither do we. IOKit is imported only in MWBMac/Awake.swift.
  • Fullscreen rule (Common.IsEasyMouseSwitchAllowed, Common.cs:1638-1650, called only from Event.cs:79). Before an edge switch — never a hotkey switch, never the relative-mode NextMachine path — the Engine asks Fullscreen.frontmostIsFullscreen(excluding:displays:), but only when DisableEasyMouseWhenForegroundWindowIsFullscreen is on and this Mac currently holds the pointer (Common.cs:1646). The check takes NSWorkspace.shared.frontmostApplication, skips it when its bundle identifier, localized name or bundle file name (with or without .app) is in EasyMouseFullscreenSwitchBlockExcludedApps case-insensitively — the two spellings Common.cs:1597-1599 accepts — and otherwise asks whether that app owns an on-screen kCGWindowLayer == 0 window whose bounds equal a display's, via CGWindowListCopyWindowInfo(.optionOnScreenOnly) filtered by kCGWindowOwnerPID. Bounds need no Screen Recording grant; window names are never read. Cached 250 ms, keyed on the excluded set, so an edge storm costs one query.
  • Drawn cursor (CustomCursor.cs:71-146, fed from Receiver.cs:186-188). On the Mac being controlled, with DrawMouseCursor on, a borderless, transparent, click-through NSWindow (level = .screenSaver, ignoresMouseEvents, collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle]) shows NSCursor.arrow.image at (x+1, y+1) of the position read back after each injected move, and hides on a park, on local input and at shutdown. Deviation: Windows draws only while the real cursor is hidden or suppressed (GetCursorInfo, ci.flags != 1, CustomCursor.cs:79); macOS has no read-only equivalent and the injected moves keep the real pointer visible, so the overlay is a second marker rather than a replacement (protocol §10.8 note 4). DrawMouseEx is accepted and ignored.
  • Settings.drawMouseCursor accessor added to MWBCore/Settings.swift (authorised; app-ui's open request) and the toggle added to BehaviourPane.swift after "Hide mouse at the screen edge", the position MouseWithoutBordersPage.xaml:246-251 shows it in.
  • Corners and relative mode: verified by reading, not by running — see the Work log for the trace. Two gaps found, one fixed with a comment and a Handshake request (NextMachine is gated on EasyMouse == Enable alone, where Windows also accepts the held Ctrl/Shift Easy-Mouse key), one recorded as the clipboard lane's (HasSwitchedMachineSinceLastCopy).
  • Transfer notifications (clipboard's open request): the Engine only logged ClipboardAction.note. UIBridge.TransferNotices is the wire from there to Notifier, which already carries the ShowClipboardAndNetworkStatusMessages gate.
  • Permissions: confirmed — none of this needs a new TCC grant. IOKit assertions, CGWindowList bounds and overlay windows need nothing.

Handshakes

Consumed

  • app-engine: Engine.dispatch, Engine.pointerPosition(), EngineActions.perform(_:)/applyConfiguration(), Settings accessors, Log, EventTap.now().
  • input-capture: ScreenLayout.displays, Screens.layout, EventTap.now(), RoutingSnapshot's easy-mouse gate on .edgeCandidate (nothing changed).
  • input-inject: nothing. The Engine already knows every injected position, so FakeCursor is driven from Engine.dispatch and Injector was not touched.
  • app-ui: Notifier.post(title:body:), SettingsToggle, SettingsViewModel.binding(_:).
  • clipboard: ClipboardAction.note.

Promised (to polish)

As shipped 2026-09-16.

// MWBMac/Awake.swift — IOKit lives here and nowhere else
public final class DisplayAwake: Sendable {
    public static let timeout: TimeInterval          // 90
    public init()
    public var isAsserted: Bool { get }
    public func renew(seconds: TimeInterval = DisplayAwake.timeout)
    public func release()
}

// MWBMac/Fullscreen.swift
public enum Fullscreen {
    public static let cacheInterval: TimeInterval    // 0.25
    public static func frontmostIsFullscreen(excluding: Set<String>, displays: [CGRect]) -> Bool
    public static func invalidate()
}

// MWBMac/FakeCursor.swift
public final class FakeCursor: Sendable {            // the Engine's door
    public init()
    public func setEnabled(_ isOn: Bool)
    public func show(at point: CGPoint)              // CG coordinates
    public func hide()
}
@MainActor public final class CursorOverlay {        // the window itself
    public init()
    public func show(at point: CGPoint)
    public func hide()
}

// MWBCore/Settings.swift
public var drawMouseCursor: Bool { get set }         // "DrawMouseCursor"

// mwb/UIBridge.swift
@MainActor enum TransferNotices {
    static func install(_ notifier: Notifier?)
    static func post(_ text: String)
}

Four deviations from the shape this section sketched at planning time:

  • Fullscreen.frontmostIsFullscreen takes displays:. The sketch had it read the display list itself; passing ScreenLayout.displays in means nothing here queries CoreGraphics for geometry the Engine already holds, and it keeps the 250 ms cache honest.
  • CursorOverlay has no move(to:), and is fronted by FakeCursor. Windows has one call, ShowFakeMouseCursor(x, y), with int.MinValue meaning hide, so show(at:) + hide() is the whole surface. The overlay stays @MainActor as the brief requires; FakeCursor is the nonisolated, Sendable door the Engine actor calls, and it coalesces — the latest wanted state under a lock, at most one main-thread hop scheduled — because a controlled Mac takes up to a hundred mouse packets a second and one Task each would both allocate and arrive out of order.
  • DisplayAwake.renew() re-creates the assertion rather than extending one. Once a minute, and it means the assertion's own timeout is the only lifetime rule; an assertion we somehow fail to release cannot outlive 90 s.
  • TransferNotices is a @MainActor static rendezvous, not a property on the Engine: the Engine is an actor, Notifier is @MainActor, and there is exactly one of each per process.

Requested of input-capture (open)

  1. EventTap.easyMouseKeyDown is not published, so relative mode ignores NextMachine when Easy Mouse is set to Ctrl or Shift. Windows gates the NextMachine handler on Event.IsSwitchingByMouseEnabled() (Receiver.cs:198), which is EasyMouse == Enable or the Easy-Mouse modifier being held (Event.cs:152-155). The tap owns that second half (EventTap.swift:93, 349-353) and already applies it to .edgeCandidate, but the Engine cannot read it, so Engine.dispatch's .nextMachine case tests the setting alone. A var easyMouseKeyDown: Bool { get } on EventTap, or the flag in RoutingSnapshot, closes it. Commented at the call site; not worked around.

Requested of clipboard / app-engine (taken provisionally — the lead rules at review)

The brief authorised UIBridge.swift for the transfer notifications, but the note never leaves the Engine: ClipboardAction.note is consumed in Sources/mwb/ClipboardBridge.swift, which belongs to the clipboard lane. Three one-line additions were made there rather than silently widening the scope; revert them and the notifications are inert but nothing else changes.

  1. perform(_ actions: [ClipboardAction]), case .note: also Task { @MainActor in TransferNotices.post(text) }.
  2. clipboardFailed(_:): the same, for the bulk channel's failures (Clipboard.cs:916).
  3. commitReceivedFile(staged:name:), on success: the same, with "Received ." (Clipboard.cs:869-881).

There is no .note for a send, and none was invented: Windows' only send-side balloon is "Connecting to " (Clipboard.cs:451), which our Notifier.connected(to:) already covers from the control channel.

Requested of clipboard (open)

  1. HasSwitchedMachineSinceLastCopy has no equivalent. Windows sets it on both edge paths (Event.cs:81, Receiver.cs:160), on HideMouse (Receiver.cs:384) and in Helper.cs:320, and it suppresses the "same content as last time" short-circuit exactly once (Clipboard.cs:130-139, 206-215). Without it, copying the same text again after a machine switch can be dropped where Windows resends it. ClipboardBridge.swift is the clipboard lane's file; recorded in protocol §10.8 note 7.

Status / TODO

  • Sources/MWBMac/Awake.swift + Engine .awake hook (Receiver.cs:244-249, Common.cs:561-591).
  • Sources/MWBMac/Fullscreen.swift + edge-path hook + excluded apps (Common.cs:1562-1650, called from Event.cs:79).
  • Sources/MWBCore/Settings.swift drawMouseCursor accessor; Sources/MWBMac/SettingsWindow/BehaviourPane.swift toggle.
  • Sources/MWBMac/FakeCursor.swift + Engine wiring (CustomCursor.cs:71-146, Receiver.cs:186-188).
  • Corners + relative mode verified end-to-end by reading; one gap fixed by citation and a Handshake request, one recorded as the clipboard lane's (see the Work log).
  • Sources/mwb/UIBridge.swift: clipboard transfer notifications (three provisional lines in ClipboardBridge.swift, flagged above).
  • docs/protocol.md: §10.8 appended, seven notes, all cited.
  • Checkpoint CP3 is the lead's after merge.

Work log

2026-09-16 (dev)

Read first: CLAUDE.md, README.md, docs/protocol.md §3.3, §4.3-§4.4, §10.1-§10.7, docs/contracts.md, docs/topo.md, and the Handshakes and Review sections of app-engine, app-ui, input-inject, input-capture, clipboard and session-matrix.

Awake. DisplayAwake holds one IOPMAssertionCreateWithProperties assertion with kIOPMAssertionTimeoutKey: 90 and kIOPMAssertionTimeoutActionRelease; renew() creates the new one before releasing the old so the display is never momentarily unasserted, and Engine.stop() releases. Hooked by splitting .awake out of the .heartbeat, .heartbeatEx, .awake, .hello case in Engine.dispatch, so it still learns the sender (switcher.learn) and then renews, in Receiver.cs:244-249 order. Decision: the Windows PokeMyself jiggle is not ported, at all — invariant 5. Decision: no gate on our own BlockScreenSaverOnOtherMachines; that setting is the sender's, and Common.HumanBeingDetected checks nothing (protocol §10.8 note 1). Autolinking picks IOKit up from import IOKit.pwr_mgt; Package.swift needed no change.

Fullscreen. Fullscreen.frontmostIsFullscreen(excluding:displays:) with a 250 ms cache keyed on the excluded set, called from Engine.easyMouseSwitchAllowed(), which reproduces IsEasyMouseSwitchAllowed's two early outs. Placed in considerCrossing after switcher.crossing, because Event.cs:79 asks in that order and crossing is what updates LastX/LastY. Finder is treated as the Windows shell/desktop early-out (Common.cs:1607-1612). Deviation: SHQueryUserNotificationState has no macOS twin, so the test is "the frontmost app owns an on-screen layer-0 window whose bounds equal a display's" — a zoomed window stops below the menu bar, a native full-screen one does not, which is the discrimination the Windows call is making. 1-point tolerance.

Drawn cursor. FakeCursor (nonisolated, coalescing) + CursorOverlay (@MainActor, the window). Shown from Engine.dispatch after injecting a .mouse packet, at pointerPosition() — the port of Receiver.cs:186-188's inject → GetCursorPos → draw. Hidden from SwitchAction.parkCursor (Common.cs:1495), from drainCapture when real local input arrives and the destination is not remote (InputHook.cs:256-264, where local means NewDesMachineID is us or ALL), and in Engine.stop(). applyConfiguration() follows the setting, which is Setting.cs:97-101's behaviour of hiding the moment the box is unticked. Deviation, flagged for CP3: the Windows ci.flags != 1 gate cannot be ported (protocol §10.8 note 4), so with DrawMouseCursor at its PowerToys default of true a controlled Mac shows the overlay beside its own real pointer. The default is kept (README D3 says the schema matches PowerToys); if the second arrow reads as a bug at CP3, the fix is a macOS-specific default of false, not a change here.

Behaviour pane. The toggle went in after "Block mouse at screen corners", matching MouseWithoutBordersPage.xaml:240-251. The two NotYetActive footnotes were replaced by one: the first said clipboard sharing, file transfer and screen-saver blocking were inert, which stopped being true with the clipboard lane and this one, and the second said the drawn cursor was not shown here, which this change undoes. Leaving either in place would have been a false statement in the UI.

Corners and relative mode, verified by reading. No code change was needed for the corner path and none was made.

  • Corners. Settings.blockMouseAtScreenCorners → EngineActions.applyConfiguration() → ScreenLayout.edgeConfig(blockCorners:moveRelatively:) → Switcher.edge.config, re-applied on every settings change and every display change (Engine.handle(.screensChanged)). ScreenLayout. current() builds corners as the four corners of every active display in WinAPI.cs:106-109 order, and CGDisplayBounds' maxX/maxY are exclusive exactly as rcMonitor.Right/Bottom are. Edge.isNearCorner is abs(dx) < 100 && abs(dy) < 100 over that list — the Chebyshev square of MachineStuff.cs:228, not a radius — and it sits between the debounce and the edge comparisons, as at MachineStuff.cs:217-234, so a blocked switch still records lastX/lastY. Because the check is inside Edge.crossing, it applies on both callers: the controller's edge path and the controlled machine's relative-mode path, which is also true of the one Windows function.
  • Relative mode, controller → wire. EventTap.remotePosition tags every delta with Coordinates.tagRelative when moveMouseRelatively, including a zero delta, which is InputHook.cs:311-312; that is why Event.cs:105's |dx| >= MOVE_MOUSE_RELATIVE && |dy| >= … test always takes the relative branch in this mode, and why Coordinates.isRelative tests both axes (Receiver.cs:147). EventTap.offerEdgeCandidate refuses to propose an edge while the destination is remote and the mode is on, which is Event.cs:73's (DesMachineID == MachineID || !MoveMouseRelatively).
  • Relative mode, controlled machine. Engine.dispatch's .mouse case runs takeControlBack() (Receiver.cs:122-125), injects — and Injector.injectMouse reads the tag, adds the delta to the current pointer for a move and re-reads the pointer for a button or wheel, which is Receiver.cs:151-153 and :170-176 — then reportEdgeToController, which requires WM_MOUSEMOVE and a relative tag, reads pointerPosition() (GetCursorPos, Receiver.cs:154) and calls switcher.crossing. Switcher.crossing computes cursorIsLocal = desMachineID == localID, which is true here because takeControlBack has just made it so — the same thing Windows gets by passing Common.MachineID explicitly at Receiver.cs:156. The reply is Switcher.nextMachinePacket, rate-limited to one per 100 ms (Common.cs:516-524), Des = the controller, Md.X/Y = the landing point, Md.WheelDelta = the target id (§4.4). Note that the lastJump debounce inside Edge.crossing is dead on this side, in our port and in Windows alike, because only prepareToSwitch / PrepareToSwitchToMachine writes it and the controlled machine never calls either (protocol §10.8 note 6).
  • Relative mode, back on the controller. .nextMachine → switcher.prepareToSwitch(to: UInt32(bitPattern: wheelDelta), landing: (x, y)), which is Receiver.cs:195-201. Gap found: the guard is settings.easyMouse == .enable, where Windows also accepts the held Ctrl/Shift Easy-Mouse key (Event.cs:152-155). The flag lives in the tap and is not published, so the gap is cited at the call site and filed as a Handshake request to input-capture rather than worked around. Second gap, not ours: neither edge path sets anything like Clipboard.HasSwitchedMachineSinceLastCopy; filed to the clipboard lane and recorded in protocol §10.8 note 7.

Transfer notifications. TransferNotices in UIBridge.swift, with the notifier installed in UIBridge.start() and dropped in stop(). Feeding it needed three one-line additions in the clipboard lane's ClipboardBridge.swift; they are listed in Handshakes above rather than made silently.

Verification: build-only, as the brief requires. Nothing here was executed: no app launched, no tap created, no event posted, no overlay window made, no IOKit assertion taken and no notification posted. tools/gates.sh green under tools/guard.sh.

QA log

2026-09-16 (QA)

Scope: git diff b73e878..HEAD, build-only (CLAUDE.md invariant 5): no app launched, no tap created, no event posted, no overlay window made, no IOKit assertion taken, no notification posted.

Gates. tools/gates.sh — clean: swift-format lint --strict, the MWBCore layering grep (no AppKit/CoreGraphics/Network/IOKit import), swift build -Xswiftc -warnings-as-errors. swift build only (gates.sh runs no swift test), so tools/guard.sh was not needed for this step.

Status/TODO ticks, checked against the Windows source.

  • Awake (Sources/MWBMac/Awake.swift, Engine.swift:558-565). Matches Receiver.cs:244-249 (AddToMachinePool + HumanBeingDetected) and Common.cs:545-591: the setting gates only the sender (SendAwakeBeat), the receiver honours any Awake unconditionally, and renew() (90 s kIOPMAssertionTimeoutKey, re-create-before-release) is a faithful substitute for the effect PokeMyself is reaching for, without posting input. Confirmed only .awake calls renew(); .heartbeat, .heartbeatEx, .hello do not (Engine.swift:558-572).
  • Fullscreen (Sources/MWBMac/Fullscreen.swift, Engine.swift:485-512). Confirmed easyMouseSwitchAllowed() is called from exactly one place, considerCrossing (the edge path), and not from the .nextMachine case — matches Event.cs:79's call inside MouseEvent, gated the same way (IsSwitchingByMouseEnabled() on the geometry call, IsEasyMouseSwitchAllowed() only after a non-empty jump) and never called from Receiver.cs:145-172's relative-mode path or Receiver.cs:195-201's NextMachine handler. The two early-outs (Common.cs:1638-1650) are reproduced in order. Cache keyed on the excluded set (not on displays), but Fullscreen.invalidate() is called from applyConfiguration(), which fires on .screensChanged (Engine.swift:395-396) as well as every settings change, so a display edit is still felt within one applyConfiguration(), not stale for a whole cache window. Excluded-apps matching (Fullscreen.isExcluded(_:in:)) tests bundle identifier, localized name, and bundle file name with/without .app, case-insensitively — the two spellings Common.cs:1597-1599 accepts, correctly widened for bundle identifiers which Windows has no equivalent of.
  • Drawn cursor (Sources/MWBMac/FakeCursor.swift). CursorOverlay is @MainActor (FakeCursor.swift:224), ignoresMouseEvents = true (click-through, :272). Hidden on .parkCursor (EngineActions.swift:69, matching Common.cs:1495's ShowFakeMouseCursor(int.MinValue,…) at the end of HideMouseCursor), on local input while the destination is not remote (Engine.swift:456, matching InputHook.cs:256-264's if (local) { … ShowFakeMouseCursor (int.MinValue,…) }), and in Engine.stop() (Engine.swift:295). FakeCursor itself (Sendable, lock-coalesced) is only ever driven from Engine.swift (.mouse case, applyConfiguration(), .parkCursor, stop()); grepped Sources/MWBMac/EventTap.swift for FakeCursor / CursorOverlay — no hits, so the tap never touches it, as required.
  • ClipboardBridge.swift provisional lines (clipboardFailed, the .note case, commitReceivedFile's success arm). Read every string that reaches TransferNotices.post: "clipboard text could not be compressed", "clipboard file not found", "clipboard payload from \(source) was too big", "image received", "text received", "clipboard text could not be decoded", and "Received \(name)." — all fixed strings or a filename, never clipboard content, and clipboardFailed's reason is BulkChannel's own failure description, not the payload. Notifier.post (Notifications.swift:47-56) does not log body. Minimal: 4 added lines total (one is a citation comment), matching the "three one-line additions" the Handshakes section describes.
  • drawMouseCursor accessor + toggle (Settings.swift:198-205, BehaviourPane.swift:38-44). Plain boxed-bool accessor matching the existing pattern; toggle placed after "Block mouse at screen corners" as claimed, matching MouseWithoutBordersPage.xaml:246-251's ordering. DrawMouseEx stays a boxed default (Settings.swift:159, pre-existing) that nothing reads — "accepted and ignored" is accurate.
  • Corners and relative mode, two claims spot-checked directly against code (not just the README's prose): Edge.isNearCorner (Edge.swift:139-142) is abs(dx) < 100 && abs(dy) < 100 — a Chebyshev square, not a radius, over config.corners, matching MachineStuff.cs:222-234. EventTap.remotePosition (EventTap.swift:397-410) tags every delta, zero included, with Coordinates.tagRelative when moveMouseRelatively is on, matching the cited InputHook.cs:311-312; confirmed Coordinates.isRelative tests both axes (Coordinates.swift:119). Also confirmed the filed gap is real: EventTap.easyMouseKeyDown (EventTap.swift:93) is private, so Engine.swift:551's .nextMachine case can only test settings.easyMouse == .enable, not the held Ctrl/Shift key (Event.cs:152-155) — correctly cited and correctly left as a Handshake request rather than worked around by reaching into EventTap.swift (input-capture's file).

Read top to bottom: Awake.swift, FakeCursor.swift, Fullscreen.swift in full (new files); the diffed regions of Engine.swift, EngineActions. swift, UIBridge.swift, ClipboardBridge.swift, Settings.swift, BehaviourPane.swift. No force-unwraps, try!, fatalError or precondition in any changed line. No new @unchecked Sendable (the two in ClipboardBridge.swift/Settings.swift predate this diff). IOKit is imported only in Awake.swift; MWBMac imports no MWBNet in the new files; MWBCore still imports nothing but Foundation (gate 2). No retain cycles found: FakeCursor's Task { @MainActor in self.draw() } is a one-shot hop with no back-reference from CursorOverlay, and TransferNotices' notifier is weak. Engine.swift grew from 620 to 678 lines — under the 800-line "consider splitting" mark, no action needed. Comments are cited throughout; none found uncited.

Finding (informational, not blocking). Common.HumanBeingDetected() (Common.cs:561-572) only runs PokeMyself() when lastInputEventCount == Event.InputEventCount, i.e. only when this machine's own user has had no input since the previous Awake/beat — a machine whose local user is already active never jiggles itself. The port's displayAwake.renew() (Sources/mwb/Engine.swift:565) has no equivalent guard: it renews the assertion on every Awake regardless of local activity. This is harmless with the assertion-based mechanism (renewing while the local user is already active costs nothing and asserts nothing false — the display would stay awake anyway), so it is not a wire or recoverability defect, but it is a behaviour Windows has that the port silently drops without a note in the Assumptions section or protocol §10.8 note 1, both of which describe the jiggle being dropped but not this conditional. Suggest a one-line addition to protocol §10.8 note 1 next time that file is touched; not worth a rework on its own.

No typos found to fix directly.

Verdict: PASS

Findings:

  1. (informational, low severity) Sources/mwb/Engine.swift:565 (displayAwake.renew()) vs. Common.cs:561-572 (HumanBeingDetected's lastInputEventCount guard): the port renews the display-awake assertion on every Awake packet unconditionally, where Windows only pokes itself when the receiving machine's own user has been idle since the last beat. No correctness or invariant impact; recorded so protocol §10.8 note 1 can mention it.

Review

  • 2026-09-16 (lead): inspected per docs/loop.md §5. Gates green run by me; diff limited to the brief's files and authorised edits plus three provisional lines in ClipboardBridge.swift (accepted: fixed strings and filenames only). Checked CursorOverlay is @MainActor and click-through, and that only .awake renews the assertion. QA PASS with one documentation follow-up (Windows pokes only when local input is idle), moved to TODO §10 with the lane's two open requests. Verdict: merge. CP3 is now due. The app is feature-complete against the PowerToys module minus README D6; lane 10 (polish) waits on the user's CP1–CP3 findings.