session-matrix: parkCursor carries the HideMouseCursor gate

QA finding 3. HideMouseCursor moves the real cursor only when
(desMachineID != MachineID && desMachineID != ID.ALL) || byHideMouseMessage
(Common.cs:1488), and SwitchToMachine calls it after setting DesMachineID
(MachineStuff.cs:1025) — so control coming home parks nothing. The action
is now .parkCursor(destinationIsRemote:byHideMouseMessage:), both halves
of that gate pre-evaluated by Switcher (new .destinationIsRemote), so
input-inject can implement it without reading the Windows source. Spelled
out as a consumer rule in the README's Handshakes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 00:59:29 -07:00
1 parent e0638de0b9
commit 9252158bbc
2 files changed
+42 -7

No files matched your search

+29 -6
View File
@@ -28,10 +28,20 @@ public struct Jump: Sendable, Equatable {
public enum SwitchAction: Sendable, Equatable {
/// Queue this packet on every connection (`Des` is already set).
case send(Packet)
/// Park the real cursor at the top centre of the primary screen
/// (`HideMouseCursor`, `Common.cs:1482-1496`). `byHideMouseMessage` is the
/// Windows flag: true when a peer asked with `HideMouse (50)`.
case parkCursor(byHideMouseMessage: Bool)
/// Park the cursor at the top centre of the primary screen — the "hidden"
/// position the app also remembers as `LastPos` (`HideMouseCursor`,
/// `Common.cs:1482-1496`).
///
/// **Record the position always; move the real OS cursor only when
/// `destinationIsRemote || byHideMouseMessage`.** That is the whole of the
/// `Common.cs:1488` gate, pre-evaluated here so no consumer has to re-derive
/// it from `desMachineID`: `destinationIsRemote` is
/// `desMachineID != localID && desMachineID != ID.ALL` *after* the switch,
/// and `byHideMouseMessage` is true only when a peer asked with
/// `HideMouse (50)`. Moving the cursor when both are false is a visible bug:
/// control coming home (a `ByeBye`, a disconnect, a hotkey back to this
/// machine) would jerk the user's own cursor to the top of the screen.
case parkCursor(destinationIsRemote: Bool, byHideMouseMessage: Bool)
/// Put the cursor at this switch location; pixel-tagged values mean pixels
/// (`Coordinates.isPixels`, `Helper.cs:100-115`).
case moveCursor(UniversalPoint)
@@ -107,6 +117,13 @@ public final class Switcher {
/// True while input goes to every machine at once (`ID.ALL`).
public var isBroadcasting: Bool { desMachineID == MachineID.all }
/// Whether the machine currently receiving input is a remote one — the
/// `desMachineID != MachineID && desMachineID != ID.ALL` half of the
/// `HideMouseCursor` gate (`Common.cs:1488`).
public var destinationIsRemote: Bool {
desMachineID != localID && desMachineID != MachineID.all
}
/// Whether a machine can be reached right now: itself always, others only
/// with a live socket (`Common.cs:852-855`).
public func isConnected(to id: UInt32) -> Bool {
@@ -197,7 +214,10 @@ public final class Switcher {
let centre = Coordinates.centre(of: edge.config.primary) // MachineStuff.cs:1021-1022
actions.append(.moveCursor(Coordinates.tagPixels(centre)))
actions.append(.parkCursor(byHideMouseMessage: false)) // MachineStuff.cs:1025
// HideMouseCursor(false) after DesMachineID is set (MachineStuff.cs:1025),
// so the gate reads the new destination, not the old one.
actions.append(
.parkCursor(destinationIsRemote: destinationIsRemote, byHideMouseMessage: false))
actions.append(.desMachineChanged(id: desMachineID, name: desMachineName))
return actions
}
@@ -298,7 +318,10 @@ public final class Switcher {
/// Handles `HideMouse (50)`: a peer took control, so park our cursor and let
/// go of every modifier (`Receiver.cs:383-388`).
public func handleHideMouse() -> [SwitchAction] {
[.parkCursor(byHideMouseMessage: true), .releaseAllKeys]
[
.parkCursor(destinationIsRemote: destinationIsRemote, byHideMouseMessage: true),
.releaseAllKeys,
]
}
/// A connection dropped: back-date the machine so it reads as dead, and take
+13 -1
View File
@@ -268,7 +268,7 @@ public struct Jump: Sendable, Equatable {
}
public enum SwitchAction: Sendable, Equatable {
case send(Packet) // already addressed
case parkCursor(byHideMouseMessage: Bool)
case parkCursor(destinationIsRemote: Bool, byHideMouseMessage: Bool)
case moveCursor(UniversalPoint) // pixel-tagged means pixels
case releaseAllKeys
case desMachineChanged(id: UInt32, name: String?)
@@ -287,6 +287,7 @@ public final class Switcher { // not Sendable: app-wide
public private(set) var desMachineName: String?
public private(set) var newDesMachineID: UInt32
public var isBroadcasting: Bool { get }
public var destinationIsRemote: Bool { get } // the HideMouseCursor gate
public func isConnected(to id: UInt32) -> Bool
public func crossing(at point: CGPoint, now: TimeInterval) -> Jump?
public func prepareToSwitch(to:landing:now:) -> [SwitchAction]
@@ -317,6 +318,17 @@ Rules the consuming lanes must honour:
**not** `Session.send(_:)` — one broadcast must keep one `Id` across a
peer's two connections or the receiver's replay ring will not collapse
the duplicate.
- **`.parkCursor` records a position; it moves the OS cursor only when
`destinationIsRemote || byHideMouseMessage`.** `Switcher` pre-evaluates
both halves of the `HideMouseCursor` gate (`Common.cs:1488`) so no
consumer needs `desMachineID`, and `destinationIsRemote` is computed
*after* the switch, as `SwitchToMachine` does (`MachineStuff.cs:1025`).
The hidden position (primary screen, horizontal centre, `y = 4` with
`HideMouse` on, else vertical centre) is remembered as `LastPos` every
time, because that is what the cursor is restored to. An injector that
moves unconditionally will jerk the local cursor to the top of the
screen every time control comes home — on every `ByeBye` and every peer
disconnect (`Common.cs:622-625`).
- **`Matrix.live(connectedNames:)` must be given the local machine's own
name**, because the Windows `IsConnectedTo` answers yes for it without a
socket. `Switcher.crossing` adds it; a direct caller must too.