Skip to content

Conversation

@wjyrich
Copy link
Contributor

@wjyrich wjyrich commented Nov 27, 2025

  1. Added new dconfig property "dockHiddenSurfaceIds" to store tray items that should be hidden in dock but remain visible in other areas like control center
  2. Introduced DockVisibleRole to track separate visibility state for dock display
  3. Modified TrayItemPositioner.qml to consider both visibility and dockVisible properties when positioning items
  4. Updated tray item filtering logic to check dockVisible status in addition to existing visibility checks
  5. Added setDockVisible and isDockVisible methods for controlling dock- specific visibility
  6. Enhanced updateVisualIndexes method to handle both visibility states when calculating visual positions

Log: Added ability to hide tray items from dock while keeping them visible in control center

Influence:

  1. Test tray items can be hidden from dock while remaining visible in control center
  2. Verify dockHiddenSurfaceIds configuration is properly saved and loaded
  3. Test visual positioning considers both visibility and dockVisible states
  4. Verify tray items with Attribute_ForceDock flag are always visible in dock
  5. Test collapsable, pinned, and fixed sections handle dock visibility correctly
  6. Verify stash placeholder visibility logic works with new dockVisible property

feat: 添加 Dock 特定托盘项可见性控制

  1. 新增 dconfig 属性 "dockHiddenSurfaceIds" 用于存储在 Dock 中隐藏但在控 制中心等其他区域保持可见的托盘项
  2. 引入 DockVisibleRole 来跟踪 Dock 显示的独立可见性状态
  3. 修改 TrayItemPositioner.qml 在定位项目时同时考虑可见性和 dockVisible 属性
  4. 更新托盘项过滤逻辑,在现有可见性检查基础上增加 dockVisible 状态检查
  5. 添加 setDockVisible 和 isDockVisible 方法来控制 Dock 特定可见性
  6. 增强 updateVisualIndexes 方法,在计算视觉位置时处理两种可见性状态

注:
加上此参数为了处理,在控制中心可以显示相应的插件项,保证在控制中心的任务栏插件列表可以驻留在任务栏的,但是即使控制中心可以控制保留驻留在任务栏,也可以通过此参数设置为不显示在任务栏。

Log: 新增在控制中心保持可见的同时从 Dock 隐藏托盘项的功能

Influence:

  1. 测试托盘项可以从 Dock 隐藏同时在控制中心保持可见
  2. 验证 dockHiddenSurfaceIds 配置是否正确保存和加载
  3. 测试视觉定位同时考虑可见性和 dockVisible 状态
  4. 验证带有 Attribute_ForceDock 标志的托盘项在 Dock 中始终可见
  5. 测试可折叠、固定和固定部分正确处理 Dock 可见性
  6. 验证隐藏占位符可见性逻辑与新的 dockVisible 属性正常工作

PMS: BUG-341141 BUG-341651

Summary by Sourcery

Add dock-specific tray item visibility, backed by configuration, and integrate it into tray item positioning and visual index calculation.

New Features:

  • Introduce a separate dockVisible role for tray items to control visibility in the dock independently from general visibility.
  • Persist dock-specific hidden tray item IDs via a new dockHiddenSurfaceIds dconfig entry and expose QML-invokable APIs to modify them.

Enhancements:

  • Update tray visual index calculation and section assignment to respect both general visibility and dock-specific visibility across stashed, collapsable, pinned, and fixed sections.
  • Modify TrayItemPositioner logic so dock layout only shows items that are both generally visible and dock-visible.

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 27, 2025

Reviewer's Guide

Adds a dock-specific visibility layer for tray items, backed by new dconfig state, and integrates it into tray sorting, visual index calculation, and QML positioning so items can be hidden from the dock while remaining visible elsewhere (e.g. control center).

Sequence diagram for toggling dock-specific tray item visibility

sequenceDiagram
    actor User
    participant DockUI as DockTraySettingsQML
    participant TrayModel as TraySortOrderModel
    participant DConfig as DtkCoreDConfig

    User->>DockUI: Toggle "Show in dock" for surfaceId
    DockUI->>TrayModel: setDockVisible(surfaceId, false)
    activate TrayModel
    TrayModel->>TrayModel: update m_dockHiddenIds (add surfaceId)
    TrayModel->>TrayModel: updateVisualIndexes()
    TrayModel->>DConfig: setValue(dockHiddenSurfaceIds, m_dockHiddenIds)
    DConfig-->>TrayModel: value persisted
    deactivate TrayModel

    Note over DockUI,TrayModel: Dock tray now filters by
    Note over DockUI,TrayModel: visibility && dockVisible

    User->>DockUI: Opens control center tray list
    DockUI->>DConfig: value(hiddenSurfaceIds)
    DConfig-->>DockUI: list without surfaceId (still visible)
    DockUI->>TrayModel: isDisplayedSurface(surfaceId)
    TrayModel-->>DockUI: true
    Note over User,DockUI: Item is hidden in dock but remains
    Note over User,DockUI: visible and configurable in control center

    rect rgb(230,230,250)
    Note over DConfig,TrayModel: On next startup
    DConfig-->>TrayModel: valueChanged(dockHiddenSurfaceIds)
    TrayModel->>TrayModel: loadDataFromDConfig()
    TrayModel->>TrayModel: updateVisualIndexes()
    end
Loading

Updated class diagram for TraySortOrderModel dock-specific visibility

classDiagram
    class TraySortOrderModel {
        +enum Roles
        +enum VisualSections
        +TraySortOrderModel(parent : QObject)
        +bool dropToDockTray(draggedSurfaceId : QString, dropVisualIndex : int, isBefore : bool)
        +void setSurfaceVisible(surfaceId : QString, visible : bool)
        +bool isDisplayedSurface(surfaceId : QString) const
        +void setDockVisible(surfaceId : QString, visible : bool)
        +bool isDockVisible(surfaceId : QString) const
        +QModelIndex getModelIndexByVisualIndex(visualIndex : int) const
        -void updateVisualIndexes()
        -QStandardItem* createTrayItem(name : QString, sectionType : int, iconKey : QString, delegateType : int, forbiddenSections : int)
        -void loadDataFromDConfig()
        -void saveDataToDConfig()
        -- roles --
        -int SurfaceIdRole
        -int VisibilityRole
        -int DockVisibleRole
        -int SectionTypeRole
        -int VisualIndexRole
        -int DelegateTypeRole
        -int PluginFlagsRole
        -- state --
        -DtkCoreDConfig* m_dconfig
        -QStringList m_collapsableIds
        -QStringList m_pinnedIds
        -QStringList m_fixedIds
        -QStringList m_hiddenIds
        -QStringList m_dockHiddenIds
        -bool m_collapsed
    }

    class DtkCoreDConfig {
        +QVariant value(key : QString) const
        +void setValue(key : QString, value : QVariant)
        +signal valueChanged(key : QString)
    }

    TraySortOrderModel --> DtkCoreDConfig : uses
Loading

File-Level Changes

Change Details Files
Introduce dock-specific visibility role and state in the tray sort model, persisted via dconfig.
  • Add DockVisibleRole to TraySortOrderModel roles and default role names for QML access.
  • Initialize each tray item with dockVisible = true when created.
  • Add m_dockHiddenIds list to store dock-hidden surface IDs, with accessor logic via setDockVisible and isDockVisible.
  • Load and save dockHiddenSurfaceIds from/to dconfig alongside existing hiddenSurfaceIds.
  • Trigger reload and visual index recomputation when dockHiddenSurfaceIds changes in dconfig.
panels/dock/tray/traysortordermodel.h
panels/dock/tray/traysortordermodel.cpp
panels/dock/dconfig/org.deepin.ds.dock.tray.json
Update visual index computation so dock visibility is considered independently from global visibility across all tray sections.
  • In updateVisualIndexes, compute dockVisible from m_dockHiddenIds for each item and set both VisibilityRole and DockVisibleRole on the item.
  • Gate stashed, collapsable, pinned, and fixed section visual index assignment on both itemVisible and dockVisible, ensuring dock-hidden items don’t occupy visual slots.
  • Keep Attribute_ForceDock behavior by still treating those plugins as visible while allowing separate dockVisible control where appropriate.
  • Ensure stash placeholder and collapse toggle visibility flags are driven by items that are both visible and dockVisible.
panels/dock/tray/traysortordermodel.cpp
Make QML tray item positioning respect the new dockVisible role in addition to existing visibility and section logic.
  • Extend TrayItemPositioner.qml’s shouldShowItem logic to require model.dockVisible in both collapsable and non-stashed branches.
  • Ensure QML bindings can consume DockVisibleRole via the newly exposed dockVisible role name from the model so dock-hidden items are excluded from layout while remaining logically visible elsewhere.
panels/dock/tray/package/TrayItemPositioner.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 updateVisualIndexes() for the stashed section, the itemVisible expression was accidentally changed to use Attribute_ForceDock in both the second and third terms, making (pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock) always true and effectively ignoring m_hiddenIds; this should likely remain Attribute_CanSetting in the negated check as in the other sections.
  • The new dockVisible handling currently ignores Attribute_ForceDock, so items with Attribute_ForceDock can still be hidden via dockHiddenSurfaceIds; if the intent is that force-docked items are always visible in the dock per the PR description, consider computing dockVisible as (flags & Dock::Attribute_ForceDock) || !m_dockHiddenIds.contains(id) (and potentially enforcing this in setDockVisible).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `updateVisualIndexes()` for the stashed section, the `itemVisible` expression was accidentally changed to use `Attribute_ForceDock` in both the second and third terms, making `(pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock)` always true and effectively ignoring `m_hiddenIds`; this should likely remain `Attribute_CanSetting` in the negated check as in the other sections.
- The new `dockVisible` handling currently ignores `Attribute_ForceDock`, so items with `Attribute_ForceDock` can still be hidden via `dockHiddenSurfaceIds`; if the intent is that force-docked items are always visible in the dock per the PR description, consider computing `dockVisible` as `(flags & Dock::Attribute_ForceDock) || !m_dockHiddenIds.contains(id)` (and potentially enforcing this in `setDockVisible`).

## Individual Comments

### Comment 1
<location> `panels/dock/tray/traysortordermodel.cpp:385` </location>
<code_context>
         // forcedock and can not setting plugin need always set to visible
         auto pluginFlags = results[0]->data(TraySortOrderModel::PluginFlagsRole).toInt();
-        bool itemVisible = (pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock) || !m_hiddenIds.contains(id);
+        bool itemVisible = (pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock) || !m_hiddenIds.contains(id);        bool dockVisible = !m_dockHiddenIds.contains(id);
+        bool dockVisible = !m_dockHiddenIds.contains(id);
         results[0]->setData(SECTION_STASHED, TraySortOrderModel::SectionTypeRole);
</code_context>

<issue_to_address>
**issue (bug_risk):** The combined declaration line both fails to compile and uses a visibility condition that is effectively always true.

Two separate issues here:

1) `itemVisible` and `dockVisible` are on the same physical line, which will not compile and harms readability. Since `dockVisible` is correctly declared on the next line, drop it from the first line and format as:

```cpp
bool itemVisible = (pluginFlags & Dock::Attribute_ForceDock)
                   || !(pluginFlags & Dock::Attribute_CanSetting)
                   || !m_hiddenIds.contains(id);
bool dockVisible = !m_dockHiddenIds.contains(id);
```

2) The current expression

```cpp
(pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock)
```

is a tautology (`A || !A`), so `itemVisible` is effectively always `true` (aside from the `m_hiddenIds` part). Other sections use `!(pluginFlags & Dock::Attribute_CanSetting)`, which matches the comment and should be mirrored here for correctness and consistency.
</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.

// forcedock and can not setting plugin need always set to visible
auto pluginFlags = results[0]->data(TraySortOrderModel::PluginFlagsRole).toInt();
bool itemVisible = (pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock) || !m_hiddenIds.contains(id);
bool itemVisible = (pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock) || !m_hiddenIds.contains(id); bool dockVisible = !m_dockHiddenIds.contains(id);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The combined declaration line both fails to compile and uses a visibility condition that is effectively always true.

Two separate issues here:

  1. itemVisible and dockVisible are on the same physical line, which will not compile and harms readability. Since dockVisible is correctly declared on the next line, drop it from the first line and format as:
bool itemVisible = (pluginFlags & Dock::Attribute_ForceDock)
                   || !(pluginFlags & Dock::Attribute_CanSetting)
                   || !m_hiddenIds.contains(id);
bool dockVisible = !m_dockHiddenIds.contains(id);
  1. The current expression
(pluginFlags & Dock::Attribute_ForceDock) || !(pluginFlags & Dock::Attribute_ForceDock)

is a tautology (A || !A), so itemVisible is effectively always true (aside from the m_hiddenIds part). Other sections use !(pluginFlags & Dock::Attribute_CanSetting), which matches the comment and should be mirrored here for correctness and consistency.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, 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

1. Added new dconfig property "dockHiddenSurfaceIds" to store tray items
that should be hidden in dock but remain visible in other areas like
control center
2. Introduced DockVisibleRole to track separate visibility state for
dock display
3. Modified TrayItemPositioner.qml to consider both visibility and
dockVisible properties when positioning items
4. Updated tray item filtering logic to check dockVisible status in
addition to existing visibility checks
5. Added setDockVisible and isDockVisible methods for controlling dock-
specific visibility
6. Enhanced updateVisualIndexes method to handle both visibility states
when calculating visual positions

Log: Added ability to hide tray items from dock while keeping them
visible in control center

Influence:
1. Test tray items can be hidden from dock while remaining visible in
control center
2. Verify dockHiddenSurfaceIds configuration is properly saved and
loaded
3. Test visual positioning considers both visibility and dockVisible
states
4. Verify tray items with Attribute_ForceDock flag are always visible
in dock
5. Test collapsable, pinned, and fixed sections handle dock visibility
correctly
6. Verify stash placeholder visibility logic works with new dockVisible
property

feat: 添加 Dock 特定托盘项可见性控制

1. 新增 dconfig 属性 "dockHiddenSurfaceIds" 用于存储在 Dock 中隐藏但在控
制中心等其他区域保持可见的托盘项
2. 引入 DockVisibleRole 来跟踪 Dock 显示的独立可见性状态
3. 修改 TrayItemPositioner.qml 在定位项目时同时考虑可见性和 dockVisible
属性
4. 更新托盘项过滤逻辑,在现有可见性检查基础上增加 dockVisible 状态检查
5. 添加 setDockVisible 和 isDockVisible 方法来控制 Dock 特定可见性
6. 增强 updateVisualIndexes 方法,在计算视觉位置时处理两种可见性状态

注:
加上此参数为了处理,在控制中心可以显示相应的插件项,保证在控制中心的任务栏插件列表可以驻留在任务栏的,但是即使控制中心可以控制保留驻留在任务栏,也可以通过此参数设置为不显示在任务栏。

Log: 新增在控制中心保持可见的同时从 Dock 隐藏托盘项的功能

Influence:
1. 测试托盘项可以从 Dock 隐藏同时在控制中心保持可见
2. 验证 dockHiddenSurfaceIds 配置是否正确保存和加载
3. 测试视觉定位同时考虑可见性和 dockVisible 状态
4. 验证带有 Attribute_ForceDock 标志的托盘项在 Dock 中始终可见
5. 测试可折叠、固定和固定部分正确处理 Dock 可见性
6. 验证隐藏占位符可见性逻辑与新的 dockVisible 属性正常工作

PMS: BUG-341141 BUG-341651
@deepin-ci-robot
Copy link

deepin pr auto review

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

  1. 代码功能概述:
    这段代码实现了Dock托盘中新增一个功能,允许某些项目在Dock托盘中隐藏但在其他区域(如控制中心)保持可见。主要修改包括:
  • 添加了新的配置项 dockHiddenSurfaceIds
  • 新增了 DockVisibleRole 角色来控制项目在Dock中的可见性
  • 增加了相关的方法来管理Dock可见性
  1. 代码质量分析:

优点:

  • 代码结构清晰,新功能与原有代码保持一致的风格
  • 添加了详细的注释说明
  • 配置项提供了中英文描述
  • 保持了向后兼容性

改进建议:

(1) 性能优化:
在 TraySortOrderModel::setDockVisible 方法中,每次修改都会调用 updateVisualIndexes() 和 saveDataToDConfig(),这可能会造成频繁的IO操作。建议:

void TraySortOrderModel::setDockVisible(const QString &surfaceId, bool visible)
{
    bool changed = false;
    if (visible) {
        if (m_dockHiddenIds.contains(surfaceId)) {
            m_dockHiddenIds.removeOne(surfaceId);
            changed = true;
        }
    } else {
        if (!m_dockHiddenIds.contains(surfaceId)) {
            m_dockHiddenIds.append(surfaceId);
            changed = true;
        }
    }
    
    if (changed) {
        updateVisualIndexes();
        saveDataToDConfig();
    }
}

(2) 安全性考虑:

  • 在处理 surfaceId 时应该添加验证,确保输入的合法性
  • 建议在 loadDataFromDConfig 中添加对 dockHiddenSurfaceIds 值的验证

(3) 代码健壮性:

  • 在 updateVisualIndexes() 方法中,对 dockVisible 的判断逻辑重复出现多次,建议提取为独立方法:
bool TraySortOrderModel::shouldShowInDock(const QString& surfaceId, bool itemVisible) const
{
    return itemVisible && !m_dockHiddenIds.contains(surfaceId);
}

(4) 命名规范:

  • 配置项名称 dockHiddenSurfaceIds 可以考虑改为更直观的名称,如 dockInvisibleSurfaceIds

(5) 错误处理:

  • 建议在配置文件读写操作中添加错误处理机制
  • 在 setDockVisible 方法中应该检查 surfaceId 是否存在
  1. 其他建议:
  • 考虑添加单元测试来验证新功能的正确性
  • 建议在代码文档中添加使用示例
  • 可以考虑添加信号来通知 dockHiddenSurfaceIds 的变化

这些改进建议主要关注代码的健壮性、性能和可维护性,不会影响现有功能。

@wjyrich
Copy link
Contributor Author

wjyrich commented Nov 27, 2025

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Nov 27, 2025

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit 8958bc5 into linuxdeepin:master Nov 27, 2025
10 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