Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Sep 28, 2025

目前,更新窗口所在任务栏区域的调用仍在依赖 ItemModel::instance() 模型, 此提交转而将相关实现补充到新的 taskmanager interface 中,并移除对即将废弃的接口的调用.

Summary by Sourcery

Migrate window icon geometry updates to the new AbstractTaskManagerInterface, rename related methods to requestUpdateWindowIconGeometry, implement them in models and monitors, and remove the deprecated ItemModel-based API.

Enhancements:

  • Rename requestUpdateWindowGeometry to requestUpdateWindowIconGeometry across TaskManager, AbstractTaskManagerInterface, AbstractWindowMonitor, and relevant model classes
  • Implement requestUpdateWindowIconGeometry in DockGlobalElementModel, DockGroupModel, and X11WindowMonitor to forward icon geometry updates via the taskmanager interface
  • Remove the deprecated setAppItemWindowIconGeometry method and drop dependencies on ItemModel::instance()
  • Update the QML AppItem to invoke requestUpdateWindowIconGeometry instead of the old API

目前,更新窗口所在任务栏区域的调用仍在依赖 ItemModel::instance() 模型,
此提交转而将相关实现补充到新的 taskmanager interface 中,并移除对即将
废弃的接口的调用.

Log:
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要涉及窗口图标几何形状更新的功能改进,我将从以下几个方面进行分析:

  1. 语法逻辑:
  • 代码整体结构清晰,函数命名规范,符合Qt的命名习惯
  • requestUpdateWindowGeometry改为requestUpdateWindowIconGeometry更准确地表达了函数的功能
  • 函数参数保持一致,使用了默认参数delegate = nullptr
  1. 代码质量:
  • 改进后的代码移除了之前未使用的参数(Q_UNUSED),提高了代码可读性
  • 在DockGlobalElementModel和DockGroupModel中实现了具体的逻辑,而不是空实现
  • 使用了类型安全的dynamic_cast进行类型检查
  1. 代码性能:
  • 在DockGlobalElementModel中添加了sourceModel的检查,避免不必要的操作
  • 使用了更精确的几何计算,减少了冗余计算
  • 移除了旧的setAppItemWindowIconGeometry方法,避免了重复功能
  1. 代码安全:
  • 添加了nullptr检查,防止空指针访问
  • 使用了类型安全的类型转换
  • 在X11WindowMonitor中正确处理了窗口坐标转换

改进建议:

  1. 在X11WindowMonitor::requestUpdateWindowIconGeometry中,建议添加对geometry有效性的检查:
void X11WindowMonitor::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
{
    if (!index.isValid() || geometry.isEmpty() || !delegate) {
        return;
    }
    
    xcb_window_t winId = index.data(TaskManager::WinIdRole).toUInt();
    auto pos = qobject_cast<QWindow *>(delegate)->position() + geometry.topLeft();
    X11->setWindowIconGemeotry(winId, QRect(pos.x(), pos.y(), geometry.width(), geometry.height()));
}
  1. 在DockGroupModel中,建议添加对index有效性的检查:
void DockGroupModel::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
{
    if (!index.isValid()) {
        return;
    }
    
    auto interface = dynamic_cast<AbstractTaskManagerInterface *>(sourceModel());
    if (nullptr == interface)
        return;

    auto indexRowCount = RoleGroupModel::rowCount(index);
    for (int i = 0; i < indexRowCount; i++) {
        auto cIndex = RoleGroupModel::index(i, 0, index);
        callInterfaceMethod(cIndex, &AbstractTaskManagerInterface::requestUpdateWindowIconGeometry, geometry, delegate);
    }
}
  1. 建议在AppItem.qml中添加geometry有效性检查:
onTriggered: {
    var pos = icon.mapToItem(null, 0, 0)
    var rect = Qt.rect(pos.x, pos.y, icon.width, icon.height)
    if (rect.width > 0 && rect.height > 0) {
        taskmanager.Applet.requestUpdateWindowIconGeometry(root.modelIndex, rect, Panel.rootObject)
    }
}
  1. 考虑在TaskManager中添加信号机制,当窗口图标几何形状更新时发出信号,便于其他组件响应。

  2. 建议为窗口图标几何形状更新添加日志记录,便于调试和问题追踪:

void X11WindowMonitor::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
{
    if (!index.isValid() || geometry.isEmpty() || !delegate) {
        qWarning() << "Invalid parameters in requestUpdateWindowIconGeometry";
        return;
    }
    
    xcb_window_t winId = index.data(TaskManager::WinIdRole).toUInt();
    auto pos = qobject_cast<QWindow *>(delegate)->position() + geometry.topLeft();
    X11->setWindowIconGemeotry(winId, QRect(pos.x(), pos.y(), geometry.width(), geometry.height()));
    
    qDebug() << "Updated window icon geometry for window:" << winId 
             << "Geometry:" << QRect(pos.x(), pos.y(), geometry.width(), geometry.height());
}

这些改进可以提高代码的健壮性、可维护性和可调试性,同时保持原有功能的完整性。

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 28, 2025

Reviewer's Guide

Migrates window icon geometry updates from the deprecated ItemModel interface to the new TaskManager interface by renaming methods, removing legacy calls, and implementing the propagation logic across models and monitors.

Class diagram for updated window icon geometry propagation

classDiagram
class AbstractTaskManagerInterface {
  +requestUpdateWindowIconGeometry(index: QModelIndex, geometry: QRect, delegate: QObject*)
}
class AbstractWindowMonitor {
  +requestUpdateWindowIconGeometry(index: QModelIndex, geometry: QRect, delegate: QObject*)
}
class X11WindowMonitor {
  +requestUpdateWindowIconGeometry(index: QModelIndex, geometry: QRect, delegate: QObject*)
}
class DockGlobalElementModel {
  +requestUpdateWindowIconGeometry(index: QModelIndex, geometry: QRect, delegate: QObject*)
}
class DockGroupModel {
  +requestUpdateWindowIconGeometry(index: QModelIndex, geometry: QRect, delegate: QObject*)
}
class TaskManager {
  +requestUpdateWindowIconGeometry(index: QModelIndex, geometry: QRect, delegate: QObject*)
}

AbstractTaskManagerInterface <|-- AbstractWindowMonitor
AbstractWindowMonitor <|-- X11WindowMonitor
AbstractTaskManagerInterface <|-- DockGlobalElementModel
AbstractTaskManagerInterface <|-- DockGroupModel
AbstractTaskManagerInterface <|-- TaskManager
TaskManager --> DockGlobalElementModel: uses
DockGlobalElementModel --> X11WindowMonitor: uses
DockGroupModel --> AbstractTaskManagerInterface: uses
Loading

File-Level Changes

Change Details Files
Renamed and replaced requestUpdateWindowGeometry with requestUpdateWindowIconGeometry across TaskManager interfaces and API
  • Updated method signatures in abstracttaskmanagerinterface.h, abstractwindowmonitor.h, x11windowmonitor.h, taskmanager.h, dockglobalelementmodel.h, and dockgroupmodel.h
  • Refactored TaskManager, DockGlobalElementModel, DockGroupModel, and AbstractWindowMonitor implementations to invoke the new method
  • Removed the deprecated setAppItemWindowIconGeometry API from TaskManager
abstracttaskmanagerinterface.h
abstractwindowmonitor.h
abstractwindowmonitor.cpp
x11windowmonitor.h
taskmanager.h
taskmanager.cpp
dockglobalelementmodel.h
dockgroupmodel.h
Added forwarding logic in models to propagate icon geometry updates to source models
  • In DockGlobalElementModel, extract sourceModel/sourceRow and delegate geometry update to activeAppModel
  • In DockGroupModel, iterate child indexes and callInterfaceMethod for each to request geometry update
dockglobalelementmodel.cpp
dockgroupmodel.cpp
Implemented requestUpdateWindowIconGeometry in X11WindowMonitor
  • Calculated window icon position based on delegate’s window position and provided geometry
  • Invoked X11->setWindowIconGemeotry to apply the new rectangle
x11windowmonitor.cpp
Updated QML to use the new TaskManager interface for icon geometry updates
  • Replaced deprecated setAppItemWindowIconGeometry call with requestUpdateWindowIconGeometry in AppItem.qml
  • Passed the modelIndex and Qt.rect for geometry instead of raw coordinates
AppItem.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 they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `panels/dock/taskmanager/x11windowmonitor.cpp:157` </location>
<code_context>
+void X11WindowMonitor::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
+{
+    xcb_window_t winId = index.data(TaskManager::WinIdRole).toUInt();
+    auto pos = qobject_cast<QWindow *>(delegate)->position() + geometry.topLeft();
+    X11->setWindowIconGemeotry(winId, QRect(pos.x(), pos.y(), geometry.width(), geometry.height()));
+}
</code_context>

<issue_to_address>
**issue (bug_risk):** Potential null pointer dereference with delegate casting.

Add a null check or type verification for delegate before casting to QWindow to prevent possible crashes.
</issue_to_address>

### Comment 2
<location> `panels/dock/taskmanager/x11windowmonitor.cpp:158` </location>
<code_context>
+{
+    xcb_window_t winId = index.data(TaskManager::WinIdRole).toUInt();
+    auto pos = qobject_cast<QWindow *>(delegate)->position() + geometry.topLeft();
+    X11->setWindowIconGemeotry(winId, QRect(pos.x(), pos.y(), geometry.width(), geometry.height()));
+}
+
</code_context>

<issue_to_address>
**issue (typo):** Typo in method name 'setWindowIconGemeotry'.

Rename the method to 'setWindowIconGeometry' for clarity and consistency.

Suggested implementation:

```cpp
    X11->setWindowIconGeometry(winId, QRect(pos.x(), pos.y(), geometry.width(), geometry.height()));

```

You will also need to:
1. Rename the method definition from `setWindowIconGemeotry` to `setWindowIconGeometry` in the X11 class implementation file.
2. Update the declaration in the corresponding header file for the X11 class.
3. Search for any other usages of `setWindowIconGemeotry` throughout the codebase and update them to `setWindowIconGeometry`.
</issue_to_address>

### Comment 3
<location> `panels/dock/taskmanager/dockgroupmodel.cpp:137-139` </location>
<code_context>
-    Q_UNUSED(index)
-    Q_UNUSED(geometry)
-    Q_UNUSED(delegate)
+    auto interface = dynamic_cast<AbstractTaskManagerInterface *>(sourceModel());
+    if (nullptr == interface)
+        return;
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Silent return on failed interface cast may hide errors.

Consider adding logging or error handling when the cast fails to improve debuggability.

```suggestion
    auto interface = dynamic_cast<AbstractTaskManagerInterface *>(sourceModel());
    if (nullptr == interface) {
        qWarning() << "DockGroupModel::requestUpdateWindowIconGeometry: sourceModel is not an AbstractTaskManagerInterface";
        return;
    }
```
</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.

void X11WindowMonitor::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
{
xcb_window_t winId = index.data(TaskManager::WinIdRole).toUInt();
auto pos = qobject_cast<QWindow *>(delegate)->position() + geometry.topLeft();
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): Potential null pointer dereference with delegate casting.

Add a null check or type verification for delegate before casting to QWindow to prevent possible crashes.

Comment on lines +137 to +139
auto interface = dynamic_cast<AbstractTaskManagerInterface *>(sourceModel());
if (nullptr == interface)
return;
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Silent return on failed interface cast may hide errors.

Consider adding logging or error handling when the cast fails to improve debuggability.

Suggested change
auto interface = dynamic_cast<AbstractTaskManagerInterface *>(sourceModel());
if (nullptr == interface)
return;
auto interface = dynamic_cast<AbstractTaskManagerInterface *>(sourceModel());
if (nullptr == interface) {
qWarning() << "DockGroupModel::requestUpdateWindowIconGeometry: sourceModel is not an AbstractTaskManagerInterface";
return;
}

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@BLumia BLumia merged commit 4f2ce6b into linuxdeepin:master Sep 28, 2025
10 of 11 checks passed
@BLumia BLumia deleted the set-window-icon-geometry branch September 28, 2025 09:59
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