Skip to content

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Nov 25, 2025

Fix the focus issue on secondary pages in Quick Settings

Log: Fix the focus issue on secondary pages in Quick Settings
pms: BUG-341435

Summary by Sourcery

Fix focus handling in Quick Settings pages to ensure the active view correctly receives focus when navigated to.

Bug Fixes:

  • Ensure embedded shell surfaces in quick panel sub-pages can explicitly receive focus.
  • Trigger focus acquisition when Quick Settings stack pages are activated to resolve focus loss on secondary pages.

Fix the focus issue on secondary pages in Quick Settings

Log: Fix the focus issue on secondary pages in Quick Settings
pms: BUG-341435
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码变更进行审查:

  1. 代码语法和逻辑:
  • 代码语法正确,符合QML规范
  • 添加了takeFocus()函数的调用链,逻辑清晰:
    • QuickPanelPage在StackView.onActivated时调用takeFocus()
    • SubPluginPage和ShellSurfaceItemProxy都实现了takeFocus()函数
    • 最终通过impl.takeFocus()或surfaceLayer.takeFocus()实现焦点获取
  1. 代码质量:
  • 函数命名清晰,takeFocus()直观表达了获取焦点的意图
  • 代码结构合理,通过代理模式将焦点请求传递到底层实现
  • 建议添加注释说明takeFocus()的具体作用和调用时机
  1. 代码性能:
  • 函数调用链较短,性能开销小
  • 没有引入额外的计算或内存分配
  1. 代码安全:
  • 需要确保impl和surfaceLayer对象在调用takeFocus()时已经初始化
  • 建议添加空值检查,例如:
function takeFocus() {
    if (impl) {
        impl.takeFocus()
    }
}

改进建议:

  1. 添加函数注释,说明takeFocus()的作用
  2. 增加空值检查,提高代码健壮性
  3. 考虑添加错误处理机制,防止焦点获取失败时的情况
  4. 可以考虑添加焦点状态检查,避免重复获取焦点

总体来说,这是一个合理的代码变更,实现了焦点管理的功能,但可以通过添加错误处理和注释来提高代码质量。

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 25, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes a focus handling bug on secondary Quick Settings pages by adding explicit focus delegation functions and invoking them when pages become active in the StackView.

Sequence diagram for focus delegation on Quick Settings secondary pages

sequenceDiagram
    actor User
    participant QuickPanelPage
    participant StackView
    participant SubPluginPage
    participant ShellSurfaceItemProxy as SurfaceLayer
    participant ShellSurfaceItemImpl as ShellSurfaceItem

    User->>QuickPanelPage: select_secondary_quick_setting()
    QuickPanelPage->>StackView: push(SubPluginPage)
    StackView->>SubPluginPage: activate()
    note over StackView,SubPluginPage: StackView.onActivated triggers
    StackView->>SubPluginPage: takeFocus()
    SubPluginPage->>SurfaceLayer: takeFocus()
    SurfaceLayer->>ShellSurfaceItem: takeFocus()
    ShellSurfaceItem-->>SurfaceLayer: focus_set()
    SurfaceLayer-->>SubPluginPage: focus_confirmed()
    SubPluginPage-->>User: secondary_page_is_focused()
Loading

Updated class diagram for Quick Settings focus handling components

classDiagram
    class ShellSurfaceItemProxy {
        +int implicitWidth
        +int implicitHeight
        +ShellSurfaceItem impl
        +takeFocus()
    }

    class ShellSurfaceItem {
        +int width
        +int height
        +takeFocus()
    }

    ShellSurfaceItemProxy *-- ShellSurfaceItem : contains_impl

    class SubPluginPage {
        +int subPluginMinHeight
        +int headerMargin
        +Item surfaceLayer
        +takeFocus()
    }

    SubPluginPage *-- ShellSurfaceItemProxy : uses_as_surfaceLayer

    class QuickPanelPage {
        +int contentHeight
        +Item panelView
        +StackView stackView
    }

    class StackView {
        +onActivating()
        +onActivated()
        +push(page)
    }

    QuickPanelPage *-- StackView : contains
    StackView --> SubPluginPage : manages_pages

    class FocusFlow {
        +takeFocus()
    }

    FocusFlow <|.. ShellSurfaceItemProxy : focus_delegate
    FocusFlow <|.. SubPluginPage : focus_delegate
Loading

File-Level Changes

Change Details Files
Expose a focus-handling function on shell surface proxy items so other components can delegate focus to the underlying implementation.
  • Added a takeFocus() function on the proxy item that delegates to impl.takeFocus()
  • Kept existing width/height bindings and structure unchanged
panels/dock/tray/ShellSurfaceItemProxy.qml
Allow Quick Settings sub-plugin pages to explicitly move focus to their surface layer when needed.
  • Introduced a takeFocus() function on the sub-plugin page item that calls surfaceLayer.takeFocus()
  • Left other initialization logic and properties untouched
panels/dock/tray/quickpanel/SubPluginPage.qml
Trigger focus acquisition on Quick Settings pages after they are fully activated in the StackView.
  • Hooked into StackView.onActivated in the quick panel page delegate to call takeFocus()
  • Retained existing StackView.onActivating behavior that rebinds contentHeight
panels/dock/tray/quickpanel/QuickPanelPage.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 there - I've reviewed your changes and found some issues that need to be addressed.

  • In QuickPanelPage.qml, StackView.onActivated blindly calls takeFocus(), which will throw if a given page/delegate does not implement that function; consider checking for its existence (e.g., if (typeof takeFocus === 'function') takeFocus();) or using a more generic focus API.
  • In SubPluginPage.qml and ShellSurfaceItemProxy.qml, the new takeFocus() helpers assume surfaceLayer/impl always exist and expose takeFocus; adding null/feature checks would make this safer against future layout or component changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In QuickPanelPage.qml, `StackView.onActivated` blindly calls `takeFocus()`, which will throw if a given page/delegate does not implement that function; consider checking for its existence (e.g., `if (typeof takeFocus === 'function') takeFocus();`) or using a more generic focus API.
- In SubPluginPage.qml and ShellSurfaceItemProxy.qml, the new `takeFocus()` helpers assume `surfaceLayer`/`impl` always exist and expose `takeFocus`; adding null/feature checks would make this safer against future layout or component changes.

## Individual Comments

### Comment 1
<location> `panels/dock/tray/quickpanel/QuickPanelPage.qml:67-68` </location>
<code_context>
             StackView.onActivating: function () {
                 panelView.contentHeight = Qt.binding(function() { return contentHeight})
             }
+            StackView.onActivated: function () {
+                takeFocus()
+            }
         }
</code_context>

<issue_to_address>
**issue (bug_risk):** Unqualified `takeFocus()` here is likely calling the wrong (or a non-existent) function.

Within this `StackView.onActivated` handler, `takeFocus()` will be resolved through the JS scope chain rather than on the activated item. If the goal is to focus the newly activated page, call it explicitly on that item (for example, `currentItem && currentItem.takeFocus()`) or another clearly scoped reference. As written, it may either invoke an unintended function or fail at runtime if `takeFocus` is not defined in the current scope.
</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: caixr23, pengfeixx

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

@pengfeixx
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Nov 26, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 66f3128 into linuxdeepin:master Nov 26, 2025
8 of 11 checks passed
@pengfeixx pengfeixx deleted the fix-341435 branch November 26, 2025 02:35
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