Skip to content

fix: restore hardware sleep shortcuts - #188

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/sleep-shortcut-compatibility
Oct 15, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/sleep-shortcut-compatibility

Conversation

@yixinshark

@yixinshark yixinshark commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Restore hardware sleep shortcuts with independent Sleep and Suspend bindings invoking dde-shortcut-tool power suspend. On X11, a missing keysym no longer rolls back the other available binding.

  • Accept Qt::Key_Sleep in shared shortcut validation.
  • Check suspend availability before locking the session.
  • Keep bare Sleep inactive on Wayland until Treeland accepts it, preventing rejection of the startup shortcut and gesture batch. Suspend remains a separate binding.

Validation

  • Isolated shortcut module and relevant test targets built successfully.
  • Converter checks: 14 passed.
  • Xvfb backend checks: 12 passed, including four Sleep/Suspend keymap scenarios; no skipped checks in the successful run.
  • JSON/INI registration, generated install entries, and git diff --check passed.
  • Treeland validation was checked with an extracted-function probe; full Wayland startup and physical suspend were not exercised.

Pms: BUG-378959

Summary by Sourcery

Restore reliable hardware Sleep and Suspend shortcuts across supported backends while preserving unrelated shortcut registrations.

New Features:

  • Add independent Sleep and Suspend hardware shortcut registrations that invoke system suspension through dde-shortcut-tool.
  • Extend the power command interface with a suspend action.

Bug Fixes:

  • Restore hardware Sleep/Suspend shortcut recognition and prevent an unavailable suspend request from locking the session.
  • Prevent unsupported bare Sleep shortcuts from causing Wayland/Treeland shortcut registration batches to be rejected.
  • Allow X11 to retain available Sleep or Suspend bindings independently when the other keysym is absent.

Tests:

  • Add converter coverage for Sleep and Suspend multimedia key recognition.
  • Add X11 regression coverage for independent Sleep/Suspend keymap registration and activation scenarios.

@sourcery-ai

sourcery-ai Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

Restores independent hardware Sleep and Suspend shortcuts, routes both through the suspend power action with availability-aware locking, and hardens key validation and backend registration behavior for X11 and Treeland-compatible Wayland environments.

Sequence diagram for hardware suspend shortcut execution

sequenceDiagram
    participant Shortcut as ShortcutHandler
    participant Tool as dde_shortcut_tool
    participant Power as PowerController
    participant Session as SessionLock
    participant System as SystemSuspend

    Shortcut->>Tool: execute suspend
    Tool->>Power: execute suspend
    Power->>Power: canSuspend()
    alt suspend unavailable
        Power-->>Tool: return true
    else suspend available
        Power->>Power: shouldLockOnSleep(config)
        opt lock on sleep
            Power->>Session: doLock(true)
        end
        Power->>System: systemSuspend()
        Power-->>Tool: return true
    end
Loading

Flow diagram for Sleep and Suspend shortcut registration

flowchart TD
    Config[Sleep and Suspend shortcut configs] --> Validate[QKeySequenceConverter validates Qt Key_Sleep]
    Validate --> Backend{Backend}
    Backend -->|X11| X11[X11 registers available bindings independently]
    Backend -->|Wayland| Guard{Contains bare Sleep?}
    Guard -->|Yes| Reject[WaylandKeyHandler rejects Sleep]
    Guard -->|No| Register[Suspend binding registers]
    X11 --> Action[dde-shortcut-tool power suspend]
    Register --> Action
Loading

File-Level Changes

Change Details Files
Added separate Sleep and Suspend shortcut registrations that invoke the suspend power action.
  • Registered new Sleep and Suspend configuration IDs.
  • Added generated shortcut metadata with the suspend command.
  • Exposed the suspend action through the power controller CLI and dispatch path.
  • Checked suspend availability before applying sleep locking behavior.
src/plugin-qt/shortcut/configs/org.deepin.dde.keybinding.ini
src/plugin-qt/shortcut/configs/org.deepin.dde.keybinding.shortcut.sleep/org.deepin.shortcut.json
src/plugin-qt/shortcut/configs/org.deepin.dde.keybinding.shortcut.suspend/org.deepin.shortcut.json
src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp
Made hardware Sleep and Suspend keys valid and resilient across shortcut backends.
  • Recognized Qt::Key_Sleep as a multimedia key while preserving existing key classifications.
  • Prevented Wayland from queuing unsupported bare Sleep bindings that Treeland would reject as a batch.
  • Added converter coverage for Sleep, Suspend, and representative multimedia/non-multimedia keys.
  • Added X11 keymap scenarios verifying Sleep and Suspend register independently and do not disrupt unrelated shortcuts.
src/plugin-qt/shortcut/src/core/qkeysequenceconverter.cpp
src/plugin-qt/shortcut/src/backend/wayland/waylandkeyhandler.cpp
src/plugin-qt/shortcut/tests/tst_qkeysequenceconverter.cpp
src/plugin-qt/shortcut/tests/tst_x11grabresilientshortcuts.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 分通过阈值,代码质量符合要求。本次提交恢复了硬件睡眠快捷键功能,代码逻辑清晰,测试覆盖完善,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。所有C++代码语法无误,快捷键注册→键值验证→Wayland兼容性守卫→动作执行的逻辑链条完整。handleSystemSuspend()中先检查canSuspend()再锁屏的逻辑正确,避免了在不支持挂起的机器上不必要的锁屏UI延迟。测试代码使用Qt测试框架规范,智能指针和qScopeGuard确保资源正确释放。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/plugin-qt/shortcut/configs/org.deepin.dde.keybinding.shortcut.suspend/org.deepin.shortcut.json:20 - Suspend快捷键的displayName.name[zh_CN]设置为"睡眠",与Sleep快捷键的中文翻译重复,应改为"挂起"或"休眠"以区分两个不同的快捷键功能

建议: 代码结构清晰,注释完整。注释充分解释了Treeland兼容性问题、Qt键值位置异常等设计决策。测试覆盖全面,包括单元测试和X11集成测试。建议修正Suspend快捷键配置文件中displayName的中文翻译,将"睡眠"改为"挂起"以与Sleep区分。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,资源使用合理。handleSystemSuspend()中canSuspend()前置检查是良好的性能优化,避免了在不支持挂起的机器上触发500ms锁屏UI延迟。无频繁系统调用,无不必要的计算。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 存在0个安全漏洞,安全合规。triggerValue中的命令执行来自配置文件而非用户输入,无注入风险。无硬编码密钥或敏感信息泄露。


💡 改进建议代码示例

// 修正 suspend 快捷键配置中的中文翻译
// 文件: org.deepin.dde.keybinding.shortcut.suspend/org.deepin.shortcut.json
// 修改前:
//   "name[zh_CN]": "睡眠"
// 修改后:
//   "name[zh_CN]": "挂起"

// 同步修正 description 字段以保持一致性
// 修改前:
//   "description": "睡眠快捷键"
// 修改后:
//   "description": "挂起快捷键"

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

@deepin-bot

deepin-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.45
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #189

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, yixinshark

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

Register Sleep and Suspend as independent fixed hardware shortcuts that
invoke dde-shortcut-tool power suspend, so an unavailable X11 keysym does
not disable the other binding. Accept Qt::Key_Sleep in shared validation
and check suspend availability before locking the session.

Reject bare Sleep before queuing Wayland bindings while the current
Treeland validator does not support it, preserving the startup shortcut
and gesture batch. Add converter checks and Xvfb regression coverage for
keymaps containing either sleep variant, both, or neither.

将 Sleep 和 Suspend 注册为独立的固定硬件快捷键,统一调用
dde-shortcut-tool power suspend,避免 X11 缺少一种按键符号时
连带禁用另一种绑定。公共校验接受 Qt::Key_Sleep,并在锁屏前
检查待机能力。

当前 Treeland 校验尚不支持无修饰的 Sleep,因此在 Wayland 请求
入队前拒绝该绑定,保护启动时的快捷键和手势批次。补充按键转换
测试及 Xvfb 回归测试,覆盖仅有一种睡眠键、两者都有和都没有的映射。

Log: restore hardware sleep shortcuts
Pms: BUG-378959
Change-Id: I662ac9d99245210ddf0b5b5ee9b7de7ccb0b9a60
@yixinshark
yixinshark force-pushed the fix/sleep-shortcut-compatibility branch from 47b185e to c1550eb Compare October 15, 2026 11:14
@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit a9ffc8a into linuxdeepin:master Oct 15, 2026
5 of 6 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.

3 participants