Skip to content

feat(shortcut): add Treeland compositor action shortcuts to dde-app-shortcuts - #77

Merged
deepin-bot[bot] merged 1 commit into
masterfrom
fix/skip-lock-key-wayland
Jun 3, 2026
Merged

deepin-bot[bot] merged 1 commit into
masterfrom
fix/skip-lock-key-wayland

Conversation

@yixinshark

Copy link
Copy Markdown
Contributor

概述

将 Treeland 合成器的原生快捷键从 treeland-shortcut-client 迁移到 dde-app-shortcuts,通过 triggerType=3 (Action) 注册到 compositor,由合成器直接处理执行。

背景

Treeland 原有独立的快捷键客户端 (treeland-shortcut),使用 INI 配置文件注册全局快捷键。该客户端已被禁用,需要由 dde-services 的 shortcut 插件接管这些快捷键。

新增快捷键 (20 个)

窗口管理

  • Meta+Up 最大化窗口 (action=11)
  • Meta+Down 取消最大化 (action=12)
  • Meta+D 显示桌面 (action=10)
  • Alt+Space 显示窗口菜单 (action=15)
  • Alt+F4 关闭窗口 (action=14)

工作区

  • Meta+Left / Meta+Right 上/下一个工作区
  • Meta+1 ~ Meta+6 切换到工作区 1-6

任务切换 (keyEventFlags=Press|Repeat)

  • Alt 任务切换器 | Alt+Tab 下一窗口 | Alt+Shift+Backtab 上一窗口
  • Alt+\`` 同应用下一窗口 | Alt+Shift+~` 同应用上一窗口

视图

  • Meta+S 切换多任务视图 | Meta+F11 切换 FPS 显示

技术细节

  • triggerType=3 (Action): WaylandKeyHandler 解析 triggerValue 为 action enum,通过 bind_key() 注册到 compositor,compositor 直接执行
  • keyEventFlags=5: Alt+Tab 系列使用 Press+Repeat (0x1|0x4),匹配 treeland 原有 KeyPressRepeat 模式
  • modifiable: Workspace 1-6 和 FPS Display 设为 false(系统级),其余为 true
  • 翻译: 已通过 update_shortcut_i18n 更新 54 语言 .ts 文件,zh_CN 已手动补翻译

文件变更

  • dde-app-shortcuts/configs/ — 新增 20 个 JSON 配置目录
  • dde-app-shortcuts/configs/org.deepin.dde.shortcut.dde-app.ini — 新增 20 条 SubPath
  • dde-app-shortcuts/translations/ — 更新 55 个翻译文件

参考

  • Treeland 协议: /usr/share/treeland-protocols/treeland-shortcut-manager-v2.xml
  • Action 枚举: 协议 XML action enum (1=notify, 2-7=workspace, 8-9=prev/next_ws, 10=show_desktop, 11=maximize, 12=cancel_maximize, 14=close_window, 15=show_window_menu, 18=toggle_multitask_view, 19=toggle_fps, 23-27=taskswitch)

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

Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@yixinshark
yixinshark force-pushed the fix/skip-lock-key-wayland branch 2 times, most recently from c132a0c to 72750b4 Compare June 3, 2026 08:25
…hortcuts

Add 20 compositor action shortcuts from treeland-shortcut INI configs.
These use triggerType=3 (Action) and register with the compositor via
treeland-shortcut-manager-v2 protocol. The compositor handles execution
directly.

Shortcuts added:
- Window management: maximize(Meta+Up), cancel-maximize(Meta+Down),
  show-desktop(Meta+D), show-window-menu(Alt+Space), close-window(Alt+F4)
- Workspace: prev(Meta+Left), next(Meta+Right), workspace 1-6(Meta+1-6)
- Task switching: enter(Alt), next(Alt+Tab), prev(Alt+Shift+Backtab),
  same-app-next(Alt+`), same-app-prev(Alt+Shift+~)
- View: toggle-multitaskview(Meta+S), toggle-fpsdisplay(Meta+F11)

Workspace and FPS display shortcuts are modifiable=false (system-level).
Task switcher uses keyEventFlags=5 (Press|Repeat) for continuous cycling.

Change-Id: I6a38178cf9dd6f9607acca868b6095c2859acb5f
@yixinshark
yixinshark force-pushed the fix/skip-lock-key-wayland branch from 72750b4 to c0fb619 Compare June 3, 2026 08:26
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已经仔细审查了你提交的 git diff。本次修改主要为 DDE(深度桌面环境)新增了多个窗口管理、工作区切换和任务切换相关的快捷键配置文件(JSON)、主配置以及对应的国际化翻译文件。

整体来看,代码结构清晰,符合 DDE 配置规范,JSON 格式正确。但从语法逻辑、代码质量、性能和安全等角度,我提出以下改进意见:

1. 语法与逻辑

  • triggerValue 类型不一致:
    在所有的 JSON 配置中,triggerValue 的 value 字段被定义为字符串数组(如 ["12"]),但在 triggerType 的 description 中说明 3=合成器动作,且 triggerValue 的 description 也说明了 12=取消最大化(cancel_maximize)。
    • 问题:如果底层解析器期望的是整数类型(因为 triggerType 使用的是整数 3),将数字作为字符串("12" 而非 12)可能会导致运行时类型转换错误或逻辑判断失败。
    • 建议:确认底层读取该配置的代码逻辑。如果期望整型,建议改为 "value": 12(非数组)或 "value": [12];如果底层强制要求字符串数组,则保持现状,但建议在描述中说明为何使用字符串。
  • hotkeys 与 keyEventFlags 逻辑匹配问题:
    • taskswitch-enter (Alt) 的 keyEventFlags 为 1 (press)。
    • taskswitch-next (Alt+Tab) 的 keyEventFlags 为 5 (press + repeat)。
    • 其他如 maximize (Meta+Up) 的 keyEventFlags 为 2 (release)。
    • 问题:通常“最大化”等操作在按键按下时触发,而这里配置的是 2 (release 按键抬起触发)。虽然这可能符合 Wayland/KWin 的特定合成器逻辑,但容易引起开发者的误解。
    • 建议:请确认合成器端确实是在 release 时响应这些窗口操作。如果是,建议在 JSON 的 description 中补充说明为何使用 release(例如:“为避免与按键冲突,在释放时触发”),增强代码逻辑的自解释性。

2. 代码质量

  • INI 文件单行过长:
    org.deepin.dde.shortcut.dde-app.ini 中的 SubPaths 将所有新增的路径追加到了同一行,导致该行极长(超过 500 个字符),极大地降低了可读性。
    • 建议:INI 文件格式支持换行缩进,或者如果 DDE 的解析器支持,可以拆分为多行。如果解析器严格要求单行逗号分隔,建议在代码注释中说明,或者考虑后续重构为 JSON 格式配置。
  • 国际化翻译遗漏:
    在 JSON 配置中,displayName 有 "name[zh_CN]" 字段(如“取消最大化窗口”),但在 translations/org.deepin.dde.shortcut.dde-app_zh_CN.ts 中,已经为 displayName 的英文值提供了翻译。
    • 问题:JSON 中的 name[zh_CN] 和 .ts 翻译文件的作用域可能发生重叠。如果框架优先读取 JSON 内的 name[zh_CN],那么 .ts 文件中的翻译就是冗余的;如果框架只读 .ts,那 JSON 里的 name[zh_CN] 就是死代码。
    • 建议:明确 DDE 配置框架的国际化优先级。通常建议将翻译统一收口到 .ts 文件中,JSON 中仅保留英文默认值,移除 JSON 里的 name[zh_CN],以降低维护成本。
  • 翻译文件中缺少 "Toggle FPS Display" 的翻译:
    在 org.deepin.dde.shortcut.dde-app_zh_CN.ts 中,遗漏了 Toggle FPS Display 的翻译。
    • 建议:补充该条目的中文翻译,如 <translation>切换FPS显示</translation>。

3. 代码性能

  • 文件 I/O 与解析开销:
    新增了 16 个独立的 JSON 配置文件,这意味着系统在初始化快捷键服务时,需要额外进行 16 次文件打开、读取、解析和关闭操作。
    • 建议:对于桌面环境的基础服务,启动性能至关重要。如果这些快捷键属于同一类高频加载的配置,未来可以考虑将它们合并到一个 JSON 数组或单一文件中,减少磁盘 I/O 和 JSON 解析的开销。当前架构如果是受限于 DDE 的旧有插件规范,则可暂不修改。

4. 代码安全

  • 文件权限与可见性:
    所有 JSON 配置项的 visibility 均为 "private",大部分 permissions 为空或 "readwrite"。
    • 问题:hotkeys 字段的 permissions 为 "readwrite" 且 modifiable 为 true,意味着用户可以修改快捷键。需确保快捷键的修改接口有严格的权限校验,防止恶意程序通过 D-Bus 等途径篡改系统级快捷键导致系统不可用(如将所有快捷键屏蔽)。
    • 建议:确认 DDE 配置中心在写入这些 readwrite 配置时,是否进行了合法性与冲突校验(例如防止两个动作绑定同一个快捷键)。
  • FPS 显示功能的滥用风险:
    toggle-fpsdisplay 的 modifiable 为 false,且默认绑定 Meta+F11。
    • 建议:FPS 显示通常用于调试。将其暴露为系统快捷键是合理的,但需确保该功能仅在有权限的用户下运行,且不会在投屏/共享屏幕时泄露渲染性能隐私。

总结建议修改的代码示例

1. 修复 zh_CN 翻译遗漏:

<!-- 在 org.deepin.dde.shortcut.dde-app_zh_CN.ts 中补充 -->
<message>
    <source>Toggle FPS Display</source>
    <translation>切换FPS显示</translation>
</message>

2. (可选) 优化 INI 文件可读性(如果解析器支持多行):

[Config]
SubPaths=org.deepin.dde.keybinding.shortcut.app.launcher,\
org.deepin.dde.keybinding.shortcut.app.lockscreen,\
org.deepin.dde.keybinding.shortcut.app.clipboard,\
org.deepin.dde.keybinding.shortcut.app.notificationcenter,\
org.deepin.dde.keybinding.shortcut.app.terminalquake,\
org.deepin.dde.keybinding.shortcut.app.logout,\
org.deepin.dde.keybinding.shortcut.app.maximize,\
org.deepin.dde.keybinding.shortcut.app.cancel-maximize,\
org.deepin.dde.keybinding.shortcut.app.show-desktop,\
org.deepin.dde.keybinding.shortcut.app.show-window-menu,\
org.deepin.dde.keybinding.shortcut.app.close-window,\
org.deepin.dde.keybinding.shortcut.app.toggle-multitaskview,\
org.deepin.dde.keybinding.shortcut.app.toggle-fpsdisplay,\
org.deepin.dde.keybinding.shortcut.app.prev-workspace,\
org.deepin.dde.keybinding.shortcut.app.next-workspace,\
org.deepin.dde.keybinding.shortcut.app.workspace-1,\
org.deepin.dde.keybinding.shortcut.app.workspace-2,\
org.deepin.dde.keybinding.shortcut.app.workspace-3,\
org.deepin.dde.keybinding.shortcut.app.workspace-4,\
org.deepin.dde.keybinding.shortcut.app.workspace-5,\
org.deepin.dde.keybinding.shortcut.app.workspace-6,\
org.deepin.dde.keybinding.shortcut.app.taskswitch-enter,\
org.deepin.dde.keybinding.shortcut.app.taskswitch-next,\
org.deepin.dde.keybinding.shortcut.app.taskswitch-prev,\
org.deepin.dde.keybinding.shortcut.app.taskswitch-sameapp-next,\
org.deepin.dde.keybinding.shortcut.app.taskswitch-sameapp-prev

请根据你们项目组的具体规范和底层解析逻辑,重点确认 triggerValue 数据类型和 keyEventFlags 的触发时序问题。祝开发顺利!

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, 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

@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 70222be into master Jun 3, 2026
9 of 11 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