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:
1 parent
b73e878ae4
commit
21c886165e
9 files changed
+508
-9
No files matched your search
@@ -460,6 +460,7 @@ extension Engine {
|
||||
/// A bulk transfer did not.
|
||||
func clipboardFailed(_ reason: String) {
|
||||
Log.engine.info("clipboard: \(reason)")
|
||||
Task { @MainActor in TransferNotices.post(reason) } // the extras lane
|
||||
}
|
||||
|
||||
// MARK: - Performing the bridge's actions
|
||||
@@ -481,6 +482,7 @@ extension Engine {
|
||||
commitReceivedFile(staged: staged, name: name)
|
||||
case .note(let text):
|
||||
Log.engine.info("clipboard: \(text)")
|
||||
Task { @MainActor in TransferNotices.post(text) } // the extras lane
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -546,6 +548,8 @@ extension Engine {
|
||||
let file = try ReceivedFile.commit(staged: staged, toFileNamed: name, in: directory)
|
||||
clipboard?.announce(file)
|
||||
Log.engine.info("clipboard: received \(name)")
|
||||
// `Clipboard.cs:869-881`: "<file> from <machine> is in Clipboard."
|
||||
Task { @MainActor in TransferNotices.post("Received \(name).") } // the extras lane
|
||||
Task { @MainActor in ReceivedFile.reveal(file) }
|
||||
} catch {
|
||||
ReceivedFile.discard(staged)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -63,6 +63,10 @@ extension Engine {
|
||||
hideMouse: settings.hideMouseAtScreenEdge, layout: screens.layout,
|
||||
destinationIsRemote: destinationIsRemote,
|
||||
byHideMouseMessage: byHideMouseMessage)
|
||||
// `Common.HideMouseCursor` ends with `ShowFakeMouseCursor(int.MinValue,
|
||||
// int.MinValue)` (`Common.cs:1495`): control moved, so the arrow the
|
||||
// last remote move drew is stale either way.
|
||||
fakeCursor.hide()
|
||||
|
||||
case .moveCursor(let landing):
|
||||
noteCursorLanding(landing)
|
||||
@@ -229,6 +233,11 @@ extension Engine {
|
||||
moveRelatively: settings.moveMouseRelatively)
|
||||
tap?.reconfigure(captureConfig())
|
||||
injector.reconfigure(InjectorConfig(lockMachine: settings.lockMachineShortcut))
|
||||
// `Setting.cs:97-101`: turning `DrawMouseCursor` off hides the drawn
|
||||
// cursor there and then. The excluded-apps list is part of the cached
|
||||
// fullscreen answer, so an edit to it must not wait 250 ms.
|
||||
fakeCursor.setEnabled(settings.drawMouseCursor)
|
||||
Fullscreen.invalidate()
|
||||
applyClipboardConfiguration() // the clipboard lane
|
||||
syncRouting()
|
||||
}
|
||||
|
||||
@@ -16,6 +16,35 @@ import MWBCore
|
||||
import MWBMac
|
||||
import MWBNet
|
||||
|
||||
/// Clipboard and file transfers, shown to the user.
|
||||
///
|
||||
/// Windows pops one tray balloon per transfer — "Receiving X from Y…"
|
||||
/// (`Clipboard.cs:610-618`), "X from Y is in Clipboard." (`:869-881`) and the
|
||||
/// failure message (`:916`) — each passing `Setting.Values.ShowClipNetStatus` to
|
||||
/// `ShowToolTip`, so the setting is the gate. `Notifier` already holds that gate
|
||||
/// (`enabledChanged(_:)` follows
|
||||
/// `ShowClipboardAndNetworkStatusMessages`), so all that was missing was the
|
||||
/// wire: the clipboard lane's `ClipboardAction.note` carries the text and the
|
||||
/// Engine only logged it.
|
||||
///
|
||||
/// A static rendezvous rather than a property on the Engine because the Engine
|
||||
/// is an actor, the `Notifier` is `@MainActor`, and there is exactly one of each
|
||||
/// for the life of the process.
|
||||
@MainActor enum TransferNotices {
|
||||
private static weak var notifier: Notifier?
|
||||
|
||||
/// UIBridge hands its notifier over when the menu bar appears, and takes it
|
||||
/// back on the way out.
|
||||
static func install(_ notifier: Notifier?) {
|
||||
TransferNotices.notifier = notifier
|
||||
}
|
||||
|
||||
/// Shows one transfer message, if the user asked for them.
|
||||
static func post(_ text: String) {
|
||||
notifier?.post(title: "Mouse Without Borders", body: text)
|
||||
}
|
||||
}
|
||||
|
||||
/// Owns the menu bar, the settings window and the notifier, and keeps all three
|
||||
/// in step with the Engine.
|
||||
@MainActor final class UIBridge {
|
||||
@@ -43,11 +72,13 @@ import MWBNet
|
||||
/// the first snapshot has something to draw into.
|
||||
func start() {
|
||||
statusItem = StatusItemController(actions: makeActions())
|
||||
TransferNotices.install(notifier)
|
||||
render(EngineSnapshot())
|
||||
}
|
||||
|
||||
/// Takes the item away again, on the way out.
|
||||
func stop() {
|
||||
TransferNotices.install(nil)
|
||||
statusItem?.remove()
|
||||
statusItem = nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user