Skip to content

Commit 88cd13d

Browse files
committed
feat: group application windows together in task manager
1. Modified window insertion logic to group all windows of the same application together 2. When adding new windows, they are now inserted after the last existing window of the same application 3. Maintains docked application positions while converting them to running windows 4. Improved data change signaling to include window title updates 5. Enhanced index adjustment logic for better row position tracking Log: Application windows are now grouped together in the task manager Influence: 1. Test opening multiple windows of the same application 2. Verify that windows of the same app appear consecutively in the task manager 3. Test window grouping when applications are both docked and running 4. Verify window title updates are properly reflected 5. Test window insertion and removal scenarios 6. Check that docked application positions are preserved when windows open feat: 在任务管理器中分组显示应用程序窗口 1. 修改窗口插入逻辑,将同一应用程序的所有窗口分组显示 2. 添加新窗口时,现在会插入到同一应用程序的最后一个现有窗口之后 3. 在将停靠应用程序转换为运行窗口时保持其位置 4. 改进数据变更信号,包含窗口标题更新 5. 增强索引调整逻辑以更好地跟踪行位置 处理任务栏窗口拆分需求时,需要将同一个应用窗口显示处理在一起。 Log: 应用程序窗口现在在任务管理器中分组显示 Influence: 1. 测试打开同一应用程序的多个窗口 2. 验证同一应用程序的窗口在任务管理器中是否连续显示 3. 测试应用程序同时处于停靠和运行状态时的窗口分组 4. 验证窗口标题更新是否正确反映 5. 测试窗口插入和移除场景 6. 检查窗口打开时停靠应用程序位置是否保持
1 parent 774c00e commit 88cd13d

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

panels/dock/taskmanager/dockcombinemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ QVariant DockCombineModel::data(const QModelIndex &index, int role) const
4848
auto res = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::DesktopIdRole)).toString();
4949
if (res.isEmpty()) {
5050
auto data = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::IdentityRole)).toStringList();
51-
res = data.value(0, "");
51+
res = data.join("-");
5252
}
5353
return res;
5454
}

panels/dock/taskmanager/dockglobalelementmodel.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,55 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
6464
auto index = m_activeAppModel->index(i, 0);
6565
auto desktopId = index.data(TaskManager::DesktopIdRole).toString();
6666

67-
auto it = std::find_if(m_data.begin(), m_data.end(), [this, &desktopId](auto &data) {
68-
return m_appsModel == std::get<1>(data) && desktopId == std::get<0>(data);
67+
if (desktopId.isEmpty())
68+
continue;
69+
//将同一应用的窗口添加到一起
70+
// Find the first occurrence of this app in m_data (either docked item or existing window)
71+
auto firstIt = std::find_if(m_data.begin(), m_data.end(), [&desktopId](const auto &data) {
72+
return std::get<0>(data) == desktopId;
6973
});
7074

71-
if (it != m_data.end()) {
72-
*it = std::make_tuple(desktopId, m_activeAppModel, i);
73-
auto pIndex = this->index(it - m_data.begin(), 0);
74-
Q_EMIT dataChanged(pIndex, pIndex, {TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole});
75-
76-
} else {
75+
if (firstIt == m_data.end()) {
76+
// No docked item or existing window yet, append to the end
7777
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
7878
m_data.append(std::make_tuple(desktopId, m_activeAppModel, i));
7979
endInsertRows();
80+
continue;
8081
}
82+
83+
// If the first occurrence still comes from m_appsModel, this is the first window:
84+
// reuse the docked position and turn it into a running window.
85+
if (std::get<1>(*firstIt) == m_appsModel) {
86+
*firstIt = std::make_tuple(desktopId, m_activeAppModel, i);
87+
auto pIndex = this->index(firstIt - m_data.begin(), 0);
88+
Q_EMIT dataChanged(pIndex,
89+
pIndex,
90+
{TaskManager::ActiveRole,
91+
TaskManager::AttentionRole,
92+
TaskManager::WindowsRole,
93+
TaskManager::MenusRole,
94+
TaskManager::WinTitleRole});
95+
continue;
96+
}
97+
98+
// There are already windows for this app: insert the new window
99+
// right after the last existing one so that all windows stay together.
100+
auto lastIt = firstIt;
101+
while (lastIt + 1 != m_data.end() && std::get<0>(*(lastIt + 1)) == desktopId) {
102+
++lastIt;
103+
}
104+
105+
auto insertRow = (lastIt - m_data.begin()) + 1;
106+
beginInsertRows(QModelIndex(), insertRow, insertRow);
107+
m_data.insert(lastIt + 1, std::make_tuple(desktopId, m_activeAppModel, i));
108+
endInsertRows();
81109
}
82110

83111
std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
84112
if (std::get<1>(data) == m_activeAppModel && std::get<2>(data) > first) {
85-
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) + ((last - first) + 1));
113+
data = std::make_tuple(std::get<0>(data),
114+
std::get<1>(data),
115+
std::get<2>(data) + ((last - first) + 1));
86116
}
87117
});
88118
},

0 commit comments

Comments
 (0)