Skip to content

fix(wlroots): scroll 垂直滚动方向与 win32 保持一致#1269

Merged
MistEO merged 1 commit intoMaaXYZ:mainfrom
mx6436:fix/wlroots-scroll
Apr 14, 2026
Merged

fix(wlroots): scroll 垂直滚动方向与 win32 保持一致#1269
MistEO merged 1 commit intoMaaXYZ:mainfrom
mx6436:fix/wlroots-scroll

Conversation

@mx6436
Copy link
Copy Markdown
Contributor

@mx6436 mx6436 commented Apr 14, 2026

Summary by Sourcery

错误修复:

  • 修正 Wayland 客户端中的垂直滚动方向,使正 dy 对应向上滚动,与外部规范保持一致。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Correct vertical scroll direction in the Wayland client so that positive dy corresponds to upward scrolling as externally specified.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我发现了 1 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="source/MaaWlRootsControlUnit/Client/WaylandClient.cpp" line_range="316" />
<code_context>
-        const int step_y = dy / 120;
+        // Wayland 的垂直滚动方向与 Maa 对外约定(dy > 0 表示向上滚动)相反,
+        // 这里对 dy 取反以与 Win32 等控制器保持一致行为。
+        const int step_y = -dy / 120;
         for (int i = 0; i < abs(step_y); ++i) {
             zwlr_virtual_pointer_v1_axis_discrete(
</code_context>
<issue_to_address>
**issue (bug_risk):** 直接对 `dy` 取反在 `dy == INT_MIN` 时可能导致溢出。

当 `dy == INT_MIN` 时,对有符号 `int` 使用 `-dy` 属于未定义行为(UB)。为避免这一点,可以先使用更宽的有符号类型计算 `step_y`,例如:`long long step_y = -static_cast<long long>(dy) / 120;`,然后再在必要时进行截断/转换回 `int`,以在不发生溢出的前提下保持原有行为。
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得这次评审有帮助,欢迎分享 ✨
帮我变得更有用吧!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审质量。
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="source/MaaWlRootsControlUnit/Client/WaylandClient.cpp" line_range="316" />
<code_context>
-        const int step_y = dy / 120;
+        // Wayland 的垂直滚动方向与 Maa 对外约定(dy > 0 表示向上滚动)相反,
+        // 这里对 dy 取反以与 Win32 等控制器保持一致行为。
+        const int step_y = -dy / 120;
         for (int i = 0; i < abs(step_y); ++i) {
             zwlr_virtual_pointer_v1_axis_discrete(
</code_context>
<issue_to_address>
**issue (bug_risk):** Negating `dy` directly can overflow when `dy == INT_MIN`.

Using `-dy` on a signed `int` is UB when `dy == INT_MIN`. To avoid this, compute `step_y` via a wider signed type, e.g. `long long step_y = -static_cast<long long>(dy) / 120;`, then clamp/cast back to `int` as needed to preserve behavior without overflow.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

const int step_y = dy / 120;
// Wayland 的垂直滚动方向与 Maa 对外约定(dy > 0 表示向上滚动)相反,
// 这里对 dy 取反以与 Win32 等控制器保持一致行为。
const int step_y = -dy / 120;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): 直接对 dy 取反在 dy == INT_MIN 时可能导致溢出。

dy == INT_MIN 时,对有符号 int 使用 -dy 属于未定义行为(UB)。为避免这一点,可以先使用更宽的有符号类型计算 step_y,例如:long long step_y = -static_cast<long long>(dy) / 120;,然后再在必要时进行截断/转换回 int,以在不发生溢出的前提下保持原有行为。

Original comment in English

issue (bug_risk): Negating dy directly can overflow when dy == INT_MIN.

Using -dy on a signed int is UB when dy == INT_MIN. To avoid this, compute step_y via a wider signed type, e.g. long long step_y = -static_cast<long long>(dy) / 120;, then clamp/cast back to int as needed to preserve behavior without overflow.

@MistEO MistEO merged commit 2c8aa4c into MaaXYZ:main Apr 14, 2026
18 of 19 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.

2 participants