§10.8 records seven findings with citations: the Awake receiver honours the sender's setting and pokes itself with a mouse jiggle; the fullscreen rule is asked once, only by the pointer's owner; the excluded-apps list matches two spellings of the image name; DrawMouseCursor only draws when the real cursor is suppressed; BlockMouseAtCorners is a 100 px square around every monitor corner; relative mode moves edge detection to the controlled machine and gates NextMachine on IsSwitchingByMouseEnabled; both edge paths set HasSwitchedMachineSinceLastCopy. README: Assumptions confirmed, Handshakes updated to the shipped API with four deviations, two open requests (input-capture's easyMouseKeyDown, clipboard's HasSwitchedMachineSinceLastCopy) and the three provisional lines taken in ClipboardBridge.swift, Status ticked, Work log with the corners/relative-mode reading trace. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
364 lines
19 KiB
Markdown
364 lines
19 KiB
Markdown
# 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.
|
|
|
|
```swift
|
|
// 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 <name>." (`Clipboard.cs:869-881`).
|
|
|
|
There is no `.note` for a *send*, and none was invented: Windows' only
|
|
send-side balloon is "Connecting to <machine>" (`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
|
|
|
|
- [x] `Sources/MWBMac/Awake.swift` + Engine `.awake` hook
|
|
(`Receiver.cs:244-249`, `Common.cs:561-591`).
|
|
- [x] `Sources/MWBMac/Fullscreen.swift` + edge-path hook + excluded apps
|
|
(`Common.cs:1562-1650`, called from `Event.cs:79`).
|
|
- [x] `Sources/MWBCore/Settings.swift` `drawMouseCursor` accessor;
|
|
`Sources/MWBMac/SettingsWindow/BehaviourPane.swift` toggle.
|
|
- [x] `Sources/MWBMac/FakeCursor.swift` + Engine wiring
|
|
(`CustomCursor.cs:71-146`, `Receiver.cs:186-188`).
|
|
- [x] 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).
|
|
- [x] `Sources/mwb/UIBridge.swift`: clipboard transfer notifications
|
|
(three provisional lines in `ClipboardBridge.swift`, flagged above).
|
|
- [x] `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
|
|
|
|
## Review
|