Skip to content

fix: improve task manager layout calculation#1237

Merged
wjyrich merged 2 commits into
linuxdeepin:masterfrom
wjyrich:fix-bug-327583
Sep 5, 2025
Merged

fix: improve task manager layout calculation#1237
wjyrich merged 2 commits into
linuxdeepin:masterfrom
wjyrich:fix-bug-327583

Conversation

@wjyrich

@wjyrich wjyrich commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

Changed dock layout calculation to use new dockRemainingSpaceForCenter property instead of dockLeftSpaceForCenter
Modified implicitWidth/Height calculations in dockCenterPart to account for task manager's center dimensions
Replaced Math.min with Math.max in task manager size calculations to ensure proper space allocation
Added centerWidth and centerHeight properties in task manager for accurate centering calculations
These changes fix layout issues where task manager was not properly utilizing available space and improve centering behavior

fix: 改进任务管理器布局计算

使用新的 dockRemainingSpaceForCenter 属性替代 dockLeftSpaceForCenter 进 行停靠栏布局计算
修改 dockCenterPart 中的隐式宽度/高度计算以考虑任务管理器的居中尺寸
将任务管理器尺寸计算中的 Math.min 替换为 Math.max 以确保正确分配空间
在任务管理器中添加 centerWidth 和 centerHeight 属性以实现精确的居中计算
这些更改解决了任务管理器未正确利用可用空间的布局问题,并改进了居中行为

Pms: BUG-327583

Summary by Sourcery

Improve the task manager and dock center layout calculations by introducing a new remaining-space property, updating size calculations to use maximum values, and adding explicit center dimensions to ensure proper space utilization and centering.

Bug Fixes:

  • Fix layout issues where the task manager and dock center were not properly utilizing available space and centering

Enhancements:

  • Replace dockLeftSpaceForCenter with dockRemainingSpaceForCenter for more accurate space calculations
  • Switch from Math.min to Math.max in implicit width/height calculations to ensure the task manager uses the correct dimension
  • Add centerWidth and centerHeight properties in the task manager for precise centering
  • Adjust dockCenterPart implicit dimensions to account for the task manager’s center dimensions

@sourcery-ai

sourcery-ai Bot commented Sep 2, 2025

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

Reviewer's Guide

This PR refactors the dock layout by introducing a dedicated remaining-space property and updating the size calculations in both TaskManager and dock center components to better utilize available space and center content.

Entity relationship diagram for dock layout properties

erDiagram
    PANEL {
        int dockLeftSpaceForCenter
        int dockRemainingSpaceForCenter
    }
    TASKMANAGER {
        int remainingSpacesForTaskManager
        int centerWidth
        int centerHeight
    }
    DOCKCENTERPART {
        int implicitWidth
        int implicitHeight
    }
    PANEL ||--o{ TASKMANAGER : contains
    TASKMANAGER ||--o{ DOCKCENTERPART : manages
Loading

Class diagram for updated TaskManager and dock layout properties

classDiagram
    class Panel {
        +int dockLeftSpaceForCenter
        +int dockRemainingSpaceForCenter
    }
    class TaskManager {
        +bool useColumnLayout
        +int dockOrder
        +int remainingSpacesForTaskManager
        +int forceRelayoutWorkaround
        +int centerWidth
        +int centerHeight
    }
    Panel <|-- TaskManager
    class dockCenterPart {
        +implicitWidth
        +implicitHeight
    }
    TaskManager o-- dockCenterPart
Loading

File-Level Changes

Change Details Files
Introduce and adopt dockRemainingSpaceForCenter for central dock layout
  • Added dockRemainingSpaceForCenter property in main.qml with screen-ratio based formula
  • Replaced remainingSpacesForTaskManager definition in TaskManager.qml to use the new property
panels/dock/package/main.qml
panels/dock/taskmanager/package/TaskManager.qml
Refactor layout dimension calculations to improve centering accuracy
  • Added centerWidth and centerHeight properties in TaskManager.qml
  • Replaced Math.min with Math.max in implicitWidth/implicitHeight logic in TaskManager.qml
  • Adjusted dockCenterPart implicitWidth/implicitHeight in main.qml to integrate centerWidth/centerHeight
panels/dock/taskmanager/package/TaskManager.qml
panels/dock/package/main.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:

  • Extract the hardcoded 1.8 divisor in dockRemainingSpaceForCenter into a named constant or property to remove the magic number and clarify its purpose.
  • Cache the DS.applet("org.deepin.ds.dock.taskmanager").rootObject lookup in dockCenterPart implicit size bindings to improve readability and avoid repeated lookups.
  • Add a note or consider removing the forceRelayoutWorkaround hack in centerWidth/centerHeight once the underlying layout issue is resolved to avoid lingering temporary workarounds.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract the hardcoded 1.8 divisor in dockRemainingSpaceForCenter into a named constant or property to remove the magic number and clarify its purpose.
- Cache the DS.applet("org.deepin.ds.dock.taskmanager").rootObject lookup in dockCenterPart implicit size bindings to improve readability and avoid repeated lookups.
- Add a note or consider removing the forceRelayoutWorkaround hack in centerWidth/centerHeight once the underlying layout issue is resolved to avoid lingering temporary workarounds.

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.

Comment thread panels/dock/package/main.qml Outdated
Comment thread panels/dock/package/main.qml Outdated
let applet = DS.applet("org.deepin.ds.dock.taskmanager")
return applet ? applet.rootObject : null
}
implicitWidth: centerLoader.implicitWidth - taskmanagerRootObject.implicitWidth + taskmanagerRootObject.centerWidth

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这也没判空呀,

Changed dock layout calculation to use new dockRemainingSpaceForCenter
property instead of dockLeftSpaceForCenter
Modified implicitWidth/Height calculations in dockCenterPart to account
for task manager's center dimensions
Replaced Math.min with Math.max in task manager size calculations to
ensure proper space allocation
Added centerWidth and centerHeight properties in task manager for
accurate centering calculations
These changes fix layout issues where task manager was not properly
utilizing available space and improve centering behavior

fix: 改进任务管理器布局计算

使用新的 dockRemainingSpaceForCenter 属性替代 dockLeftSpaceForCenter 进
行停靠栏布局计算
修改 dockCenterPart 中的隐式宽度/高度计算以考虑任务管理器的居中尺寸
将任务管理器尺寸计算中的 Math.min 替换为 Math.max 以确保正确分配空间
在任务管理器中添加 centerWidth 和 centerHeight 属性以实现精确的居中计算
这些更改解决了任务管理器未正确利用可用空间的布局问题,并改进了居中行为

Pms: BUG-327583
@deepin-ci-robot

Copy link
Copy Markdown

[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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我对这个Git diff进行了仔细审查,以下是我的分析和改进建议:

1. 代码逻辑分析

  1. 在main.qml中新增了dockRemainingSpaceForCenter属性,用于计算中心区域的剩余空间
  2. 修改了dockCenterPart的尺寸计算逻辑,引入了任务管理器相关的属性
  3. 在TaskManager.qml中,修改了remainingSpacesForTaskManager的计算方式
  4. 将Math.min改为Math.max来计算implicitWidth和implicitHeight

2. 语法问题

没有明显的语法错误,但代码格式可以进一步优化:

  • main.qml中新增的属性声明可以适当分组,提高可读性
  • TaskManager.qml中的注释可以更详细地解释用途

3. 代码质量改进

  1. 命名一致性

    • dockRemainingSpaceForCenterdockLeftSpaceForCenter命名风格保持一致,这点很好
    • taskmanagerRootObject的命名使用了驼峰式,而其他属性使用下划线式,建议统一
  2. 代码组织

    • main.qml中taskmanager相关的属性可以组织在一起,形成一个更清晰的结构
    • 建议将TaskManager.qml中的appContainerWidth和appContainerHeight的注释移到属性声明处
  3. 错误处理

    • 在获取taskmanagerRootObject时使用了空值检查,这是好的实践
    • 但建议添加更多的错误处理逻辑,例如当applet加载失败时的回退方案

4. 性能优化

  1. 属性访问优化

    • taskmanagerRootObject使用了属性绑定,这可能导致频繁的重新计算
    • 考虑使用Loader的onLoaded信号来获取rootObject,减少不必要的重新计算
  2. 计算优化

    • dockRemainingSpaceForCenter中的除法运算(/1.8)可以提取为常量,提高可读性
    • forceRelayoutWorkaround的使用可能影响性能,建议寻找更好的解决方案

5. 安全性考虑

  1. 空值检查

    • 已经对taskmanagerRootObject进行了空值检查,这是好的
    • 建议对其他可能为null的属性也添加类似的保护
  2. 边界条件

    • 在计算尺寸时没有考虑负值的情况,可能导致布局问题
    • 建议添加Math.max(0, ...)来确保尺寸不为负

具体改进建议

  1. main.qml中的改进:
// 常量定义
readonly property real DOCK_CENTER_SPACE_RATIO: 1.8

// 任务管理器相关属性分组
property var taskmanagerRootObject: {
    let applet = DS.applet("org.deepin.ds.dock.taskmanager")
    return applet ? applet.rootObject : null
}

readonly property real taskmanagerImplicitWidth: taskmanagerRootObject ? taskmanagerRootObject.implicitWidth : 0
readonly property real taskmanagerImplicitHeight: taskmanagerRootObject ? taskmanagerRootObject.implicitHeight : 0
readonly property real taskmanagerAppContainerWidth: taskmanagerRootObject ? taskmanagerRootObject.appContainerWidth : 0
readonly property real taskmanagerAppContainerHeight: taskmanagerRootObject ? taskmanagerRootObject.appContainerHeight : 0

// 改进后的尺寸计算
implicitWidth: Math.max(0, centerLoader.implicitWidth - taskmanagerImplicitWidth + taskmanagerAppContainerWidth)
implicitHeight: Math.max(0, centerLoader.implicitHeight - taskmanagerImplicitHeight + taskmanagerAppContainerHeight)
  1. TaskManager.qml中的改进:
// 常量定义
readonly property real TASK_MANAGER_SPACE_RATIO: 1.2

// 改进后的空间计算
property int remainingSpacesForTaskManager: Panel.itemAlignment === Dock.LeftAlignment ? 
    Panel.rootObject.dockLeftSpaceForCenter : 
    Math.max(0, Panel.rootObject.dockRemainingSpaceForCenter)

// 改进后的尺寸计算
implicitWidth: useColumnLayout ? 
    Panel.rootObject.dockSize : 
    (Math.max(0, remainingSpacesForTaskManager) + forceRelayoutWorkaround)
implicitHeight: useColumnLayout ? 
    (Math.max(0, remainingSpacesForTaskManager) + forceRelayoutWorkaround) : 
    Panel.rootObject.dockSize

这些改进可以提高代码的可读性、可靠性和性能,同时更好地处理边界条件。

@wjyrich wjyrich merged commit 34db1b0 into linuxdeepin:master Sep 5, 2025
9 of 10 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