feat(shortcut): support unassigned hotkeys#91
Conversation
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
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Allow a shortcut to be left without any hotkey: it stays visible in the list (shown as "None") without being registered with the compositor, so ReplaceHotkey can intentionally unassign a binding and Reset can restore the default later. - Keep empty-hotkey configs valid and visible without registration - Reset: collect resettable ids, unregister them up front and only mutate local state after the compositor confirms the commit; on commit failure leave the map and dconfig untouched so state stays consistent - Reset: drop reset targets from the map so the async valueChanged restore takes the new-entry path and always emits ShortcutChanged, even when the restored default is unassigned - Add KeyConfig operator==/!= and skip onKeyConfigChanged work (and the spurious ShortcutChanged) when the incoming config is unchanged 支持快捷键不分配任何热键:该项仍显示在列表中(显示为 "None"), 但不向合成器注册,从而 ReplaceHotkey 可以主动取消绑定,Reset 之后 可恢复默认值。 - 空热键配置保持有效并可见,但不注册 - Reset:先收集可重置项并提前注销,仅在合成器确认提交后才修改本地 状态;提交失败时不动 map 与 dconfig,保持状态一致 - Reset:从 map 中移除重置目标,使异步 valueChanged 恢复走新增分支, 即使恢复后的默认值为未分配也能正确发出 ShortcutChanged - 新增 KeyConfig operator==/!=,当传入配置无变化时跳过 onKeyConfigChanged 处理并避免冗余的 ShortcutChanged 信号 Log: support unassigned hotkeys Pms: BUG-365989 Change-Id: I655ae653366dfd6b554002c55e2444a3ee731fa3
a814bce to
6ed6f9d
Compare
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 当前代码已非常完善,无需强制修改。以下仅展示一种可选的微优化:
// 在 Reset() 中合并遍历逻辑(仅为演示风格,当前分离逻辑因 commitSync 阻塞更清晰)
void KeybindingManager::Reset()
{
const QStringList resetIds = m_loader->resettableHotkeyIds();
if (resetIds.isEmpty()) {
return;
}
QStringList toRestore;
for (const QString &id : resetIds) {
if (!m_keyConfigsMap.contains(id)) {
continue;
}
m_keyHandler->unregisterKey(id);
m_specialKeyHandler->unregisterKey(id);
toRestore.append(id);
}
if (!m_keyHandler->commitSync()) {
qWarning() << "Reset: failed to commit unregistering existing hotkeys";
return;
}
for (const QString &id : toRestore) {
m_keyConfigsMap.remove(id);
}
m_loader->resetHotkeys(resetIds);
} |
Summary
ReplaceHotkeycan intentionally unassign a binding andResetcan restore the default later.Reset: unregister reset targets up front and only mutate local state after the compositor confirms the commit; on commit failure leave the map and dconfig untouched so state stays consistent (matching the rollback contract ofModifyHotkeys/Disable).Reset: drop reset targets from the map so the asyncvalueChangedrestore takes the new-entry path and always emitsShortcutChanged, even when the restored default is unassigned.KeyConfigoperator==/!=and skiponKeyConfigChangedwork (and the spuriousShortcutChanged) when the incoming config is unchanged.Test plan
Reset: the shortcut returns to its default (or to unassigned when the default is empty) and the control center reflects the change.ShortcutChanged.Pms: BUG-365989