input-capture: coalescing two relative moves sums the deltas

Latest-wins is right for an absolute position and wrong for a
MOVE_MOUSE_RELATIVE delta, which would have silently dropped motion in
MoveMouseRelatively mode.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 02:14:52 -07:00
1 parent c578e0a656
commit 59fc7a3162
1 file changed
+22 -1
+22 -1
View File
@@ -120,7 +120,7 @@ public final class CaptureQueue: Sendable {
return next // the latest pointer position is the only one that matters
case (.mouse(let old), .mouse(let new)):
if old.flags == WindowsMessage.mouseMove && new.flags == WindowsMessage.mouseMove {
return next
return .mouse(mergedMove(old, new))
}
if old.flags == new.flags,
new.flags == WindowsMessage.wheel || new.flags == WindowsMessage.horizontalWheel
@@ -134,4 +134,25 @@ public final class CaptureQueue: Sendable {
return nil
}
}
/// Two consecutive moves become one.
///
/// An absolute move carries a position, so the newest one wins. A *relative*
/// move carries a delta (`MoveMouseRelatively`, docs/protocol.md §4.4), and
/// dropping the older one would throw away real motion — those are summed,
/// untagged and re-tagged so the `MOVE_MOUSE_RELATIVE` bias is applied once.
private func mergedMove(_ old: MouseData, _ new: MouseData) -> MouseData {
let oldPoint = UniversalPoint(x: old.x, y: old.y)
let newPoint = UniversalPoint(x: new.x, y: new.y)
guard Coordinates.isRelative(oldPoint), Coordinates.isRelative(newPoint) else {
return new
}
let a = Coordinates.untagRelative(oldPoint)
let b = Coordinates.untagRelative(newPoint)
let summed = Coordinates.tagRelative(dx: a.x &+ b.x, dy: a.y &+ b.y)
var merged = new
merged.x = summed.x
merged.y = summed.y
return merged
}
}