Skip to content

refactor: control unit进一步细分#1191

Merged
MistEO merged 2 commits intomainfrom
refactor/control_unit
Mar 7, 2026
Merged

refactor: control unit进一步细分#1191
MistEO merged 2 commits intomainfrom
refactor/control_unit

Conversation

@MistEO
Copy link
Member

@MistEO MistEO commented Mar 7, 2026

Summary by Sourcery

通过将滚动支持显式化并与具体控制器关联,以及将相对移动能力从基础输入接口中分离出来,优化控制单元接口设计。

新功能:

  • 引入专用的 CustomControlUnitAPIGamepadControlUnitAPI 接口,用于更清晰地描述不同控制器的能力。
  • 为支持相对光标移动的 Win32 输入方式新增 RelativeMoveInput 接口。

Bug 修复:

  • 确保调试控制器和通用控制器在不支持滚动时正确报告为“不支持”,而不是静默成功,或者复现并不适用的滚动操作。
  • 使 Python 和 NodeJS 绑定及测试与新的滚动支持规则保持一致,在不支持滚动的场景下断言失败。

增强:

  • ControllerAgent 中的滚动处理限制为 Win32 控制单元以及显式实现滚动功能的自定义控制单元,否则记录错误日志。
  • 重构游戏手柄控制单元处理逻辑,在库持有者和绑定中全面使用新的 GamepadControlUnitAPI
  • 更新 Win32 输入管理逻辑,仅在底层输入实现支持时才触发相对鼠标移动。

文档:

  • 在英文和中文的 API 概览及管线协议参考中,记录“仅 Win32 控制器和实现了滚动功能的自定义控制器支持滚动”。

测试:

  • 调整控制器 API 和代理测试,用于验证在不支持滚动操作的控制器上滚动失败的行为。

杂项:

  • 从从未支持滚动和相对移动操作的控制器与输入中移除未使用的 scrollrelative_move 方法,简化控制单元 API 表面。
Original summary in English

Summary by Sourcery

Refine control unit interfaces by making scroll support explicit and controller-specific, and by separating relative-move capabilities from the base input interfaces.

New Features:

  • Introduce dedicated CustomControlUnitAPI and GamepadControlUnitAPI interfaces to clarify controller capabilities.
  • Add a RelativeMoveInput interface for Win32 input methods that support relative cursor movement.

Bug Fixes:

  • Ensure debug and generic controllers correctly report scroll as unsupported rather than silently succeeding or replaying scroll actions that are not applicable.
  • Align Python and NodeJS bindings and tests with the new scroll support rules, asserting failures where scroll is not supported.

Enhancements:

  • Restrict scroll handling in ControllerAgent to Win32 control units and custom control units that explicitly implement scroll, logging an error otherwise.
  • Refactor gamepad control unit handling to use the new GamepadControlUnitAPI throughout library holders and bindings.
  • Update Win32 input management so relative mouse movement is only invoked when supported by the underlying input implementation.

Documentation:

  • Document that scroll is supported only by Win32 controllers and custom controllers that implement scroll in both English and Chinese API overviews and pipeline protocol references.

Tests:

  • Adjust controller API and agent tests to validate scroll failure behavior on controllers that do not support scroll operations.

Chores:

  • Remove unused scroll and relative_move methods from controllers and inputs that never supported these operations, simplifying the control unit API surface.

Copilot AI review requested due to automatic review settings March 7, 2026 12:04
Copy link
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 个问题

给 AI 代理(Agents)的提示
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="source/MaaFramework/Controller/ControllerAgent.cpp" line_range="870-871" />
<code_context>
     cv::Point point = preproc_touch_point(param.point);
-    if (!control_unit_->touch_move(0, point.x, point.y, 0)) {
-        LogWarn << "Failed to move to scroll position" << VAR(point);
+    auto move_to_scroll_position = [&]() {
+        if (!control_unit_->touch_move(0, point.x, point.y, 0)) {
+            LogWarn << "Failed to move to scroll position" << VAR(point);
+        }
</code_context>
<issue_to_address>
**issue (bug_risk):** 请考虑在 `touch_move` 调用失败时向上层传播该失败,而不是只记录日志。

之前,当 `touch_move` 失败时,`handle_scroll` 会返回 `false`,但现在的新 lambda 只记录一条警告日志,并且仍然尝试执行 `scroll`,这改变了可观测行为,并可能掩盖定位错误。如果你希望保留原有语义,建议在 `touch_move` 失败时返回 `false`(或通过其他方式发出失败信号),而不仅仅是记录日志。
</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/MaaFramework/Controller/ControllerAgent.cpp" line_range="870-871" />
<code_context>
     cv::Point point = preproc_touch_point(param.point);
-    if (!control_unit_->touch_move(0, point.x, point.y, 0)) {
-        LogWarn << "Failed to move to scroll position" << VAR(point);
+    auto move_to_scroll_position = [&]() {
+        if (!control_unit_->touch_move(0, point.x, point.y, 0)) {
+            LogWarn << "Failed to move to scroll position" << VAR(point);
+        }
</code_context>
<issue_to_address>
**issue (bug_risk):** Consider propagating failures from `touch_move` instead of only logging.

Previously, `handle_scroll` returned `false` when `touch_move` failed, but the new lambda only logs a warning and still attempts `scroll`, changing observable behavior and potentially hiding positioning errors. If you want to preserve the original semantics, consider returning `false` (or otherwise signaling the failure) when `touch_move` fails instead of just logging it.
</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.

Comment on lines +870 to +871
auto move_to_scroll_position = [&]() {
if (!control_unit_->touch_move(0, point.x, point.y, 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): 请考虑在 touch_move 调用失败时向上层传播该失败,而不是只记录日志。

之前,当 touch_move 失败时,handle_scroll 会返回 false,但现在的新 lambda 只记录一条警告日志,并且仍然尝试执行 scroll,这改变了可观测行为,并可能掩盖定位错误。如果你希望保留原有语义,建议在 touch_move 失败时返回 false(或通过其他方式发出失败信号),而不仅仅是记录日志。

Original comment in English

issue (bug_risk): Consider propagating failures from touch_move instead of only logging.

Previously, handle_scroll returned false when touch_move failed, but the new lambda only logs a warning and still attempts scroll, changing observable behavior and potentially hiding positioning errors. If you want to preserve the original semantics, consider returning false (or otherwise signaling the failure) when touch_move fails instead of just logging it.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR further subdivides ControlUnit interfaces to make controller capabilities (notably scroll and relative_move) explicit by type, and updates bindings/tests/docs accordingly.

Changes:

  • Refactors ControlUnitAPI into more specific interfaces (Win32ControlUnitAPI, CustomControlUnitAPI, GamepadControlUnitAPI) and routes scroll via supported types only.
  • Splits Win32 input relative_move into a separate RelativeMoveInput interface and gates runtime support via dynamic_pointer_cast.
  • Updates Python/NodeJS bindings, C API docs, pipeline docs, and tests to reflect new scroll support behavior (dbg/adb/etc. fail).

Reviewed changes

Copilot reviewed 45 out of 46 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/python/binding_test.py Updates Python binding tests to assert dbg scroll fails.
test/agent/agent_child_test.py Updates agent child test to assert scroll fails.
source/include/LibraryHolder/ControlUnit.h Tightens library-holder return types for custom/gamepad control units.
source/include/ControlUnit/GamepadControlUnitAPI.h Updates Gamepad control-unit handle type in exported API.
source/include/ControlUnit/ControlUnitAPI.h Introduces specialized ControlUnit API subclasses and handle typedefs.
source/binding/Python/maa/controller.py Updates scroll documentation to reflect supported controller types.
source/binding/NodeJS/src/apis/controller.d.ts Updates scroll documentation to reflect supported controller types.
source/MaaWlRootsControlUnit/Manager/WlRootsControlUnitMgr.h Removes scroll override from WlRoots control unit.
source/MaaWlRootsControlUnit/Manager/WlRootsControlUnitMgr.cpp Removes WlRoots scroll implementation.
source/MaaWlRootsControlUnit/Client/WaylandClient.h Removes WaylandClient scroll API.
source/MaaWlRootsControlUnit/Client/WaylandClient.cpp Removes WaylandClient scroll implementation/constants.
source/MaaWin32ControlUnit/Manager/Win32ControlUnitMgr.cpp Gates relative_move behind RelativeMoveInput runtime support.
source/MaaWin32ControlUnit/Input/SeizeInput.h Makes SeizeInput implement RelativeMoveInput.
source/MaaWin32ControlUnit/Input/MessageInput.h Removes unsupported relative_move declaration.
source/MaaWin32ControlUnit/Input/MessageInput.cpp Removes unsupported relative_move implementation.
source/MaaWin32ControlUnit/Input/LegacyEventInput.h Removes unsupported relative_move declaration.
source/MaaWin32ControlUnit/Input/LegacyEventInput.cpp Removes unsupported relative_move implementation.
source/MaaWin32ControlUnit/Base/UnitBase.h Introduces RelativeMoveInput interface.
source/MaaPlayCoverControlUnit/Manager/PlayCoverControlUnitMgr.h Removes scroll override from PlayCover control unit.
source/MaaPlayCoverControlUnit/Manager/PlayCoverControlUnitMgr.cpp Removes PlayCover scroll implementation.
source/MaaGamepadControlUnit/Manager/GamepadControlUnitMgr.h Switches gamepad manager to GamepadControlUnitAPI and drops scroll/relative_move overrides.
source/MaaGamepadControlUnit/Manager/GamepadControlUnitMgr.cpp Removes gamepad scroll/relative_move implementations.
source/MaaGamepadControlUnit/API/GamepadControlUnitAPI.cpp Updates exported create/destroy signatures to new handle type.
source/MaaFramework/Controller/ControllerAgent.cpp Routes scroll only for Win32/custom control units; errors otherwise.
source/MaaDbgControlUnit/ReplayRecording/ReplayRecording.h Removes scroll override from replay recording.
source/MaaDbgControlUnit/ReplayRecording/ReplayRecording.cpp Removes replay recording scroll logic.
source/MaaDbgControlUnit/CarouselImage/CarouselImage.h Removes scroll override from carousel image dbg controller.
source/MaaDbgControlUnit/CarouselImage/CarouselImage.cpp Removes carousel image scroll implementation.
source/MaaCustomControlUnit/Manager/CustomControlUnitMgr.h Switches custom manager to CustomControlUnitAPI.
source/MaaAdbControlUnit/Manager/InputAgent.h Removes scroll override from ADB input agent.
source/MaaAdbControlUnit/Manager/InputAgent.cpp Removes ADB input agent scroll implementation.
source/MaaAdbControlUnit/Manager/AdbControlUnitMgr.h Removes scroll override from ADB control unit manager.
source/MaaAdbControlUnit/Manager/AdbControlUnitMgr.cpp Removes ADB control unit manager scroll implementation.
source/MaaAdbControlUnit/Input/MtouchHelper.h Removes scroll override from MtouchHelper.
source/MaaAdbControlUnit/Input/MtouchHelper.cpp Removes MtouchHelper scroll implementation.
source/MaaAdbControlUnit/Input/AdbShellInput.h Removes scroll override from AdbShellInput.
source/MaaAdbControlUnit/Input/AdbShellInput.cpp Removes AdbShellInput scroll implementation.
source/MaaAdbControlUnit/EmulatorExtras/MuMuPlayerExtras.h Removes scroll override from MuMu extras.
source/MaaAdbControlUnit/EmulatorExtras/MuMuPlayerExtras.cpp Removes MuMu extras scroll implementation.
source/MaaAdbControlUnit/Base/UnitBase.h Removes scroll from ADB InputBase interface.
source/LibraryHolder/ControlUnit/ControlUnit.cpp Updates holder implementations to return specialized API shared_ptrs.
include/MaaFramework/Instance/MaaController.h Updates scroll API note to reflect supported controller types.
docs/en_us/3.1-PipelineProtocol.md Updates scroll support note in pipeline protocol docs.
docs/en_us/2.2-IntegratedInterfaceOverview.md Updates scroll support note in integrated interface overview.

* @return The control id of the scroll action.
*
* @note Not all controllers support scroll. If not supported, the action will fail.
* @note Scroll is supported by Win32 controllers and custom controllers that implement scroll.
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

This docstring notes which controller types support scroll, but it no longer states what happens when scroll is posted to an unsupported controller. Consider adding an explicit note (similar to MaaControllerPostRelativeMove docs) that the action will fail on unsupported controllers so API consumers know to check job status.

Suggested change
* @note Scroll is supported by Win32 controllers and custom controllers that implement scroll.
* @note Scroll is supported by Win32 controllers and custom controllers that implement scroll.
* @note If the controller does not support scroll, the action will fail and the job status will indicate failure.

Copilot uses AI. Check for mistakes.
> [!NOTE]
>
> - Adb Controller and PlayCover Controller do not support scroll operations. Only Win32 Controller is supported.
> - Win32 controllers and custom controllers that implement `scroll` support scroll operations.
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

The NOTE explains which controllers support Scroll, but it omits that posting this action to other controllers will fail (the previous wording made this explicit). Consider adding a bullet clarifying that unsupported controller types will return a failed action/job, to set correct expectations for pipeline users.

Suggested change
> - Win32 controllers and custom controllers that implement `scroll` support scroll operations.
> - Win32 controllers and custom controllers that implement `scroll` support scroll operations.
> - Posting a `Scroll` action to controllers that do not implement `scroll` will result in a failed action/job.

Copilot uses AI. Check for mistakes.
Comment on lines 462 to 467
Asynchronously scroll. This is an asynchronous operation that immediately returns an operation id. You can query the status via `MaaControllerStatus` and `MaaControllerWait`.

> [!NOTE]
>
> - Only Win32 Controller supports scroll operations. Adb Controller does not support scrolling.
> - Win32 controllers and custom controllers that implement `scroll` support scroll operations.
> - The `dx`/`dy` values are sent directly as scroll increments. The Windows standard wheel increment is 120 (WHEEL_DELTA) per notch. Using multiples of 120 is recommended for best compatibility.
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

Similar to the relative-move section above, this scroll section should explicitly mention that operations posted to unsupported controllers will fail (so callers know they must check status). Right now it only lists supported controller types.

Copilot uses AI. Check for mistakes.

Note:
不是所有控制器都支持滚动操作 / Not all controllers support scroll operation
Win32 控制器和实现了 scroll 的自定义控制器支持滚动操作 / Win32 controllers and custom controllers with scroll support this operation
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

The English sentence in this Note is grammatically incorrect ("custom controllers with scroll support this operation"). Consider rephrasing to match the other bindings/docs, e.g. "Win32 controllers and custom controllers that implement scroll support this operation."

Copilot uses AI. Check for mistakes.
@MistEO MistEO merged commit 4862d0a into main Mar 7, 2026
14 checks passed
@MistEO MistEO deleted the refactor/control_unit branch March 7, 2026 12:23
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