fix: monitor X11 lock state changes through XKB - #128
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
Reviewer's GuideThis PR wires XKB-based monitoring of X11 modifier lock state (Caps/Num Lock) into the existing shortcut backend, propagates lock changes through the key handler and keybinding manager, and centralizes/filters emission of the exported D-Bus state-change signals to avoid duplicates. Sequence diagram for XKB lock state propagationsequenceDiagram
participant XServer
participant X11KeyHandler
participant KeybindingManager
participant DbusClients
XServer->>X11KeyHandler: XkbStateNotify
X11KeyHandler->>X11KeyHandler: notifyLockStateChange(event)
alt [Num Lock changed]
X11KeyHandler-->>KeybindingManager: numLockStateChanged(on)
KeybindingManager->>KeybindingManager: updateNumLockState(on)
KeybindingManager-->>DbusClients: NumLockStateChanged(state)
end
alt [Caps Lock changed]
X11KeyHandler-->>KeybindingManager: capsLockStateChanged(on)
KeybindingManager->>KeybindingManager: updateCapsLockState(on)
KeybindingManager-->>DbusClients: CapsLockStateChanged(state)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
cc94572 to
0639b49
Compare
Subscribe to XKB modifier lock state notifications independently of passive shortcut grabs. Propagate Caps Lock and Num Lock changes through the key handler and deduplicate the exported D-Bus signals. This also observes lock state changes made through XKB APIs without physical key press events. 独立于被动快捷键抓取订阅 XKB 修饰键锁定状态通知。 通过按键处理后端传递大小写锁定和数字锁定状态变化,并对导出的 D-Bus 信号去重。 同时支持检测通过 XKB API 直接修改且没有物理按键事件的锁定状态变化。 Log: monitor X11 lock state changes through XKB Pms: BUG-372751 Change-Id: I923a352f91a63218d287bb013464538a65b27c56
0639b49 to
67fde5a
Compare
|
[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) |
deepin pr auto review★ 总体评分:60分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 diff --git a/src/plugin-qt/shortcut/src/backend/x11/x11keyhandler.cpp b/src/plugin-qt/shortcut/src/backend/x11/x11keyhandler.cpp
index ee0cae8..safe_version 100644
--- a/src/plugin-qt/shortcut/src/backend/x11/x11keyhandler.cpp
+++ b/src/plugin-qt/shortcut/src/backend/x11/x11keyhandler.cpp
@@ -968,17 +968,16 @@ void X11KeyHandler::handleKeyPress(const xcb_key_press_event_t *event)
+// 解析 XKB StateNotify 事件,提取并发射锁键状态变更信号
void X11KeyHandler::notifyLockStateChange(const xcb_generic_event_t *event)
{
if (!event)
return;
- static_assert(sizeof(xkbStateNotify) == sz_xkbStateNotify);
- xkbStateNotify stateEvent{};
- std::memcpy(&stateEvent, event, sizeof(stateEvent));
- if (stateEvent.xkbType != XkbStateNotify
- || !(stateEvent.changed & XkbModifierLockMask)) {
+ // 使用 reinterpret_cast 替代 memcpy,避免越界读取风险,符合 XCB 事件处理规范
+ const auto *stateEvent = reinterpret_cast<const xkbStateNotify *>(event);
+ if (stateEvent->xkbType != XkbStateNotify
+ || !(stateEvent->changed & XkbModifierLockMask)) {
return;
}
- emit numLockStateChanged(stateEvent.lockedMods & m_numLockMask);
- emit capsLockStateChanged(stateEvent.lockedMods & m_capsLockMask);
+ emit numLockStateChanged(stateEvent->lockedMods & m_numLockMask);
+ emit capsLockStateChanged(stateEvent->lockedMods & m_capsLockMask);
}
diff --git a/src/plugin-qt/shortcut/src/core/keybindingmanager.cpp b/src/plugin-qt/shortcut/src/core/keybindingmanager.cpp
index 050907b..deduplicate_version 100644
--- a/src/plugin-qt/shortcut/src/core/keybindingmanager.cpp
+++ b/src/plugin-qt/shortcut/src/core/keybindingmanager.cpp
@@ -1285,24 +1285,17 @@ void KeybindingManager::onCaptureKeyEvent(bool pressed, const QString &keystroke
emit KeyEvent(pressed, keystroke);
}
-void KeybindingManager::updateNumLockState(bool on)
+// 统一的锁键状态更新逻辑,包含去重判断与信号发射
+void KeybindingManager::updateLockState(uint &lastState, bool on, void (KeybindingManager::*signalPtr)(uint))
{
- const uint state = on ? 1U : 0U;
- if (m_lastNumLockState == state)
+ const uint state = on ? 1U : 0U;
+ if (lastState == state)
return;
- m_lastNumLockState = state;
- emit NumLockStateChanged(state);
-}
+ lastState = state;
+ emit (this->*signalPtr)(state);
+}
-void KeybindingManager::updateCapsLockState(bool on)
+void KeybindingManager::updateNumLockState(bool on)
{
- const uint state = on ? 1U : 0U;
- if (m_lastCapsLockState == state)
- return;
-
- m_lastCapsLockState = state;
- emit CapsLockStateChanged(state);
+ updateLockState(m_lastNumLockState, on, &KeybindingManager::NumLockStateChanged);
}
+
+void KeybindingManager::updateCapsLockState(bool on)
+{
+ updateLockState(m_lastCapsLockState, on, &KeybindingManager::CapsLockStateChanged);
+} |
Summary
Tests
cmake --build build --target plugin-dde-shortcut -j2git diff --checkPms: BUG-372751
Summary by Sourcery
Handle X11 keyboard lock state changes via XKB and ensure consistent, deduplicated propagation of Caps Lock and Num Lock state updates through the shortcut subsystem.
Bug Fixes:
Enhancements: