Skip to content

fix(windows): preserve large virtual mouse scroll input - #855

Merged
Yundi339 merged 2 commits into
masterfrom
fix_zakomouse_roll
Jul 28, 2026
Merged

fix(windows): preserve large virtual mouse scroll input#855
Yundi339 merged 2 commits into
masterfrom
fix_zakomouse_roll

Conversation

@Yundi339

Copy link
Copy Markdown
Member

说明

修复 Zako 虚拟鼠标在大幅垂直或水平滚动时丢失输入的问题。

原实现会从累计值中扣除全部滚轮格数,但 HID 实际发送值会被限制到 [-127, 127],导致超出单次报告范围的滚动量被永久丢弃。

Fixes #849

修改

  • 垂直和水平滚轮按照 HID 单次范围分片发送。
  • 每个分片发送成功后才从累计值中扣除。
  • 发送失败时停止发送并保留尚未发送的累计量。
  • 保留不足一个 WHEEL_DELTA 的高精度滚动余量。

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c5b85e88-6a0f-4c59-b277-9edb79c20e96

📥 Commits

Reviewing files that changed from the base of the PR and between edb49e1 and 1c776d9.

📒 Files selected for processing (1)
  • src/platform/windows/input.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/platform/windows/input.cpp

Summary by CodeRabbit

  • Bug Fixes
    • 改善 Windows 平台虚拟鼠标的高精度垂直/水平滚动:将累计滚动按 WHEEL_DELTA 粒度拆分为多个事件,减少快速或细微滚动时的偏差。
    • 当注入失败时不再错误累积;同时在回退到其他输入路径前会清空累计值,避免出现陈旧滚动重复发送。
    • 保持原有输入注入逻辑的整体稳定性与一致性。

Walkthrough

Windows 虚拟鼠标的垂直和水平滚轮处理改为按 WHEEL_DELTA 分片,在 [-127, 127] 范围内循环发送累积值;发送失败或切换到 SendInput() 回退路径时清理相应累积值。

Changes

Windows 滚轮累积量处理

Layer / File(s) Summary
滚轮累积量分片与回退清理
src/platform/windows/input.cpp
scroll()hscroll()WHEEL_DELTA 循环处理累积滚轮量,将每批 notch 数限制在 [-127, 127],成功发送后扣除实际增量;设备发送失败时清零并停止,进入 SendInput() 回退路径前清零旧累积值。

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了 Windows 虚拟鼠标大滚动输入保留的核心修复。
Description check ✅ Passed 描述与滚动分片发送、失败保留余量的修改一致。
Linked Issues check ✅ Passed 实现了 #849 要求的垂直/水平滚动分片发送与失败时保留累计值。
Out of Scope Changes check ✅ Passed 未见明显与 #849 无关的代码改动;额外的回退前清零属于同一修复链路。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_zakomouse_roll

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/platform/windows/input.cpp`:
- Around line 712-723: Update the virtual mouse scroll handling around scroll(),
hscroll(), and set_mouse_mode(...) so pending vmouse_*scroll_accum values are
not lost when virtual scrolling fails, SendInput fallback occurs, or vmouse_dev
is destroyed. Forward pending deltas through SendInput where appropriate or
explicitly reset them, and add a regression test covering recovery after
virtual-device failure or mode switching.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9bfa8380-c3ab-40fe-b8bd-21a72beaf2d6

📥 Commits

Reviewing files that changed from the base of the PR and between b6174e3 and edb49e1.

📒 Files selected for processing (1)
  • src/platform/windows/input.cpp
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Windows
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.{cpp,c,h}

⚙️ CodeRabbit configuration file

src/**/*.{cpp,c,h}: Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

Files:

  • src/platform/windows/input.cpp
src/platform/**

⚙️ CodeRabbit configuration file

src/platform/**: 平台抽象层代码(Windows/Linux/macOS)。确保各平台实现一致, 注意 Windows API 调用的错误处理和资源释放。

Files:

  • src/platform/windows/input.cpp
🔇 Additional comments (2)
src/platform/windows/input.cpp (2)

712-723: 🩺 Stability & Availability

请确认累计量更新与发送已被串行化。

vmouse_vscroll_accumvmouse_hscroll_accum 是共享的普通 int;新循环把读取、设备发送和扣除拆成了多步。若多个输入回调并发执行,同一轴可能丢失或重复滚轮量。请确认上层调度保证这些函数串行调用;否则应使用互斥量保护整个累计/发送序列。

依据路径指令,本文件需要重点检查线程安全。

Also applies to: 743-754

Source: Path instructions


712-723: 🩺 Stability & Availability

为异常大的累计量设置处理上限。

当前 while 会同步耗尽整个 int 累计量;极端输入最多可能触发约 14 万次设备调用,长时间阻塞输入线程。设备持续发送失败时,累计值还可能在 += distance 处发生有符号整数溢出。请确认上游限制了 distance 和累计量;否则应限制单次调用的批次数,并保留余量异步续发。

Also applies to: 743-754

Comment thread src/platform/windows/input.cpp
@Yundi339
Yundi339 merged commit 8131e30 into master Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Zako 虚拟鼠标大幅滚动时会丢失滚轮输入

1 participant