Conversation
Contributor
There was a problem hiding this comment.
Hey - 我在这里给出了一些整体性的反馈:
- 在析构函数中,你移除了
s_active_instance_.compare_exchange_strong(this, nullptr)调用,但activate_mouse_lock_follow仍然会设置s_active_instance_ = this;建议在销毁或停用时恢复相应的清理逻辑,以避免将悬空指针暴露给其他线程。 - 你将
mouse_lock_follow_active_改成了std::atomic<bool>,但跟踪线程使用的其他状态(例如lock_anchor_cursor_、lock_offset_x_、lock_offset_y_、lock_anchor_window_)仍然是非原子的;请再次检查读/写模式,以确保在mouse_lock_follow_active_现在可能更明显地允许并发线程访问的情况下,不会产生数据竞争。 - 在
ensure_process_dpi_awareness_once中,之前的实现会在SetProcessDpiAwareness返回E_ACCESSDENIED后停止,而新版本忽略了 HRESULT 并始终返回 0;请确认这是有意删除对E_ACCESSDENIED的特殊处理,并在该情况下不再提前返回。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- In the destructor you removed the `s_active_instance_.compare_exchange_strong(this, nullptr)` call, but `activate_mouse_lock_follow` still sets `s_active_instance_ = this`; consider restoring a corresponding clear on destruction or deactivation to avoid leaving a dangling pointer visible to other threads.
- You changed `mouse_lock_follow_active_` to `std::atomic<bool>` but other state used by the tracking thread (e.g. `lock_anchor_cursor_`, `lock_offset_x_`, `lock_offset_y_`, `lock_anchor_window_`) remains non-atomic; double-check the read/write pattern to ensure there is no data race now that `mouse_lock_follow_active_` may allow concurrent thread access more visibly.
- In `ensure_process_dpi_awareness_once`, the previous implementation stopped after `SetProcessDpiAwareness` returned `E_ACCESSDENIED`, whereas the new version ignores the HRESULT and always returns 0; confirm that it is intentional to drop the special handling of `E_ACCESSDENIED` and not early-out in that case.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've left some high level feedback:
- In the destructor you removed the
s_active_instance_.compare_exchange_strong(this, nullptr)call, butactivate_mouse_lock_followstill setss_active_instance_ = this; consider restoring a corresponding clear on destruction or deactivation to avoid leaving a dangling pointer visible to other threads. - You changed
mouse_lock_follow_active_tostd::atomic<bool>but other state used by the tracking thread (e.g.lock_anchor_cursor_,lock_offset_x_,lock_offset_y_,lock_anchor_window_) remains non-atomic; double-check the read/write pattern to ensure there is no data race now thatmouse_lock_follow_active_may allow concurrent thread access more visibly. - In
ensure_process_dpi_awareness_once, the previous implementation stopped afterSetProcessDpiAwarenessreturnedE_ACCESSDENIED, whereas the new version ignores the HRESULT and always returns 0; confirm that it is intentional to drop the special handling ofE_ACCESSDENIEDand not early-out in that case.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the destructor you removed the `s_active_instance_.compare_exchange_strong(this, nullptr)` call, but `activate_mouse_lock_follow` still sets `s_active_instance_ = this`; consider restoring a corresponding clear on destruction or deactivation to avoid leaving a dangling pointer visible to other threads.
- You changed `mouse_lock_follow_active_` to `std::atomic<bool>` but other state used by the tracking thread (e.g. `lock_anchor_cursor_`, `lock_offset_x_`, `lock_offset_y_`, `lock_anchor_window_`) remains non-atomic; double-check the read/write pattern to ensure there is no data race now that `mouse_lock_follow_active_` may allow concurrent thread access more visibly.
- In `ensure_process_dpi_awareness_once`, the previous implementation stopped after `SetProcessDpiAwareness` returned `E_ACCESSDENIED`, whereas the new version ignores the HRESULT and always returns 0; confirm that it is intentional to drop the special handling of `E_ACCESSDENIED` and not early-out in that case.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors parts of MaaFramework’s Win32 message-based input implementation (notably mouse-lock-follow) and tidies the C++ module export surface to better match the public API.
Changes:
- Refactors Win32
MessageInputmouse-lock-follow internals (extracts window-centering helper, improves state thread-safety via atomics, minor flow cleanups). - Simplifies DLL/function resolution logic for DPI-awareness initialization and ntdll suspend/resume calls.
- Removes
MaaControllerPostMouseLockFollowfrom the module export list.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| source/modules/MaaFramework.cppm | Removes an exported symbol (MaaControllerPostMouseLockFollow) from the module surface. |
| source/MaaWin32ControlUnit/Input/MessageInput.h | Adjusts mouse-lock-follow state to std::atomic<bool> and adds a helper declaration. |
| source/MaaWin32ControlUnit/Input/MessageInput.cpp | Refactors DPI-awareness one-time init, ntdll loading, and mouse-lock-follow window positioning; uses std::clamp. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@ZeroAd-06 康康
Summary by Sourcery
优化 Win32 基于消息的输入控制器中的 DPI 感知初始化、鼠标锁定跟随行为以及目标进程处理。
Bug 修复:
mouse_lock_follow_active_改为原子类型,并移除过时的活动实例重置逻辑,以更准确反映实际的跟踪状态。增强功能:
SetWindowPos处理的健壮性。std::clamp,并清理鼠标锁定跟随处理中的冗余注释和日志格式。Original summary in English
Summary by Sourcery
Refine DPI awareness initialization, mouse lock follow behavior, and target process handling for the Win32 message-based input controller.
Bug Fixes:
Enhancements: