fix(apple): scroll from trackpads/Magic Mouse — forward NSEvent scrollWheel, drop GC scroll
ci / rust (push) Has been cancelled
ci / rust (push) Has been cancelled
Scroll was wired to GCMouse's scroll dpad, which only fires for plain HID wheel deltas — trackpad and Magic Mouse scrolling are gesture events that never reach GameController, so scrolling was dead on the default Mac setups. The stream view now overrides scrollWheel (while captured the cursor is parked mid-view, so it receives every scroll event) and feeds InputCapture.sendScroll: precise gesture deltas are pixels (~0.1 notch/px, SDL's factor → ×12 for WHEEL_DELTA(120)), classic wheels are lines (×120), fractional remainders accumulate, and the GC scroll handler is gone so wheel mice can't double-deliver. Signs pass through as-is, preserving the local (natural-)scrolling preference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -237,18 +237,26 @@ public final class InputCapture {
|
||||
}
|
||||
}
|
||||
}
|
||||
input.scroll.valueChangedHandler = { [weak self] _, x, y in
|
||||
guard let self, self.forwarding else { return }
|
||||
// WHEEL_DELTA(120) per notch; positive = up / right (Moonlight's convention).
|
||||
let fy = y * 120 + self.residualScrollY
|
||||
let fx = x * 120 + self.residualScrollX
|
||||
let iy = fy.rounded(.towardZero)
|
||||
let ix = fx.rounded(.towardZero)
|
||||
self.residualScrollY = fy - iy
|
||||
self.residualScrollX = fx - ix
|
||||
if iy != 0 { self.connection.send(.scroll(Int32(iy))) }
|
||||
if ix != 0 { self.connection.send(.scroll(Int32(ix), horizontal: true)) }
|
||||
}
|
||||
// NOTE: no scroll handler here. GCMouse's scroll dpad only fires for plain HID
|
||||
// wheel deltas — trackpad/Magic Mouse scrolling is gesture-based and never
|
||||
// reaches GameController. Scroll arrives via the stream view's scrollWheel
|
||||
// override (NSEvent covers wheels too) → sendScroll().
|
||||
}
|
||||
|
||||
/// Forward a scroll gesture, WHEEL_DELTA(120)-scaled (positive = up / right,
|
||||
/// Moonlight's convention). Fed by StreamLayerView.scrollWheel — the only delivery
|
||||
/// path that covers trackpad/Magic Mouse gestures (GCMouse never reports them).
|
||||
/// Fractional remainders accumulate so slow two-finger scrolling isn't truncated away.
|
||||
public func sendScroll(dx: Float, dy: Float) {
|
||||
guard forwarding else { return }
|
||||
let fy = dy + residualScrollY
|
||||
let fx = dx + residualScrollX
|
||||
let iy = fy.rounded(.towardZero)
|
||||
let ix = fx.rounded(.towardZero)
|
||||
residualScrollY = fy - iy
|
||||
residualScrollX = fx - ix
|
||||
if iy != 0 { connection.send(.scroll(Int32(iy))) }
|
||||
if ix != 0 { connection.send(.scroll(Int32(ix), horizontal: true)) }
|
||||
}
|
||||
|
||||
private func attach(keyboard: GCKeyboard) {
|
||||
|
||||
@@ -215,6 +215,23 @@ public final class StreamLayerView: NSView {
|
||||
super.mouseUp(with: event)
|
||||
}
|
||||
|
||||
/// Scroll is forwarded from here, not from GCMouse: trackpad/Magic Mouse gestures
|
||||
/// never reach GameController's scroll dpad. While captured the cursor is parked
|
||||
/// mid-view, so this view receives every scroll event. Precise (gesture) deltas are
|
||||
/// pixels — ~0.1 wheel notch per pixel (SDL's factor) → ×12 for WHEEL_DELTA(120);
|
||||
/// classic wheels report lines, one notch = ±1 → ×120. Signs pass through as-is,
|
||||
/// preserving the user's local (natural-)scrolling preference.
|
||||
public override func scrollWheel(with event: NSEvent) {
|
||||
guard captured, let inputCapture else {
|
||||
super.scrollWheel(with: event)
|
||||
return
|
||||
}
|
||||
let scale: Float = event.hasPreciseScrollingDeltas ? 12 : 120
|
||||
inputCapture.sendScroll(
|
||||
dx: Float(event.scrollingDeltaX) * scale,
|
||||
dy: Float(event.scrollingDeltaY) * scale)
|
||||
}
|
||||
|
||||
// While captured, the view is first responder and consumes key events — GC delivers
|
||||
// them to the host independently, and consuming here stops the responder chain's
|
||||
// "unhandled keyDown" beep without touching the event stream GC may rely on.
|
||||
|
||||
Reference in New Issue
Block a user