Skip to content

fix: improve notification close button visibility logic#1525

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-FocusWithnotify
Mar 24, 2026
Merged

fix: improve notification close button visibility logic#1525
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wjyrich:fix-FocusWithnotify

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Mar 24, 2026

  1. Added focusedByNavigation property to GroupNotify, NormalNotify, and OverlapNotify components
  2. Modified close button visibility condition to only show when focused via keyboard navigation, not programmatic focus
  3. Updated NotifyView and NotifyViewDelegate to set focusedByNavigation=true when navigating between items
  4. Reset focusedByNavigation to false when item loses active focus

The issue was that close buttons were incorrectly showing when notifications received programmatic focus (e.g., during initialization or other non-navigation scenarios). This fix ensures close buttons only appear during actual keyboard navigation, improving the user experience by preventing visual clutter when not needed.

Log: Fixed notification close button visibility during keyboard navigation

Influence:

  1. Test keyboard navigation between notification items using arrow keys
  2. Verify close buttons appear only during keyboard navigation, not during initial load
  3. Test mouse hover behavior - close buttons should appear on hover
  4. Verify focus transitions between notifications work correctly
  5. Test that programmatic focus changes don't trigger close button display
  6. Check accessibility navigation with screen readers

fix: 改进通知关闭按钮可见性逻辑

  1. 在 GroupNotify、NormalNotify 和 OverlapNotify 组件中添加 focusedByNavigation 属性
  2. 修改关闭按钮可见性条件,仅在通过键盘导航获得焦点时显示,而不是程序化 焦点
  3. 更新 NotifyView 和 NotifyViewDelegate,在导航到项目时设置 focusedByNavigation=true
  4. 当项目失去活动焦点时,将 focusedByNavigation 重置为 false

问题在于当通知获得程序化焦点时(例如初始化期间或其他非导航场景),关闭按
钮会错误地显示。此修复确保关闭按钮仅在真正的键盘导航期间出现,通过在不必
要时防止视觉混乱来改善用户体验。

Log: 修复了键盘导航期间通知关闭按钮的可见性问题

Influence:

  1. 使用方向键测试通知项目之间的键盘导航
  2. 验证关闭按钮仅在键盘导航期间出现,而不是在初始加载时
  3. 测试鼠标悬停行为 - 悬停时应显示关闭按钮
  4. 验证通知之间的焦点转换正常工作
  5. 测试程序化焦点更改不会触发关闭按钮显示
  6. 检查屏幕阅读器的辅助功能导航

Summary by Sourcery

Restrict notification close button visibility to focus gained via keyboard navigation rather than any programmatic focus, improving UX consistency across notification types.

Bug Fixes:

  • Prevent notification close buttons from appearing when items receive programmatic or initial focus instead of focus from keyboard navigation.

Enhancements:

  • Track whether notification items are focused via keyboard navigation using a dedicated flag and reset it when focus is lost to control close button visibility behavior across normal, group, and overlapping notifications.

1. Added `focusedByNavigation` property to GroupNotify, NormalNotify,
and OverlapNotify components
2. Modified close button visibility condition to only show when focused
via keyboard navigation, not programmatic focus
3. Updated NotifyView and NotifyViewDelegate to set
`focusedByNavigation=true` when navigating between items
4. Reset `focusedByNavigation` to false when item loses active focus

The issue was that close buttons were incorrectly showing when
notifications received programmatic focus (e.g., during initialization
or other non-navigation scenarios). This fix ensures close buttons only
appear during actual keyboard navigation, improving the user experience
by preventing visual clutter when not needed.

Log: Fixed notification close button visibility during keyboard
navigation

Influence:
1. Test keyboard navigation between notification items using arrow keys
2. Verify close buttons appear only during keyboard navigation, not
during initial load
3. Test mouse hover behavior - close buttons should appear on hover
4. Verify focus transitions between notifications work correctly
5. Test that programmatic focus changes don't trigger close button
display
6. Check accessibility navigation with screen readers

fix: 改进通知关闭按钮可见性逻辑

1. 在 GroupNotify、NormalNotify 和 OverlapNotify 组件中添加
`focusedByNavigation` 属性
2. 修改关闭按钮可见性条件,仅在通过键盘导航获得焦点时显示,而不是程序化
焦点
3. 更新 NotifyView 和 NotifyViewDelegate,在导航到项目时设置
`focusedByNavigation=true`
4. 当项目失去活动焦点时,将 `focusedByNavigation` 重置为 false

问题在于当通知获得程序化焦点时(例如初始化期间或其他非导航场景),关闭按
钮会错误地显示。此修复确保关闭按钮仅在真正的键盘导航期间出现,通过在不必
要时防止视觉混乱来改善用户体验。

Log: 修复了键盘导航期间通知关闭按钮的可见性问题

Influence:
1. 使用方向键测试通知项目之间的键盘导航
2. 验证关闭按钮仅在键盘导航期间出现,而不是在初始加载时
3. 测试鼠标悬停行为 - 悬停时应显示关闭按钮
4. 验证通知之间的焦点转换正常工作
5. 测试程序化焦点更改不会触发关闭按钮显示
6. 检查屏幕阅读器的辅助功能导航
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts notification components so the close button only appears when a notification gains focus via explicit keyboard navigation or hover, not when focus is set programmatically, by tracking a new focusedByNavigation flag on items and managing it in NotifyView and NotifyViewDelegate.

Sequence diagram for notification focus navigation and close button visibility

sequenceDiagram
    actor User
    participant NotifyView
    participant NotifyViewDelegate
    participant NotifyItem as NormalNotify
    participant CloseButton

    User->>NotifyView: Press arrow key
    NotifyView->>NotifyViewDelegate: handleNavigation(currentIndex)
    NotifyViewDelegate->>NotifyView: view.itemAtIndex(nextIndex)
    NotifyView-->>NotifyViewDelegate: nextItem
    NotifyViewDelegate->>NotifyItem: focusedByNavigation = true
    NotifyViewDelegate->>NotifyItem: resetFocus()
    NotifyViewDelegate->>NotifyItem: forceActiveFocus()

    NotifyItem->>NotifyItem: activeFocus becomes true
    NotifyItem->>CloseButton: parentHovered = hovered OR (activeFocus AND focusedByNavigation)
    CloseButton-->>User: Close button visible

    User->>NotifyItem: Move focus away
    NotifyItem->>NotifyItem: activeFocus becomes false
    NotifyItem->>NotifyItem: focusedByNavigation = false
    NotifyItem->>CloseButton: parentHovered recomputed
    CloseButton-->>User: Close button hidden
Loading

Class diagram for updated notification components and focus handling

classDiagram
    class NotifyItem {
    }

    class NormalNotify {
      bool focusedByNavigation
      gotoNextItem()
      gotoPrevItem()
    }

    class OverlapNotify {
      bool focusedByNavigation
      var removedCallback
      notifyContent
      expand()
      gotoNextItem()
      gotoPrevItem()
    }

    class GroupNotify {
      bool focusedByNavigation
      collapse()
      gotoNextItem()
      gotoPrevItem()
    }

    class NotifyView {
      tryFocus(retries)
    }

    class NotifyViewDelegate {
      handleNext(currentIndex)
      handlePrev(currentIndex)
    }

    NotifyItem <|-- NormalNotify
    NotifyItem <|-- OverlapNotify
    NotifyItem <|-- GroupNotify

    NotifyView "1" o-- "many" NotifyItem : contains
    NotifyViewDelegate "1" o-- "1" NotifyView : controls_navigation
    NotifyViewDelegate ..> NotifyItem : sets_focusedByNavigation
    NotifyView ..> NotifyItem : sets_focusedByNavigation_and_focus
Loading

Flow diagram for close button visibility logic

flowchart TD
    A[Start] --> B{impl.hovered?}
    B -->|Yes| C[Show close button]
    B -->|No| D{root.activeFocus?}
    D -->|No| E[Hide close button]
    D -->|Yes| F{root.focusedByNavigation?}
    F -->|Yes| C[Show close button]
    F -->|No| E[Hide close button]
    C --> G[End]
    E --> G[End]
Loading

File-Level Changes

Change Details Files
Track whether notification focus came from keyboard navigation and use it to control close button visibility.
  • Add a focusedByNavigation bool property to NormalNotify, OverlapNotify, and GroupNotify items.
  • Reset focusedByNavigation to false when an item loses active focus via onActiveFocusChanged handlers.
  • Update parentHovered condition on notification content so the close button shows only on mouse hover or when the item has active focus and focusedByNavigation is true.
panels/notification/center/NormalNotify.qml
panels/notification/center/OverlapNotify.qml
panels/notification/center/GroupNotify.qml
Ensure navigation between notification items marks focus as navigation-driven.
  • In NotifyViewDelegate, when moving to the next or previous item, set focusedByNavigation=true on the target item before resetting or forcing focus.
  • In NotifyView, when trying to focus an item by index (keyboard-driven selection), set focusedByNavigation=true before calling resetFocus/focus methods.
panels/notification/center/NotifyViewDelegate.qml
panels/notification/center/NotifyView.qml

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

@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 found 2 issues, and left some high level feedback:

  • The focusedByNavigation property and onActiveFocusChanged handler are duplicated across NormalNotify, OverlapNotify, and GroupNotify; consider moving this state and reset logic into NotifyItem (or a shared base) to avoid repetition and keep behavior consistent across all notify types.
  • Now that close-button visibility depends on focusedByNavigation, make sure all keyboard navigation paths (not just next/prev and tryFocus, e.g. page up/down, home/end, list refocus, etc.) set this flag appropriately so the close button behavior remains consistent for all navigation affordances.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `focusedByNavigation` property and `onActiveFocusChanged` handler are duplicated across `NormalNotify`, `OverlapNotify`, and `GroupNotify`; consider moving this state and reset logic into `NotifyItem` (or a shared base) to avoid repetition and keep behavior consistent across all notify types.
- Now that close-button visibility depends on `focusedByNavigation`, make sure all keyboard navigation paths (not just next/prev and `tryFocus`, e.g. page up/down, home/end, list refocus, etc.) set this flag appropriately so the close button behavior remains consistent for all navigation affordances.

## Individual Comments

### Comment 1
<location path="panels/notification/center/NormalNotify.qml" line_range="17-18" />
<code_context>
     id: root
     implicitWidth: impl.implicitWidth
     implicitHeight: impl.implicitHeight
+    property bool focusedByNavigation: false
+    onActiveFocusChanged: if (!activeFocus) focusedByNavigation = false

     signal collapse()
</code_context>
<issue_to_address>
**suggestion:** Consider centralizing the focusedByNavigation behavior to avoid repetition across notify item types.

`focusedByNavigation` and the `onActiveFocusChanged` handler are now repeated in `NormalNotify`, `OverlapNotify`, and `GroupNotify`. Centralizing this (e.g., in `NotifyItem` or a shared mixin) would keep the behavior defined in one place and avoid future inconsistencies, especially when adding new delegate types.
</issue_to_address>

### Comment 2
<location path="panels/notification/center/NotifyViewDelegate.qml" line_range="27-31" />
<code_context>
             Qt.callLater(function() {
                 let nextItem = view.itemAtIndex(currentIndex + 1)
                 if (nextItem && nextItem.enabled) {
+                    nextItem.focusedByNavigation = true
                     nextItem.resetFocus()
                     nextItem.forceActiveFocus()
                 }
</code_context>
<issue_to_address>
**suggestion:** Navigation to next and previous items handle focus slightly differently; consider aligning the behavior.

For next items you call `resetFocus()` before `forceActiveFocus()`, but for previous items you only call `forceActiveFocus()`. If delegates manage internal focus targets, this asymmetry can cause different focus behavior when moving up vs down. Please either apply the same sequence in both directions or document why they must differ.
</issue_to_address>

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-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, wjyrich

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

@wjyrich
Copy link
Contributor Author

wjyrich commented Mar 24, 2026

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 24, 2026

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit ad86104 into linuxdeepin:master Mar 24, 2026
11 of 12 checks passed
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.

3 participants