Skip to content

fix(keybinding): resolve shortcut conflicts and improve Wayland support#1088

Open
robertkill wants to merge 1 commit intolinuxdeepin:masterfrom
robertkill:master
Open

fix(keybinding): resolve shortcut conflicts and improve Wayland support#1088
robertkill wants to merge 1 commit intolinuxdeepin:masterfrom
robertkill:master

Conversation

@robertkill
Copy link
Copy Markdown
Contributor

@robertkill robertkill commented Apr 15, 2026

Problem:

  1. Shortcut modification via control-center conflicts with dconfig listener
  2. System shortcuts not properly synchronized to KWin on Wayland
  3. Special shortcuts (screenshotWindow, launcher, systemMonitor) need specific KWin formats

Solution:

  1. Add modifyingShortcuts set to track API modifications, skip dconfig callback during modification
  2. Sync system shortcut changes to KWin immediately when dconfig changes
  3. Restore hardcoded accelJson for special shortcuts with KWin-compatible formats
  4. Fix single keystroke replacement logic (clear existing except Delete shortcuts)
  5. Add enhanced logging for debugging

Influence:

  1. Test shortcut modification via control-center on Wayland
  2. Test system shortcuts (screenshot, launcher, system monitor) on Wayland
  3. Test custom shortcut add/delete/clear operations
  4. Verify no duplicate shortcut registrations after modification
  5. Verify dconfig and KWin stay in sync

fix: 修复快捷键冲突和 Wayland 支持问题

问题:

  1. 控制中心修改快捷键与 dconfig 监听回调产生竞争冲突
  2. Wayland 下系统快捷键未正确同步到 KWin
  3. 特殊快捷键(截图窗口、启动器、系统监视器)需要特定 KWin 格式

解决方案:

  1. 添加 modifyingShortcuts 集合跟踪 API 修改,修改期间跳过 dconfig 回调
  2. dconfig 变更时立即同步系统快捷键到 KWin
  3. 恢复特殊快捷键的硬编码 accelJson,使用 KWin 兼容格式
  4. 修复单键替换逻辑(清空已有快捷键,Delete 类保留双绑)
  5. 添加详细日志便于调试

影响范围:

  1. 测试 Wayland 下控制中心修改快捷键
  2. 测试 Wayland 下系统快捷键(截图、启动器、系统监视器)
  3. 测试自定义快捷键的增删清操作
  4. 验证修改后无重复快捷键注册
  5. 验证 dconfig 和 KWin 保持同步

PMS: BUG-355747

Summary by Sourcery

Resolve shortcut modification conflicts and improve Wayland shortcut synchronization with KWin, including special-case handling for system shortcuts.

Bug Fixes:

  • Prevent dconfig change callbacks from racing with API-driven shortcut modifications by tracking in-progress shortcut updates.
  • Ensure system shortcut changes are immediately propagated to KWin on Wayland when dconfig values change.
  • Fix system shortcut keystroke replacement so existing bindings are cleared for single-key updates while preserving required dual Delete bindings.

Enhancements:

  • Normalize system shortcut keystrokes into KWin-compatible formats, including dedicated handling for screenshot, launcher, and system monitor actions on Wayland.
  • Improve logging around Wayland global accelerators, shortcut grabs, and keystroke deletion to aid debugging.

Problem:
1. Shortcut modification via control-center conflicts with dconfig listener
2. System shortcuts not properly synchronized to KWin on Wayland
3. Special shortcuts (screenshotWindow, launcher, systemMonitor) need specific KWin formats

Solution:
1. Add modifyingShortcuts set to track API modifications, skip dconfig callback during modification
2. Sync system shortcut changes to KWin immediately when dconfig changes
3. Restore hardcoded accelJson for special shortcuts with KWin-compatible formats
4. Fix single keystroke replacement logic (clear existing except Delete shortcuts)
5. Add enhanced logging for debugging

Influence:
1. Test shortcut modification via control-center on Wayland
2. Test system shortcuts (screenshot, launcher, system monitor) on Wayland
3. Test custom shortcut add/delete/clear operations
4. Verify no duplicate shortcut registrations after modification
5. Verify dconfig and KWin stay in sync

fix: 修复快捷键冲突和 Wayland 支持问题

问题:
1. 控制中心修改快捷键与 dconfig 监听回调产生竞争冲突
2. Wayland 下系统快捷键未正确同步到 KWin
3. 特殊快捷键(截图窗口、启动器、系统监视器)需要特定 KWin 格式

解决方案:
1. 添加 modifyingShortcuts 集合跟踪 API 修改,修改期间跳过 dconfig 回调
2. dconfig 变更时立即同步系统快捷键到 KWin
3. 恢复特殊快捷键的硬编码 accelJson,使用 KWin 兼容格式
4. 修复单键替换逻辑(清空已有快捷键,Delete 类保留双绑)
5. 添加详细日志便于调试

影响范围:
1. 测试 Wayland 下控制中心修改快捷键
2. 测试 Wayland 下系统快捷键(截图、启动器、系统监视器)
3. 测试自定义快捷键的增删清操作
4. 验证修改后无重复快捷键注册
5. 验证 dconfig 和 KWin 保持同步

PMS: BUG-355747
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: robertkill

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
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 15, 2026

Reviewer's Guide

This PR fixes shortcut conflicts and improves Wayland/KWin integration by adding an API-modification guard, normalizing/special-casing system accelerators for KWin, synchronizing dconfig updates to KWin, tightening single-keystroke replacement behavior, and enhancing logging and diagnostics around keybinding operations.

Sequence diagram for API shortcut modification with dconfig guard

sequenceDiagram
    actor ControlCenter
    participant Manager
    participant StringSet
    participant ShortcutManager
    participant DConfig

    ControlCenter->>Manager: AddShortcutKeystroke(id, type0, keystroke)
    Manager->>StringSet: Add(id)
    activate StringSet
    StringSet-->>Manager: (ok)
    deactivate StringSet

    Manager->>ShortcutManager: GetByIdType(id, type0)
    ShortcutManager-->>Manager: shortcut

    Manager->>ShortcutManager: ModifyShortcutKeystrokes(shortcut, maybeNil)
    Manager->>ShortcutManager: AddShortcutKeystroke(shortcut, ksToAdd...)
    Manager->>ShortcutManager: SaveKeystrokes via shortcut

    Note over DConfig,Manager: DConfig emits change signal after SaveKeystrokes

    DConfig-->>Manager: listenDConfigChanged(key=id, type0)
    Manager->>StringSet: Has(id)
    activate StringSet
    StringSet-->>Manager: true
    deactivate StringSet
    Manager-->>DConfig: skip handling (return)

    Manager->>StringSet: Remove(id)
    activate StringSet
    StringSet-->>Manager: (ok)
    deactivate StringSet

    ControlCenter-->>Manager: AddShortcutKeystroke returns
Loading

Sequence diagram for dconfig-driven system shortcut sync to KWin on Wayland

sequenceDiagram
    participant DConfig
    participant Manager
    participant ShortcutManager
    participant NormalizeFn
    participant KWinWm

    DConfig-->>Manager: listenDConfigChanged(key, type0=ShortcutTypeSystem)
    Manager->>Manager: check enableListenDConfig
    Manager->>Manager: check modifyingShortcuts.Has(key)
    alt notBeingModified
        Manager->>ShortcutManager: GetByIdType(key, type0)
        ShortcutManager-->>Manager: shortcut
        Manager->>DConfig: Value(0, key)
        DConfig-->>Manager: keystrokesRaw
        Manager->>ShortcutManager: ModifyShortcutKeystrokes(shortcut, ParseKeystrokes(keystrokesRaw))

        opt Wayland
            Manager->>NormalizeFn: NormalizeSystemKeystrokesForKWin(key, keystrokesRaw)
            NormalizeFn-->>Manager: normalizedKeystrokes
            Manager->>Manager: marshal KWinAccel(Id, normalizedKeystrokes) to accelJson
            Manager->>KWinWm: SetAccel(0, accelJson)
            KWinWm-->>Manager: ok, err
        end

        Manager->>Manager: emitShortcutSignal(shortcutSignalChanged, shortcut)
    else beingModifiedViaAPI
        Manager-->>DConfig: skip (return)
    end
Loading

File-Level Changes

Change Details Files
Guard dconfig listener against concurrent API-based shortcut modifications using a concurrent-safe string set.
  • Introduce Manager.modifyingShortcuts as a concurrent-safe StringSet and initialize it in newManager
  • Skip listenDConfigChanged handling for shortcuts currently being modified via the public API
  • Wrap ClearShortcutKeystrokes and AddShortcutKeystroke with add/remove of the corresponding id in modifyingShortcuts to avoid feedback loops
keybinding1/manager.go
keybinding1/manager_ifc.go
Improve Wayland/KWin synchronization for system shortcuts, including normalization and special formats.
  • On dconfig changes for system shortcuts under Wayland, immediately update KWin with normalized keystrokes and accel JSON via wm.SetAccel
  • Add NormalizeSystemKeystrokesForKWin to adjust key names (Del/Delete, Esc/Escape) and enforce special forms for screenshotWindow, launcher, and systemMonitor
  • Refactor AddSystemToKwin and setAccelForWayland to reuse NormalizeSystemKeystrokesForKWin and consistently handle the three special shortcuts with hardcoded KWin-compatible accelJson payloads
  • Add ConvertToStringSliceForWayland helper to wrap keystroke conversion for Wayland-specific code paths
keybinding1/manager.go
keybinding1/shortcuts/shortcut_manager.go
keybinding1/manager_ifc.go
Adjust single-keystroke replacement semantics for system shortcuts, preserving Delete dual bindings.
  • In AddShortcutKeystroke, when updating a system shortcut that already has keystrokes, clear existing bindings before adding new ones unless any existing binding includes Delete
  • Keep Delete-related system shortcuts as dual bindings (Delete + KP_Delete) by skipping the clear step when Delete is present
keybinding1/manager_ifc.go
Enhance logging and diagnostics around key capture and modification, especially on Wayland.
  • Add detailed info logs for Wayland global shortcut presses and resolved actions/commands in listenGlobalAccel
  • Log id, keystrokes, and custom-flag when setting Wayland shortcuts in setShortForWayland
  • Upgrade grabKeystroke failure logs from debug to warning and log successful grabs at debug level
  • Add structured info logs for setAccelForWayland and for DeleteShortcutKeystroke before/after delete and after saving keystrokes
keybinding1/manager.go
keybinding1/shortcuts/shortcut_manager.go
keybinding1/manager_ifc.go
Introduce a small concurrent-safe StringSet utility for tracking active shortcut modifications.
  • Add StringSet type with RWMutex, backing map, and Add/Remove/Has operations
  • Use StringSet to coordinate between API handlers and the dconfig listener
keybinding1/manager.go

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The hardcoded KWin accelerators for screenshotWindow, launcher, and systemMonitor are now duplicated across NormalizeSystemKeystrokesForKWin, AddSystemToKwin, and setAccelForWayland; consider centralizing these special cases in a single helper to avoid divergence or future inconsistencies.
  • The literal "<Crtl><Alt>Escape" for the system monitor accelerator appears to contain a typo (Crtl vs Ctrl); please double-check this against the actual KWin format to ensure the shortcut is recognized correctly.
  • Several new Infof logs (e.g. in listenGlobalAccel, setShortForWayland, setAccelForWayland, and DeleteShortcutKeystroke) may be quite verbose in normal operation; consider downgrading high-frequency paths to Debugf or guarding them to avoid noisy logs in production.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The hardcoded KWin accelerators for `screenshotWindow`, `launcher`, and `systemMonitor` are now duplicated across `NormalizeSystemKeystrokesForKWin`, `AddSystemToKwin`, and `setAccelForWayland`; consider centralizing these special cases in a single helper to avoid divergence or future inconsistencies.
- The literal `"<Crtl><Alt>Escape"` for the system monitor accelerator appears to contain a typo (`Crtl` vs `Ctrl`); please double-check this against the actual KWin format to ensure the shortcut is recognized correctly.
- Several new `Infof` logs (e.g. in `listenGlobalAccel`, `setShortForWayland`, `setAccelForWayland`, and `DeleteShortcutKeystroke`) may be quite verbose in normal operation; consider downgrading high-frequency paths to `Debugf` or guarding them to avoid noisy logs in production.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Apr 23, 2026

TAG Bot

New tag: 6.1.86
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1094

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Apr 24, 2026

TAG Bot

New tag: 6.1.87
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1095

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