@@ -63,10 +63,71 @@ static QString getDesktopIdByPid(const QStringList &identifies)
6363 qCDebug (taskManagerLog) << " appId is empty, AM failed to identify window with pid:" << windowPid;
6464 return {};
6565 }
66-
66+
6767 return QString::fromUtf8 (appId);
6868}
6969
70+ // 检查应用的 Categories 是否在跳过列表中
71+ static bool shouldSkipCgroupsByCategories (const QModelIndex &itemIndex, QAbstractItemModel *model)
72+ {
73+ if (!itemIndex.isValid () || !model) {
74+ return false ;
75+ }
76+
77+ auto skipCategories = Settings->cgroupsBasedGroupingSkipCategories ();
78+ if (skipCategories.isEmpty ()) {
79+ return false ;
80+ }
81+
82+ QStringList categories = model->data (itemIndex, TaskManager::CategoriesRole).toStringList ();
83+ if (categories.isEmpty ()) {
84+ return false ;
85+ }
86+
87+ // 检查是否有任何 skipCategory 在应用的 categories 中
88+ for (const QString &skipCategory : skipCategories) {
89+ if (categories.contains (skipCategory)) {
90+ QString desktopId = model->data (itemIndex, model->roleNames ().key (" desktopId" )).toString ();
91+ qCDebug (taskManagerLog) << " Skipping cgroups grouping for" << desktopId
92+ << " due to category:" << skipCategory;
93+ return true ;
94+ }
95+ }
96+
97+ return false ;
98+ }
99+
100+ // 尝试通过 AM(Application Manager) 匹配应用程序
101+ static QModelIndex tryMatchByApplicationManager (const QStringList &identifies,
102+ QAbstractItemModel *model,
103+ const QHash<int , QByteArray> &roleNames)
104+ {
105+ if (!Settings->cgroupsBasedGrouping ()) {
106+ return QModelIndex ();
107+ }
108+
109+ auto desktopId = getDesktopIdByPid (identifies);
110+ if (desktopId.isEmpty () || Settings->cgroupsBasedGroupingSkipIds ().contains (desktopId)) {
111+ return QModelIndex ();
112+ }
113+
114+ // 先在 model 中查找 desktopId 对应的 item
115+ auto res = model->match (model->index (0 , 0 ), roleNames.key (MODEL_DESKTOPID),
116+ desktopId, 1 , Qt::MatchFixedString | Qt::MatchWrap).value (0 );
117+
118+ if (!res.isValid ()) {
119+ return QModelIndex ();
120+ }
121+
122+ // 检查找到的 item 是否应该根据 Categories 跳过 cgroups 分组
123+ if (shouldSkipCgroupsByCategories (res, model)) {
124+ return QModelIndex ();
125+ }
126+
127+ qCDebug (taskManagerLog) << " matched by AM desktop ID:" << desktopId << res;
128+ return res;
129+ }
130+
70131class BoolFilterModel : public QSortFilterProxyModel , public AbstractTaskManagerInterface
71132{
72133 Q_OBJECT
@@ -157,15 +218,9 @@ bool TaskManager::init()
157218 }
158219
159220 // 尝试通过AM(Application Manager)匹配应用程序
160- if (Settings->cgroupsBasedGrouping ()) {
161- auto desktopId = getDesktopIdByPid (identifies);
162- if (!desktopId.isEmpty () && !Settings->cgroupsBasedGroupingSkipIds ().contains (desktopId)) {
163- auto res = model->match (model->index (0 , 0 ), roleNames.key (MODEL_DESKTOPID), desktopId, 1 , Qt::MatchFixedString | Qt::MatchWrap).value (0 );
164- if (res.isValid ()) {
165- qCDebug (taskManagerLog) << " matched by AM desktop ID:" << desktopId << res;
166- return res;
167- }
168- }
221+ auto amMatchResult = tryMatchByApplicationManager (identifies, model, roleNames);
222+ if (amMatchResult.isValid ()) {
223+ return amMatchResult;
169224 }
170225
171226 auto res = model->match (model->index (0 , 0 ), roleNames.key (MODEL_DESKTOPID), identifies.value (0 ), 1 , Qt::MatchEndsWith);
0 commit comments