Skip to content

fix: remove redundant focus property in notification center#1250

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
Sep 18, 2025
Merged

fix: remove redundant focus property in notification center#1250
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

@18202781743 18202781743 commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

Removed explicit focus: true from OverlapNotify component as it was
causing focus issues when multiple notifications are present. Added
focus management to the main view container to clear focus when
NotificationCenter is closed. Replaced Control with FocusScope in
NotifyItemContent to better handle focus behavior and simplified the
close button visibility logic.

Log: Fixed focus issues in notification center

Influence:

  1. Test notification center opening and closing behavior
  2. Verify focus transitions between notifications
  3. Check close button visibility and functionality
  4. Test keyboard navigation through notifications
  5. Verify focus is properly cleared when center is closed

fix: 修复通知中心的焦点问题

移除了OverlapNotify组件中显式的focus: true属性,该属性在多个通知同时存在
时会导致焦点问题。为主视图容器添加了焦点管理,在通知中心关闭时清除焦点。
将NotifyItemContent中的Control替换为FocusScope以更好地处理焦点行为,并简
化了关闭按钮的可见性逻辑。

Log: 修复通知中心的焦点问题

Influence:

  1. 测试通知中心打开和关闭行为
  2. 验证通知之间的焦点转换
  3. 检查关闭按钮的可见性和功能
  4. 测试通过键盘在通知间的导航
  5. 验证通知中心关闭时焦点是否正确清除

PMS: BUG-284139

Summary by Sourcery

Streamline focus management in the notification center by removing redundant focus properties, centralizing focus control, and simplifying close button logic

Bug Fixes:

  • Fix focus issues when multiple notifications are present and ensure focus is cleared when the notification center closes

Enhancements:

  • Remove redundant focus property from OverlapNotify delegate
  • Add focus binding to the main view container to clear focus on close
  • Replace Control with FocusScope in NotifyItemContent for improved focus handling
  • Simplify close button visibility and focus border logic

@sourcery-ai

sourcery-ai Bot commented Sep 18, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors focus management in the notification center by removing redundant focus flags, introducing a FocusScope for item-level focus handling, clearing focus when the center closes, and simplifying close-button focus logic.

File-Level Changes

Change Details Files
Streamline focus handling in NotifyItemContent
  • Replace Control placeholder with FocusScope
  • Remove explicit focus:true attribute from placeholder
  • Update Loader’s active condition to drop hover/activeFocus checks
  • Simplify forcusBorderVisible logic to rely solely on visualFocus
panels/notification/plugin/NotifyItemContent.qml
Manage focus on main view container when center closes
  • Bind view’s focus property to NotificationCenter visibility to clear focus on close
panels/notification/center/package/main.qml
Remove redundant focus flag in OverlapNotify delegate
  • Remove explicit focus:true from OverlapNotify to prevent unwanted focus capture
panels/notification/center/NotifyViewDelegate.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Ensure the loader activation logic still covers hover scenarios if that behavior is desired, or explicitly update it to remove hover-based close button reveal.
  • Fix the typo 'forcusBorderVisible' so it matches the correct 'focusBorderVisible' property name.
  • Consider using an explicit focus clearing call (e.g., clearFocus()) on visibility changes instead of relying solely on focus: root.visible to avoid unexpected focus retention.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Ensure the loader activation logic still covers hover scenarios if that behavior is desired, or explicitly update it to remove hover-based close button reveal.
- Fix the typo 'forcusBorderVisible' so it matches the correct 'focusBorderVisible' property name.
- Consider using an explicit focus clearing call (e.g., clearFocus()) on visibility changes instead of relying solely on `focus: root.visible` to avoid unexpected focus retention.

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
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Removed explicit focus: true from OverlapNotify component as it was
causing focus issues when multiple notifications are present. Added
focus management to the main view container to clear focus when
NotificationCenter is closed. Replaced Control with FocusScope in
NotifyItemContent to better handle focus behavior and simplified the
close button visibility logic.

Log: Fixed focus issues in notification center

Influence:
1. Test notification center opening and closing behavior
2. Verify focus transitions between notifications
3. Check close button visibility and functionality
4. Test keyboard navigation through notifications
5. Verify focus is properly cleared when center is closed

fix: 修复通知中心的焦点问题

移除了OverlapNotify组件中显式的focus: true属性,该属性在多个通知同时存在
时会导致焦点问题。为主视图容器添加了焦点管理,在通知中心关闭时清除焦点。
将NotifyItemContent中的Control替换为FocusScope以更好地处理焦点行为,并简
化了关闭按钮的可见性逻辑。

Log: 修复通知中心的焦点问题

Influence:
1. 测试通知中心打开和关闭行为
2. 验证通知之间的焦点转换
3. 检查关闭按钮的可见性和功能
4. 测试通过键盘在通知间的导航
5. 验证通知中心关闭时焦点是否正确清除

PMS: BUG-284139
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我对这个代码审查有以下几点意见和建议:

1. 代码逻辑方面

  1. NotifyViewDelegate.qml中移除了focus: true,这个修改是合理的,因为焦点管理应该由父元素统一控制,避免多个元素同时争夺焦点。

  2. main.qml中添加的focus: root.visible是一个很好的改进,它确保了通知中心关闭时能正确清除焦点状态。

  3. NotifyItemContent.qml中的改动有一些需要注意的地方:

    • Control替换为FocusScope是合适的,因为这里只需要焦点处理功能,不需要Control的其他特性
    • 移除了closePlaceHolder.hoveredclosePlaceHolder.activeFocus的判断,这可能会影响某些交互场景

2. 代码质量方面

  1. 在NotifyItemContent.qml中,变量名forcusBorderVisible有拼写错误,应该是focusBorderVisible

  2. Loader组件的active条件判断变得复杂,建议拆分成多个条件或使用辅助函数来提高可读性。

  3. 注释不够完整,特别是对于焦点管理相关的逻辑应该添加更详细的说明。

3. 代码性能方面

  1. NotifyItemContent.qml中移除了对closePlaceHolder.hoveredclosePlaceHolder.activeFocus的判断,可能会在某些情况下导致不必要的Loader组件创建和销毁,影响性能。

  2. 建议对频繁更新的属性(如焦点状态)考虑使用性能优化手段,如缓存或防抖处理。

4. 代码安全方面

  1. 焦点管理相关的修改是安全的,因为遵循了Qt的焦点管理最佳实践。

  2. 在移除某些判断条件时,应该确保不会引入新的安全隐患,比如意外的焦点捕获或丢失。

改进建议

  1. 修复拼写错误:
forcusBorderVisible: visualFocus  // 改为
focusBorderVisible: visualFocus
  1. 改进Loader的active条件判断:
Loader {
    active: {
        var shouldShowCloseBtn = !(root.strongInteractive && root.actions.length > 0);
        var hasFocus = root.closeVisible || activeFocus;
        return shouldShowCloseBtn && hasFocus;
    }
    // ...
}
  1. 添加更详细的注释:
// FocusScope用于接收鼠标事件和管理焦点状态
FocusScope {
    focus: true
    // ...
}
  1. 考虑性能优化:
Loader {
    id: closeBtnLoader
    active: {
        // 使用局部变量提高可读性
        var isInteractive = root.strongInteractive && root.actions.length > 0;
        var shouldShowClose = root.closeVisible || activeFocus;
        return !isInteractive && shouldShowClose;
    }
    // ...
}

总的来说,这些修改主要集中在焦点管理的改进上,整体方向是正确的。但需要注意一些细节问题,如拼写错误和条件判断的完整性,以确保代码的健壮性和可维护性。

@18202781743

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 18, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit c691532 into linuxdeepin:master Sep 18, 2025
8 of 11 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