Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Jun 9, 2025

Summary by Sourcery

Migrate TaskManager from legacy AppItem-based APIs to a fully model-driven implementation using DockItemModel and standardized TaskManager roles.

Enhancements:

  • Replace AppItemWindowModel with DockItemWindowModel that drives window previews from QModelIndexList and TaskManager roles
  • Unify preview interface across X11 and Wayland monitors by introducing requestPreview with QModelIndexList
  • Refactor AbstractWindowMonitor to implement AbstractTaskManagerInterface and expose requestActivate, requestNewInstance, requestClose, and other model-based actions
  • Simplify TaskManager load/init flow to defer monitor start and return DockItemModel from dataModel()
  • Revamp QML delegates to use modelIndex for interactions (activate, preview, new instance) and refactor OverflowContainer with scroll controls and clipping
  • Introduce fetchWindowPreview helper for capturing window thumbnails over D-Bus
  • Streamline RoleCombineModel and RoleGroupModel to generate and expose combined role names
  • Augment unit tests for role combiners and group models with QAbstractItemModelTester

Tests:

  • Add QAbstractItemModelTester-based tests for RoleCombineModel and RoleGroupModel

BLumia added 2 commits May 21, 2025 15:32
切换 taskmanager 区域的 model 为新的 DockItemModel,以解决一系列问题:

1. 部分场景下企业微信和微信图标合并/钉钉和微信合并等问题
2. 终端执行 gitk/dde-dconfig-editor 时不会单独显示任务栏图标
3. 没有 desktop-id 的带界面的可执行程序不会单独显示任务栏图标

Log:
@deepin-ci-robot
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 9, 2025

Reviewer's Guide

Migrate TaskManager to the new index-based DockItemModel by replacing AppItem-centric models with QModelIndexList handling, unifying preview logic, aligning monitors with AbstractTaskManagerInterface, modernizing TaskManager initialization, updating QML delegates for modelIndex usage, fixing role-proxy models, and miscellaneous cleanups.

Sequence Diagram for X11 Window Preview Request

sequenceDiagram
    actor User
    participant AppItem_qml as "AppItem.qml (UI)"
    participant TaskManager_Applet as "TaskManager (Applet)"
    participant X11WM as "X11WindowMonitor"
    participant X11PreviewCont as "X11WindowPreviewContainer"
    participant DIMAdapter as "DockItemWindowModel"
    participant GlobalFunc as "fetchWindowPreview()"
    participant KWinService as "KWin (D-Bus)"

    User->>AppItem_qml: Hover over task item
    AppItem_qml->>TaskManager_Applet: requestPreview([modelIndex], ...)
    TaskManager_Applet->>X11WM: requestPreview(indexes, ...)
    X11WM->>X11PreviewCont: showPreview(indexes, ...)
    X11PreviewCont->>DIMAdapter: setData(indexes)
    DIMAdapter->>DIMAdapter: resetPreviewPixmap()
    loop for each window in indexes
        DIMAdapter->>GlobalFunc: fetchWindowPreview(winId)
        GlobalFunc->>KWinService: CaptureWindow(winId, options, fd)
        KWinService-->>GlobalFunc: Pixmap data (via fd)
        GlobalFunc-->>DIMAdapter: QPixmap
    end
    DIMAdapter-->>X11PreviewCont: Provides preview data
    X11PreviewCont->>X11PreviewCont: Update view, show previews
    X11PreviewCont-->>User: Display window previews
Loading

Sequence Diagram for X11 Window Activation from Preview

sequenceDiagram
    actor User
    participant X11PreviewCont as "X11WindowPreviewContainer"
    participant TaskManagerRoles as "TaskManager (Roles Accessor)"
    participant X11Utils_Instance as "X11Utils"

    User->>X11PreviewCont: Click on a window preview
    X11PreviewCont->>X11PreviewCont: Get QModelIndex for clicked preview
    X11PreviewCont->>TaskManagerRoles: data(index, TaskManager::WinIdRole)
    TaskManagerRoles-->>X11PreviewCont: winId
    X11PreviewCont->>X11Utils_Instance: setActiveWindow(winId)
    X11Utils_Instance-->>User: Window is activated
Loading

Sequence Diagram for App Item Click (Launch or Activate)

sequenceDiagram
    actor User
    participant AppItem_qml as "AppItem.qml (UI)"
    participant TaskManager_Applet as "TaskManager (Applet)"
    participant AWM as "AbstractWindowMonitor"
    participant TargetWindow as "AbstractWindow"

    User->>AppItem_qml: Click App Item
    alt No open windows for app
        AppItem_qml->>TaskManager_Applet: requestNewInstance(modelIndex, "")
        TaskManager_Applet->>AWM: requestNewInstance(modelIndex, "")
        AWM->>AWM: Handle new instance creation
        AWM-->>User: New application instance starts
    else Has open windows
        AppItem_qml->>TaskManager_Applet: requestActivate(modelIndex)
        TaskManager_Applet->>AWM: requestActivate(modelIndex)
        AWM->>TargetWindow: window.activate() or window.minimize()
        TargetWindow-->>User: Window activated or minimized
    end
Loading

Class Diagram for Window Preview Model Refactoring (DockItemWindowModel)

classDiagram
    class QAbstractListModel {
        <<Abstract>>
    }
    class DockItemWindowModel {
        -m_dockItemModelIndexes : QModelIndexList
        -m_previewPixmaps : QHash~uint32_t, QPixmap~
        +DockItemWindowModel(QObject* parent)
        +rowCount() int
        +data(QModelIndex index, int role) QVariant
        +setData(const QModelIndexList& itemIndexes) void
        +resetPreviewPixmap() void
    }
    QAbstractListModel <|-- DockItemWindowModel

    class X11WindowPreviewContainer {
        -m_model : DockItemWindowModel*
        +X11WindowPreviewContainer(X11WindowMonitor* monitor, QWidget* parent)
        +showPreview(const QModelIndexList& indexes, ...) void
        +updateSize(int windowCount) void
    }
    X11WindowPreviewContainer o-- "1" DockItemWindowModel : uses

    class fetchWindowPreview {
        <<Global Function>>
        +fetchWindowPreview(const uint32_t& winId) QPixmap
    }
    DockItemWindowModel ..> fetchWindowPreview : uses

    class AppItemWindowModel {
        <<Old Class - Refactored>>
        -m_item : QPointer~AppItem~
        +setData(const QPointer~AppItem~& item) void
        -fetchWindowPreview(const uint32_t& winId) QPixmap
    }
    AppItemWindowModel --|> QAbstractListModel
Loading

Class Diagram for TaskManager and Monitor Hierarchy with AbstractTaskManagerInterface

classDiagram
    class TaskManager {
        -m_itemModel : DockItemModel*
        -m_windowMonitor : QScopedPointer~AbstractWindowMonitor~
        +dataModel() DockItemModel*
        +init() bool
        +load() bool
        # requestActivate(const QModelIndex& index) const
        # requestNewInstance(const QModelIndex& index, const QString& action) const
        # requestPreview(const QModelIndexList& indexes, ...) const
    }
    class AbstractTaskManagerInterface {
        <<Interface>>
        +requestActivate(const QModelIndex& index) const = 0
        +requestOpenUrls(const QModelIndex& index, const QList~QUrl~& urls) const = 0
        +requestNewInstance(const QModelIndex& index, const QString& action) const = 0
        +requestClose(const QModelIndex& index, bool force) const = 0
        +requestPreview(const QModelIndexList& indexes, ...) const = 0
    }
    AbstractTaskManagerInterface <|.. TaskManager

    class DockItemModel {
        <<Model>>
    }
    TaskManager o-- "1" DockItemModel : uses

    class QAbstractListModel {
        <<Abstract>>
    }
    class AbstractWindowMonitor {
        -m_trackedWindows : QList~AbstractWindow*~
        +roleNames() QHash~int, QByteArray~
        +data(const QModelIndex& index, int role) QVariant
        +trackWindow(AbstractWindow* window) void
        # requestActivate(const QModelIndex& index) const override
        # requestNewInstance(const QModelIndex& index, const QString& action) const override
        # requestPreview(const QModelIndexList& indexes, ...) const override
    }
    QAbstractListModel <|-- AbstractWindowMonitor
    AbstractTaskManagerInterface <|.. AbstractWindowMonitor

    class X11WindowMonitor {
        -m_windowPreview : QScopedPointer~X11WindowPreviewContainer~
        +requestPreview(const QModelIndexList& indexes, ...) const override
    }
    AbstractWindowMonitor <|-- X11WindowMonitor

    class TreeLandWindowMonitor {
        -m_dockPreview : QScopedPointer~TreeLandDockPreviewContext~
        +requestPreview(const QModelIndexList& indexes, ...) const override
    }
    AbstractWindowMonitor <|-- TreeLandWindowMonitor

    TaskManager o-- "1" AbstractWindowMonitor : uses
Loading

Class Diagram for QML Task Item Delegate Structure using modelIndex

classDiagram
  class TaskManager_qml {
    +OverflowContainer appContainer
  }
  class OverflowContainer_qml {
    +ListView listView
    +model: VisualItemModel
    +delegate: DropArea_delegate
    +property bool interactive
    +function scrollIncrease()
    +function scrollDecrease()
  }
  class DropArea_delegate {
    +required property int index
    +property var modelIndex
    +Row itemHolder
  }
  class Row_itemHolder {
    +AppItem_qml app
    +Label windowTitleLabel
  }
  class AppItem_qml {
    +required property var modelIndex
    +MouseArea mouseArea
    # onClicked: TaskManager.requestActivate(modelIndex) / requestNewInstance(modelIndex)
    # onEntered (for preview): taskmanager.Applet.requestPreview([modelIndex], ...)
  }

  TaskManager_qml *-- "1" OverflowContainer_qml : contains
  OverflowContainer_qml *-- "1" DropArea_delegate : delegate for
  DropArea_delegate *-- "1" Row_itemHolder : contains
  Row_itemHolder *-- "1" AppItem_qml : contains
  Row_itemHolder *-- "0..1" Label : contains
Loading

File-Level Changes

Change Details Files
Replace AppItemWindowModel with DockItemWindowModel and centralize preview fetching
  • Rename AppItemWindowModel to DockItemWindowModel
  • Change setData to accept QModelIndexList instead of QPointer
  • Update data() to use TaskManager roles via QModelIndexList
  • Remove duplicate fetchWindowPreview method and reuse standalone version
  • Adjust resetPreviewPixmap to iterate QModelIndexList and fetch previews
panels/dock/taskmanager/x11preview.cpp
panels/dock/taskmanager/x11preview.h
Adapt X11 and TreeLand monitors to the new requestPreview API
  • Implement requestPreview() taking QModelIndexList in X11WindowMonitor and TreeLandWindowMonitor
  • Remove legacy showItemPreview() overrides
  • Reset and reuse m_dockPreview via QScopedPointer cast
  • Transform window ID lists from QModelIndexList using TaskManager::WinIdRole
panels/dock/taskmanager/x11windowmonitor.cpp
panels/dock/taskmanager/x11windowmonitor.h
panels/dock/taskmanager/treelandwindowmonitor.cpp
panels/dock/taskmanager/treelandwindowmonitor.h
Unify AbstractWindowMonitor with AbstractTaskManagerInterface
  • Inherit AbstractTaskManagerInterface alongside QAbstractListModel
  • Implement requestActivate, requestClose, requestNewInstance, requestPreview, requestWindowsView methods
  • Update roleNames() and data() to use TaskManager:: roles
  • Remove deprecated showItemPreview() declaration
panels/dock/taskmanager/abstractwindowmonitor.cpp
panels/dock/taskmanager/abstractwindowmonitor.h
Refactor TaskManager initialization and model integration
  • Switch dataModel() to return DockItemModel instead of ItemModel
  • Rework windowAdded connection to build AppItem via QModelIndexList matching
  • Delay window monitor start by 500ms using QTimer
  • Remove legacy loadDockedAppItems(), preview and clickItem handlers
  • Add dumpItemInfo() and emit dataModelChanged when model updates
panels/dock/taskmanager/taskmanager.cpp
panels/dock/taskmanager/taskmanager.h
Update QML delegates to leverage new modelIndex and scrolling
  • Add required property var modelIndex to AppItem.qml and TaskManager.qml delegates
  • Change preview and activate calls to use TaskManager.requestPreview/Activate with modelIndex
  • Replace custom DropArea logic and add scroll buttons in OverflowContainer.qml
  • Introduce ApplicationItem.qml for unified delegate layout
  • Remove unused DropArea code and adjust spacing/anchors
panels/dock/taskmanager/package/TaskManager.qml
panels/dock/taskmanager/package/AppItem.qml
panels/dock/taskmanager/package/ApplicationItem.qml
panels/dock/OverflowContainer.qml
Fix RoleCombineModel and RoleGroupModel implementations and add model tests
  • Rename createRoleNames() for proxy and store custom m_roleNames
  • Update roleNames() to return stored hash
  • Guard RoleGroupModel rowCount against null sourceModel
  • Add QAbstractItemModelTester in RoleCombineModel and RoleGroupModel tests
  • Tweak test formatting and CMakeLists accordingly
tests/panels/dock/taskmanager/rolecombinemodeltests.cpp
tests/panels/dock/taskmanager/rolegroupmodeltests.cpp
tests/panels/dock/taskmanager/CMakeLists.txt
panels/dock/taskmanager/rolecombinemodel.cpp
panels/dock/taskmanager/rolecombinemodel.h
panels/dock/taskmanager/rolegroupmodel.cpp
Enhance settings loader and apply miscellaneous cleanups
  • Add early return and qDebug in loadDockedItems() in TaskManagerSettings
  • Adjust dockCombineModel to fallback icon name from winIcon role
  • Reorder includes in globals.h and remove unused headers
panels/dock/taskmanager/taskmanagersettings.cpp
panels/dock/taskmanager/taskmanagersettings.h
panels/dock/taskmanager/dockcombinemodel.cpp
panels/dock/taskmanager/globals.h

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

@deepin-bot
Copy link

deepin-bot bot commented Jun 12, 2025

TAG Bot

New tag: 1.99.39
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1156

@deepin-bot
Copy link

deepin-bot bot commented Jun 19, 2025

TAG Bot

New tag: 2.0.0
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1166

@deepin-bot
Copy link

deepin-bot bot commented Jun 24, 2025

TAG Bot

New tag: 2.0.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1169

@deepin-bot
Copy link

deepin-bot bot commented Jul 3, 2025

TAG Bot

New tag: 2.0.2
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1178

@deepin-bot
Copy link

deepin-bot bot commented Jul 10, 2025

TAG Bot

New tag: 2.0.3
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1185

@BLumia
Copy link
Member Author

BLumia commented Jul 23, 2025

此 PR 关闭处理,后续工作移到 #1201 (不完全替代此 PR)以及随后的其他 PR 处理。

@BLumia BLumia closed this Jul 23, 2025
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.

2 participants