fix: persist NumLock state on X11 - #137
Conversation
Restore and save NumLock state through a shortcut-owned DConfig on X11 while leaving Treeland state management to the compositor. - Migrate the legacy NumLock state and save preference only while the new state is unknown. - Use XKB modifier locking to avoid synthetic startup shortcut events, and explicitly show the OSD for user-initiated state changes. - Keep helper-side compatibility persistence for mixed-version live upgrades and move lock-key settings to the new schema. 在 X11 下通过快捷键服务自有的 DConfig 恢复并保存 NumLock 状态,Treeland 状态仍由合成器管理。 - 仅在新状态为未知值时迁移旧的 NumLock 状态和保存开关。 - 使用 XKB 锁定修饰键,避免启动恢复产生模拟快捷键事件,并在用户主动修改状态时显式显示 OSD。 - 为在线混合版本升级保留工具侧兼容保存,并将锁定键配置迁移到新配置中。 Log: persist NumLock state on X11 Change-Id: I150de2b004527b841395deeddf9c707a160a3f50
There was a problem hiding this comment.
Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Reviewer's GuideIntroduces an X11-specific NumLock state controller and moves NumLock persistence into a shortcut-owned DConfig, replacing synthetic key events with XKB modifier locking and adding migration/compatibility paths for legacy daemon configs and live upgrades. Sequence diagram for X11 NumLock state setting and OSD behaviorsequenceDiagram
participant KeybindingManager
participant X11NumLockStateController
participant AbstractKeyHandler
participant DConfig
participant ActionExecutor
KeybindingManager->>X11NumLockStateController: setState(state)
X11NumLockStateController->>AbstractKeyHandler: setNumLockState(state == 1)
AbstractKeyHandler-->>X11NumLockStateController: numLockStateChanged(on)
X11NumLockStateController->>X11NumLockStateController: updateState(on)
X11NumLockStateController->>DConfig: persistState(state)
X11NumLockStateController-->>KeybindingManager: state()
KeybindingManager->>ActionExecutor: executeCommand(["/usr/bin/dde-shortcut-tool","lockkey","numlock"])
alt executeCommand fails
ActionExecutor-->>KeybindingManager: false
KeybindingManager->>KeybindingManager: qCWarning("failed to launch NumLock OSD tool")
else executeCommand succeeds
ActionExecutor-->>KeybindingManager: true
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/src/plugin-qt/shortcut/tools/dde-shortcut-tool/lockkeycontroller.cpp b/src/plugin-qt/shortcut/tools/dde-shortcut-tool/lockkeycontroller.cpp
index e2bd7fed..12345678 100644
--- a/src/plugin-qt/shortcut/tools/dde-shortcut-tool/lockkeycontroller.cpp
+++ b/src/plugin-qt/shortcut/tools/dde-shortcut-tool/lockkeycontroller.cpp
@@ -176,6 +176,11 @@ void LockKeyController::saveNumLockStateForUpgradeCompatibility(int state)
{
if (m_isWayland || !m_keyboardConfig || !m_keyboardConfig->isValid())
return;
+
+ // 防御性校验:确保写入配置的 state 严格限制在合法枚举范围内,防止上游传入异常值
+ if (state < 0 || state > static_cast<int>(kNumLockUnknown))
+ return;
+
bool ok = false;
const uint configuredState = m_keyboardConfig->value(kNumLockStateKey).toUInt(&ok);
if (ok && configuredState == kNumLockUnknown) { |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: robertkill, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Summary
Test plan
cmake --build build --target plugin-dde-shortcut dde-shortcut-tool dde-shortcut-debug -j2ctest --test-dir build --output-on-failure -E shortcut-x11\\(recordmonitor\\|grabresilientshortcuts\\)python3 -m json.toolSummary by Sourcery
Persist NumLock state on X11 at the shortcut service level, with migration from legacy settings and improved, non-synthetic modifier handling.
New Features:
Bug Fixes:
Enhancements:
Build: