Skip to content

Commit 65dedd8

Browse files
committed
fix: sometimes clicking dock icon won't activate window as intended
修正部分情况下点击任务栏上的图标无法激活已经打开的窗口的问题. 复现步骤: 1. 启动程序A,然后再启动程序A(使目前存在两个A窗口) 2. 点击任何一个其他程序的窗口,切换焦点到其他程序B 3. 点击任务栏上的A图标,将其中一个A窗口激活到顶部 4. 点击这个A窗口的关闭按钮 5. 点击任务栏上的A图标,观察结果 修复前:点击无反应 修复后:点击有反应,会把A置前 PMS: BUG-335803 Log:
1 parent 295e1c4 commit 65dedd8

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

panels/dock/taskmanager/dockgroupmodel.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@ DockGroupModel::DockGroupModel(QAbstractItemModel *sourceModel, int role, QObjec
2626
Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole});
2727
});
2828
connect(this, &QAbstractItemModel::rowsRemoved, this, [this](const QModelIndex &parent, int first, int last) {
29-
Q_UNUSED(first)
30-
Q_UNUSED(last)
3129
if (!parent.isValid())
3230
return;
31+
32+
// Update m_currentActiveWindow when windows are removed
33+
int parentRow = parent.row();
34+
if (m_currentActiveWindow.contains(parentRow)) {
35+
int currentActive = m_currentActiveWindow.value(parentRow);
36+
int windowCount = RoleGroupModel::rowCount(parent);
37+
38+
// Check if the current active window was removed
39+
if (currentActive >= first && currentActive <= last) {
40+
// Current active window was removed, reset to first window
41+
resetActiveWindow(parentRow);
42+
} else if (currentActive > last) {
43+
// Current active window is after the removed range, shift it back
44+
int removedCount = last - first + 1;
45+
m_currentActiveWindow[parentRow] = currentActive - removedCount;
46+
}
47+
// If currentActive < first, no change needed
48+
}
49+
3350
Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole});
3451
});
3552

@@ -179,4 +196,18 @@ void DockGroupModel::requestNewInstance(const QModelIndex &index, const QString
179196
return;
180197
}
181198
}
199+
200+
void DockGroupModel::resetActiveWindow(int parentRow)
201+
{
202+
if (m_currentActiveWindow.contains(parentRow)) {
203+
int windowCount = RoleGroupModel::rowCount(index(parentRow, 0));
204+
if (windowCount > 0) {
205+
// Reset to first window
206+
m_currentActiveWindow[parentRow] = 0;
207+
} else {
208+
// No windows left, remove the tracking
209+
m_currentActiveWindow.remove(parentRow);
210+
}
211+
}
212+
}
182213
}

panels/dock/taskmanager/dockgroupmodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class DockGroupModel : public RoleGroupModel, public AbstractTaskManagerInterfac
2828
private:
2929
bool any(const QModelIndex &index, int role) const;
3030
QVariantList all(const QModelIndex &index, int role) const;
31+
void resetActiveWindow(int parentRow);
3132

3233
private:
3334
int m_roleForDeduplication;

0 commit comments

Comments
 (0)