Add Plasma task group shortcuts

This commit is contained in:
ajp_anton
2026-09-04 14:52:45 +00:00
parent 4a78e6b485
commit 088c42bc14
13 changed files with 923 additions and 0 deletions
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: MIT
#include "taskselection.h"
#include <QAbstractItemModel>
#include <QHash>
#include <QSet>
#include <QUrl>
#include <abstracttasksmodel.h>
#include <tasktools.h>
using TaskManager::AbstractTasksModel;
QModelIndex taskToActivate(const QAbstractItemModel &model, int row, int cyclePosition)
{
const QModelIndex task = model.index(row, 0);
if (!task.isValid() || model.rowCount(task) == 0) {
return task;
}
const int childCount = model.rowCount(task);
const int childRow = ((cyclePosition % childCount) + childCount) % childCount;
return model.index(childRow, 0, task);
}
QVector<int> logicalTaskRows(const QAbstractItemModel &model, bool separateLaunchers)
{
QVector<int> rows;
rows.reserve(model.rowCount());
if (separateLaunchers) {
for (int row = 0; row < model.rowCount(); ++row) {
rows.append(row);
}
return rows;
}
QHash<int, int> launcherTargets;
QSet<int> mergedWindows;
for (int launcherRow = 0; launcherRow < model.rowCount(); ++launcherRow) {
const QModelIndex launcher = model.index(launcherRow, 0);
if (!launcher.data(AbstractTasksModel::IsLauncher).toBool()) {
continue;
}
for (int windowRow = 0; windowRow < model.rowCount(); ++windowRow) {
const QModelIndex window = model.index(windowRow, 0);
if (!window.data(AbstractTasksModel::IsWindow).toBool()) {
continue;
}
const QString launcherAppId = launcher.data(AbstractTasksModel::AppId).toString();
const QString windowAppId = window.data(AbstractTasksModel::AppId).toString();
const QUrl launcherUrl = launcher.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl();
const QUrl windowUrl = window.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl();
if ((!launcherAppId.isEmpty() && launcherAppId == windowAppId)
|| (launcherUrl.isValid() && windowUrl.isValid()
&& TaskManager::launcherUrlsMatch(launcherUrl, windowUrl, TaskManager::IgnoreQueryItems))) {
launcherTargets.insert(launcherRow, windowRow);
mergedWindows.insert(windowRow);
break;
}
}
}
for (int row = 0; row < model.rowCount(); ++row) {
if (launcherTargets.contains(row)) {
rows.append(launcherTargets.value(row));
} else if (!mergedWindows.contains(row)) {
rows.append(row);
}
}
return rows;
}