Skip to content

fix(gamepad): release GCK slots correctly#52

Merged
qiin2333 merged 1 commit into
masterfrom
codex/fix-gamepad-slot-release
Jun 26, 2026
Merged

fix(gamepad): release GCK slots correctly#52
qiin2333 merged 1 commit into
masterfrom
codex/fix-gamepad-slot-release

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 修掉 GCK 设备断开时先删 deviceId 映射、后释放槽位导致 slotOccupied 残留的问题,杂鱼默认 0 槽别再乱背锅了。
  • 对未知 GCK OFFLINE 事件加保护,避免误释放一号槽。
  • 把 2311/2313 的注释和设置文案整理成 Guide/Mode 兼容键语义,保留 USB 驱动作为 GCK 识别不足时的兜底。

为啥要改

  • 多 HID 接口或异常断开时,旧流程可能释放不到真实槽位,后续手柄重连/多手柄分配会被残留状态卡住。
  • 2311/2313 在官方命名、InputKit 上报和不同手柄实测之间有差异,文案需要讲清楚这是兼容映射,不是假装只有一个 Home 键。

验证

  • git diff --check
  • node hvigorw.js assembleHap --no-daemon --no-incremental -p buildMode=debug 未通过:本机环境报 Invalid value of DEVECO_SDK_HOME,没有进入代码编译阶段。

Summary by CodeRabbit

  • 新功能

    • 手柄设置中的相关按键动作选项文案已更新为更准确的 Guide/Mode 语义,选择器说明也同步优化。
  • Bug 修复

    • 改善了部分手柄 2313 按键的识别与映射,减少按键上报丢失的问题。
    • 优化手柄断开时的槽位释放处理,降低误释放和状态异常的风险。
  • 文档

    • 更新了按键说明与兼容性注释,帮助更清晰理解不同手柄按键的对应关系。

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@qiin2333, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 46 minutes and 13 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e377c061-be91-40b7-b699-bc4703909f1a

📥 Commits

Reviewing files that changed from the base of the PR and between 9958633 and 8d62e81.

📒 Files selected for processing (5)
  • entry/src/main/ets/pages/SettingsPageV2.ets
  • entry/src/main/ets/service/input/GameControllerService.ets
  • entry/src/main/ets/service/input/GamepadManager.ets
  • entry/src/main/ets/service/input/GamepadTypes.ets
  • nativelib/src/main/cpp/game_controller_native.h
📝 Walkthrough

Walkthrough

本次改动统一了 2313 兼容键在设置页、类型定义和本地常量中的命名与说明,并调整了 GamepadManager 对 2313 KeyEvent 的处理路径,以及 GC 设备离线时的槽位释放逻辑。

Changes

2313 兼容键命名与处理

Layer / File(s) Summary
命名与文案对齐
entry/src/main/ets/pages/SettingsPageV2.ets, entry/src/main/ets/service/input/GameControllerService.ets, entry/src/main/ets/service/input/GamepadTypes.ets, nativelib/src/main/cpp/game_controller_native.h
更新了 2313 相关注释、按键映射说明和设置页文案,内容从 Home 语义改为 Guide/Mode 兼容语义。
2313 KeyEvent 路由
entry/src/main/ets/service/input/GamepadManager.ets
调整了 2313 的 KeyEvent 处理、动作回调说明和映射更新逻辑,保留自定义动作拦截并在 guide/select 映射时更新状态。
离线槽位释放
entry/src/main/ets/service/input/GamepadManager.ets
OFFLINE 分支改为先读取已记录的 slot,再用保存的 slot 显式释放共享槽位,并忽略未注册设备的断开事件。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次修复的核心问题:GCK 手柄断开时的槽位释放逻辑。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-gamepad-slot-release

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.

@qiin2333

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

Copilot AI 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.

Pull request overview

This PR improves Game Controller Kit (GCK) gamepad robustness by fixing slot-release behavior during disconnects (especially with multi-HID interfaces) and clarifying the semantics/UX text around vendor/GCK “menu” keys (2311/2312) and the InputKit compatibility key (2313).

Changes:

  • Fix GCK disconnect flow to release the correct slot even if deviceId -> slot mappings are cleaned before releasing.
  • Add a guard for unknown GCK OFFLINE events to avoid accidentally freeing slot 0.
  • Update comments, mappings, and settings UI copy to describe 2311/2312 as GCK ButtonHome/ButtonMenu and 2313 as a Guide/Mode/Home compatibility key.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
nativelib/src/main/cpp/game_controller_native.h Clarifies 2311/2312 keycode comments to match GCK naming + observed behavior.
entry/src/main/ets/service/input/GamepadTypes.ets Updates 2311/2312/2313 mapping comments and explains 2313 compatibility semantics.
entry/src/main/ets/service/input/GamepadManager.ets Adjusts GCK disconnect slot release order/logic; adds unknown-OFFLINE guard; updates 2313 commentary in KeyEvent handling.
entry/src/main/ets/service/input/GameControllerService.ets Updates button code documentation to distinguish GCK codes vs 2313 InputKit compatibility key.
entry/src/main/ets/pages/SettingsPageV2.ets Updates settings UI copy to reflect Guide/Mode compatibility wording for 2313 behavior.
Comments suppressed due to low confidence (1)

entry/src/main/ets/service/input/GamepadManager.ets:1330

  • 断开流程里无条件删除 gcPhysicalAddressToDeviceId 中指向该 deviceId 的物理地址映射,但当该 deviceId 是“主设备ID”且仍有其他 HID 接口 deviceId 共享同一 slot 在线时,会导致后续同 physAddr 的新接口无法命中去重(可能被当作新手柄分配新槽位)。建议在存在同 slot 的其他 deviceId 时,把 physAddr 映射迁移到仍在线的 deviceId,而不是直接 delete。
      // 清理物理地址映射
      const addrEntries = Array.from(this.gcPhysicalAddressToDeviceId.entries());
      for (let i = 0; i < addrEntries.length; i++) {
        const addr = addrEntries[i][0];
        const id = addrEntries[i][1];
        if (id === deviceId) {
          this.gcPhysicalAddressToDeviceId.delete(addr);
          break;
        }
      }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@qiin2333 qiin2333 merged commit 6f8e228 into master Jun 26, 2026
3 checks passed
@qiin2333 qiin2333 deleted the codex/fix-gamepad-slot-release branch June 26, 2026 09:32
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