Skip to content

fix(input): fix PS/2 keyboard missing wake-up option in context menu - #835

Closed
GongHeng2017 wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/pms-bug-bot/b1d75eea6e4d
Closed

GongHeng2017 wants to merge 1 commit into
linuxdeepin:develop/eaglefrom
GongHeng2017:agent/pms-bug-bot/b1d75eea6e4d

Conversation

@GongHeng2017

@GongHeng2017 GongHeng2017 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

修复 PMS BUG-294489

问题描述:在华为 L420 笔记本上打开设备管理器→键盘页面,右键键盘设备"AT Translated Set 2 keyboard"时,右键菜单中缺少"允许唤起电脑"选项。

根因分析:

  1. 根因层:DeviceInput::getPS2Syspath() 在 event 号匹配失败时不剥离 m_SysPath 尾部 /input/inputN 后缀即返回 true,导致下游 wakeupPath() 拼接路径多出一级 input,canWakeupMachine() 打开文件失败返回 false,右键菜单不显示"允许唤起电脑"选项。

  2. 症状层:wakeupPath() 仅判断 m_Name.contains("PS/2"),而 "AT Translated Set 2 keyboard" 的 m_Name 不含 "PS/2"(但 m_Interface = "PS/2"),导致 PS/2 设备误走 sysfs 路径分支。同文件 isWakeupMachine() 已使用 m_Name || m_Interface 双条件判断,两者不一致。

修复方案(双方案,经方案裁决通过):

# 层级 位置 改动
1 根因层 DeviceInput.cpp:210 getPS2Syspath() return true 前兜底正则剥离 /input/inputN 后缀
2 症状层 DeviceInput.cpp:508 wakeupPath() 条件补齐 m_Interface.contains("PS/2")

PMS: https://pms.uniontech.com/bug-view-294489.html
目标分支: develop/eagle

Summary by Sourcery

Bug Fixes:

  • Restore the “allow wake the computer” context-menu option for PS/2 keyboards by correcting wake-up path detection and sysfs path handling.

1. 根因:getPS2Syspath() 在 event 号匹配失败时不剥离 m_SysPath
   尾部 /input/inputN 后缀即返回 true,导致下游 wakeupPath() 拼接
   路径多出一级 input,canWakeupMachine() 打开文件失败返回 false,
   右键菜单不显示"允许唤起电脑"选项
2. 方案1(根因层):getPS2Syspath() return true 前新增兜底正则剥离
   /input/inputN 后缀,确保 m_SysPath 始终为不含后缀的设备路径
3. 方案2(症状层):wakeupPath() 判断条件由 m_Name.contains("PS/2")
   补齐为 m_Name.contains("PS/2") || m_Interface.contains("PS/2"),
   与同文件 isWakeupMachine() 逻辑统一
4. 影响:PS/2 键盘(如 AT Translated Set 2 keyboard)右键菜单恢复
   显示"允许唤起电脑"选项;非 PS/2 设备不受影响

Log: 修复PS/2键盘右键菜单缺少允许唤起电脑选项的问题

Influence:
1. 测试PS/2键盘右键菜单显示"允许唤起电脑"选项
2. 测试非PS/2设备右键菜单和唤醒功能不受影响
3. 验证getPS2Syspath()在event号匹配失败时正确剥离路径后缀

PMS: BUG-294489
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes missing PS/2 keyboard wake-up actions by correcting fallback sysfs path normalization and aligning wake-up path selection with both the device name and interface identifiers.

Sequence diagram for PS/2 keyboard wake-up path selection

sequenceDiagram
    participant DeviceManager
    participant DeviceInput
    participant WakeupCheck

    DeviceManager->>DeviceInput: getPS2Syspath(dfs)
    alt event number matched
        DeviceInput->>DeviceInput: m_SysPath normalized
    else event number unmatched
        DeviceInput->>DeviceInput: QRegExp.exactMatch(m_SysPath)
        DeviceInput->>DeviceInput: m_SysPath = stripReg.cap(1)
    end
    DeviceInput-->>DeviceManager: return true
    DeviceManager->>DeviceInput: wakeupPath()
    alt m_Name.contains(PS/2) or m_Interface.contains(PS/2)
        DeviceInput-->>DeviceManager: /proc/acpi/wakeup
    else non-PS/2 device
        DeviceInput-->>DeviceManager: /sys.../power/wakeup
    end
    DeviceManager->>WakeupCheck: canWakeupMachine()
Loading

File-Level Changes

Change Details Files
Normalize the PS/2 sysfs path when event-based matching cannot identify the device node.
  • Add a fallback regular expression that removes the trailing /input/inputN component before returning success.
  • Preserve the corrected base path for downstream wake-up capability checks.
deepin-devicemanager/src/DeviceManager/DeviceInput.cpp
Recognize PS/2 keyboards by either their device name or interface when selecting the wake-up mechanism.
  • Extend the PS/2 branch condition to include m_Interface.contains("PS/2").
  • Route devices such as AT Translated Set 2 keyboard to /proc/acpi/wakeup instead of the generic sysfs path.
deepin-devicemanager/src/DeviceManager/DeviceInput.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值。本次提交修复了 PS/2 键盘右键菜单缺少"允许唤起电脑"选项的问题,代码变更最小化,注释清晰,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰,边界处理完善。正则表达式 (.*)/input/input[0-9]{1,2}$ 语法正确,exactMatch() 和 cap(1) 方法使用正确。|| 条件扩展逻辑正确,与 isWakeupMachine() 逻辑统一。不匹配时保持原值不变,边界处理完善。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. deepin-devicemanager/src/DeviceManager/DeviceInput.cpp:210 - 使用 QRegExp(Qt5 废弃 API),建议替换为 QRegularExpression

建议: 建议将 QRegExp 替换为 QRegularExpression,使用 QRegularExpression::match() 和 captured() 方法。注释完整清晰,代码结构合理,变更最小化。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 性能良好,资源使用合理。正则匹配操作在短字符串(设备路径)上执行,性能影响可忽略。无频繁系统调用,无资源泄漏。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 存在0个安全漏洞。m_SysPath 为内部变量,非用户直接输入,无注入风险。无硬编码密钥,无敏感信息泄露。


💡 改进建议代码示例

// 建议使用 QRegularExpression 替代 QRegExp
#include <QRegularExpression>

// 兜底:event 号匹配失败时 m_SysPath 仍可能带有 /input/inputN 后缀,剥离之
QRegularExpression stripReg("(.*)/input/input[0-9]{1,2}$");
QRegularExpressionMatch match = stripReg.match(m_SysPath);
if (match.hasMatch()) {
    m_SysPath = match.captured(1);
}

本报告由 AI 代码审查工具自动生成

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