From e85edce8fff4c40c95e1bff92c07bbe356bcc7e4 Mon Sep 17 00:00:00 2001 From: wjyrich Date: Mon, 23 Mar 2026 14:16:46 +0800 Subject: [PATCH] fix: improve notification center keyboard navigation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added resetFocus() function to all notification item types (GroupNotify, NormalNotify, OverlapNotify) to ensure consistent focus management. Modified focus navigation logic in NotifyView and NotifyViewDelegate to call resetFocus() before attempting to focus items. Enhanced keyboard navigation from action buttons to previous items by prioritizing close button focus when available. The changes ensure that when navigating between notification items using keyboard shortcuts, focus is properly reset to the item's main implementation before attempting to focus specific buttons. This prevents focus issues where keyboard navigation could get stuck or behave inconsistently. The onGotoPrevItem handler now checks for an enabled close button before navigating to the previous notification item, improving the user experience when navigating backward through notifications. Log: Improved keyboard navigation in notification center for better accessibility Influence: 1. Test Tab/Shift+Tab navigation between notification items 2. Verify arrow key navigation between notifications works correctly 3. Test focus behavior when moving from action buttons to previous items 4. Verify close button receives focus when navigating backward from action buttons 5. Test navigation with different notification types (group, normal, overlap) 6. Verify focus is properly reset when switching between notifications fix: 改进通知中心键盘导航 为所有通知项类型(GroupNotify、NormalNotify、OverlapNotify)添 加了resetFocus()函数,以确保一致性的焦点管理。修改了NotifyView和 NotifyViewDelegate中的焦点导航逻辑,在尝试聚焦项之前调用resetFocus()。增 强了从操作按钮到前一项的键盘导航,优先考虑关闭按钮焦点(如果可用)。 这些更改确保在使用键盘快捷键在通知项之间导航时,在尝试聚焦特定按钮之前, 焦点被正确重置到项的主实现。这防止了键盘导航可能卡住或行为不一致的焦点 问题。onGotoPrevItem处理程序现在在导航到前一个通知项之前检查启用的关闭按 钮,改善了向后浏览通知时的用户体验。 Log: 改进了通知中心的键盘导航,提升可访问性 Influence: 1. 测试Tab/Shift+Tab在通知项之间的导航 2. 验证箭头键在通知之间的导航工作正常 3. 测试从操作按钮移动到前一项时的焦点行为 4. 验证从操作按钮向后导航时关闭按钮获得焦点 5. 测试不同类型通知(群组、普通、重叠)的导航 6. 验证在通知之间切换时焦点被正确重置 --- panels/notification/center/GroupNotify.qml | 4 ++++ panels/notification/center/NormalNotify.qml | 4 ++++ panels/notification/center/NotifyView.qml | 1 + panels/notification/center/NotifyViewDelegate.qml | 1 + panels/notification/center/OverlapNotify.qml | 4 ++++ panels/notification/plugin/NotifyItemContent.qml | 9 ++++++++- 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/panels/notification/center/GroupNotify.qml b/panels/notification/center/GroupNotify.qml index 6e6187024..29c607a54 100644 --- a/panels/notification/center/GroupNotify.qml +++ b/panels/notification/center/GroupNotify.qml @@ -18,6 +18,10 @@ NotifyItem { signal gotoNextItem() // Signal to navigate to next notify item signal gotoPrevItem() // Signal to navigate to previous notify item + function resetFocus() { + impl.forceActiveFocus() + } + // Focus the first button for Tab navigation into group function focusFirstButton() { foldBtn.forceActiveFocus() diff --git a/panels/notification/center/NormalNotify.qml b/panels/notification/center/NormalNotify.qml index 77324eef8..593443381 100644 --- a/panels/notification/center/NormalNotify.qml +++ b/panels/notification/center/NormalNotify.qml @@ -17,6 +17,10 @@ NotifyItem { signal gotoNextItem() signal gotoPrevItem() + function resetFocus() { + impl.forceActiveFocus() + } + function focusFirstButton() { return notifyContent.focusFirstButton() } diff --git a/panels/notification/center/NotifyView.qml b/panels/notification/center/NotifyView.qml index cf041c06e..d58fa671a 100644 --- a/panels/notification/center/NotifyView.qml +++ b/panels/notification/center/NotifyView.qml @@ -38,6 +38,7 @@ Control { function tryFocus(retries) { let item = view.itemAtIndex(idx) if (item && item.enabled) { + item.resetFocus() if (!item.focusFirstButton()) { item.forceActiveFocus() } diff --git a/panels/notification/center/NotifyViewDelegate.qml b/panels/notification/center/NotifyViewDelegate.qml index a03bff0d8..bbec8e4b9 100644 --- a/panels/notification/center/NotifyViewDelegate.qml +++ b/panels/notification/center/NotifyViewDelegate.qml @@ -26,6 +26,7 @@ DelegateChooser { Qt.callLater(function() { let nextItem = view.itemAtIndex(currentIndex + 1) if (nextItem && nextItem.enabled) { + nextItem.resetFocus() nextItem.forceActiveFocus() } }) diff --git a/panels/notification/center/OverlapNotify.qml b/panels/notification/center/OverlapNotify.qml index 817297340..818e7ad6e 100644 --- a/panels/notification/center/OverlapNotify.qml +++ b/panels/notification/center/OverlapNotify.qml @@ -26,6 +26,10 @@ NotifyItem { property var clearButton: notifyContent.clearButtonItem + function resetFocus() { + impl.forceActiveFocus() + } + function focusFirstButton() { // Focus clear button first, then action buttons if (clearButton && clearButton.enabled && clearButton.visible) { diff --git a/panels/notification/plugin/NotifyItemContent.qml b/panels/notification/plugin/NotifyItemContent.qml index b0fb50e4f..740f0da65 100644 --- a/panels/notification/plugin/NotifyItemContent.qml +++ b/panels/notification/plugin/NotifyItemContent.qml @@ -340,7 +340,14 @@ NotifyItem { // From action buttons, go directly to next notification item root.gotoNextItem() } - onGotoPrevItem: root.gotoPrevItem() + onGotoPrevItem: { + // Try to focus close button first, if not available go to prev item + if (clearLoader.item && clearLoader.item.enabled) { + clearLoader.item.forceActiveFocus() + } else { + root.gotoPrevItem() + } + } } } }