extras: awake assertion, fullscreen rule, drawn cursor, transfer notices

- MWBMac/Awake.swift: DisplayAwake renews an IOPMAssertion
  (PreventUserIdleDisplaySleep, 90 s timeout) on every Awake (21), the
  macOS answer to Common.HumanBeingDetected/PokeMyself
  (Receiver.cs:244-249, Common.cs:561-591) without posting input.
- MWBMac/Fullscreen.swift: the frontmost app's excluded-apps test and a
  covers-a-whole-display window check, cached 250 ms; gated in the
  Engine by IsEasyMouseSwitchAllowed's two early outs
  (Common.cs:1638-1650), so it is asked only on the edge path.
- MWBMac/FakeCursor.swift: CursorOverlay draws NSCursor.arrow at the
  last injected position (Receiver.cs:186-188) and hides on park, local
  input and shutdown (Common.cs:1495, InputHook.cs:256-264); FakeCursor
  coalesces the main-thread hops.
- Settings.drawMouseCursor accessor + the Behaviour-pane toggle,
  answering app-ui's open request.
- UIBridge.TransferNotices wires ClipboardAction.note to the Notifier,
  answering clipboard's open request (Clipboard.cs:610-618, 869-881, 916).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 05:25:10 -07:00
1 parent b73e878ae4
commit 21c886165e
9 files changed
+508 -9

No files matched your search

+60 -2
View File
@@ -159,6 +159,12 @@ public actor Engine {
let screens: Screens
let cursor = Cursor()
let injector: Injector
/// The receiving half of `BlockScreenSaverOnOtherMachines`: every `Awake`
/// packet renews a power assertion (the extras lane, `Awake.swift`).
let displayAwake = DisplayAwake()
/// `DrawMouseCursor`: the arrow drawn where the remote pointer is while a
/// peer drives this Mac (the extras lane, `FakeCursor.swift`).
let fakeCursor = FakeCursor()
var tap: EventTap?
var channel: ControlChannel?
/// Clipboard sharing: the bulk channel, the pasteboard watcher and the
@@ -283,6 +289,10 @@ public actor Engine {
pump = nil
injector.releaseAll()
cursor.restoreEverything()
// Nothing may outlive the process: an assertion we still hold would keep
// the display awake, and the overlay would be the last thing on screen.
displayAwake.release()
fakeCursor.hide()
persistOnExit()
Log.app.info("engine stopped")
}
@@ -438,7 +448,12 @@ public actor Engine {
// `Event.RealInputEventCount++` (`Event.cs:51-55`): the sessions only
// ask whether it moved since their own previous beat, so one bump per
// drain that saw input says exactly what `SendAwakeBeat` needs.
if sawRealInput { channel?.noteUserActivity() }
guard sawRealInput else { return }
channel?.noteUserActivity()
// `InputHook.cs:256-264`: real input with the pointer on this Mac —
// `local`, i.e. the destination is us or ALL — takes the drawn cursor
// away. `hide()` is a no-op when it is already gone.
if !switcher.destinationIsRemote { fakeCursor.hide() }
}
private func sendKey(vk: Int32, flags: Int32) {
@@ -469,10 +484,33 @@ public actor Engine {
private func considerCrossing(at point: CGPoint, now: TimeInterval) {
guard let jump = switcher.crossing(at: point, now: now) else { return }
// `Event.cs:79`: the fullscreen rule is asked *after* the edge geometry
// says a switch would happen, so a blocked switch still updates
// `LastX`/`LastY` inside `crossing`, exactly as Windows does.
guard easyMouseSwitchAllowed() else {
Log.engine.debug("edge \(jump.direction) blocked: full-screen app in front")
return
}
Log.engine.debug("edge \(jump.direction) → \(jump.targetName)")
perform(switcher.prepareToSwitch(to: jump.targetID, landing: jump.landing, now: now))
}
/// `Common.IsEasyMouseSwitchAllowed` (`Common.cs:1638-1650`).
///
/// Two early outs before anything looks at a window: the setting is off, or
/// this Mac is not the one holding the pointer — "never prevent a switch if
/// we are not moving out of the host machine" (`:1646`). That second test is
/// also what keeps the check off the relative-mode path, where the machine
/// doing the edge detection is the one being controlled
/// (`Receiver.cs:156-170`, which never consults it).
private func easyMouseSwitchAllowed() -> Bool {
guard settings.disableEasyMouseWhenFullscreen else { return true }
guard switcher.desMachineID == switcher.localID else { return true }
return !Fullscreen.frontmostIsFullscreen(
excluding: Set(settings.easyMouseFullscreenExcludedApps),
displays: screens.layout.displays)
}
// MARK: - Received packets (`Receiver.ProcessPackage`, `Receiver.cs:86-390`)
/// The port of `ProcessPackage`'s switch. Long on purpose (CLAUDE.md, file
@@ -494,11 +532,22 @@ public actor Engine {
guard forUs else { break }
takeControlBack() // Receiver.cs:122-125
injector.inject(packet, layout: screens.layout)
// `Receiver.cs:186-188`: the pointer has just been moved, so this is
// where Windows records `LastX`/`LastY` and draws the fake cursor.
fakeCursor.show(at: pointerPosition())
reportEdgeToController(packet, now: now)
case .nextMachine:
// `Receiver.cs:192-198`: the machine we are controlling hit its own
// edge in relative mode and is telling us where to go next.
//
// Windows tests `Event.IsSwitchingByMouseEnabled()` (`Event.cs:152-155`),
// which is `EasyMouse == Enable` **or** the Ctrl/Shift Easy-Mouse key
// being held. That second half lives in the tap
// (`EventTap.easyMouseKeyDown`) and is not published, so with Easy
// Mouse set to Ctrl or Shift a relative-mode `NextMachine` is ignored
// here where Windows would switch. Filed in the extras README as a
// Handshake request to input-capture.
guard settings.easyMouse == .enable else { break }
let data = packet.mouse
perform(
@@ -506,7 +555,16 @@ public actor Engine {
to: UInt32(bitPattern: data.wheelDelta),
landing: UniversalPoint(x: data.x, y: data.y), now: now))
case .heartbeat, .heartbeatEx, .awake, .hello:
case .awake:
// `Receiver.cs:244-249`: learn the sender, then
// `Common.HumanBeingDetected()` (`Common.cs:561-572`) — a human is
// busy on that machine, so this one's display stays on. The sender's
// `BlockScreenSaverOnOtherMachines` decides whether `Awake` is sent
// at all (`Common.cs:545-559`); the receiver always honours it.
perform(switcher.learn(from: packet, now: now))
displayAwake.renew()
case .heartbeat, .heartbeatEx, .hello:
// `AddToMachinePool` (`Receiver.cs:207-262`). `Heartbeat_ex` and its
// two follow-ups are the Windows key-propagation handshake, which is
// out of scope (README D6); the packet still identifies its sender,