From 535ac5b480f99865e692f74f3081843b2494566c Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Tue, 20 Oct 2026 16:29:22 +0000 Subject: [PATCH] Follow reordered taskbar pins in group shortcuts --- plasma-task-group-shortcuts/CMakeLists.txt | 4 + plasma-task-group-shortcuts/main.cpp | 7 +- .../plasma-task-group-shortcuts.spec | 5 +- plasma-task-group-shortcuts/taskselection.cpp | 32 +++++ plasma-task-group-shortcuts/taskselection.h | 4 + .../tests/test-launcherorder.cpp | 130 ++++++++++++++++++ 6 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 plasma-task-group-shortcuts/tests/test-launcherorder.cpp diff --git a/plasma-task-group-shortcuts/CMakeLists.txt b/plasma-task-group-shortcuts/CMakeLists.txt index 7f7870d..945bc1c 100644 --- a/plasma-task-group-shortcuts/CMakeLists.txt +++ b/plasma-task-group-shortcuts/CMakeLists.txt @@ -78,6 +78,10 @@ if(BUILD_TESTING) ) add_test(NAME taskselection COMMAND test-taskselection) + add_executable(test-launcherorder tests/test-launcherorder.cpp taskselection.cpp) + target_link_libraries(test-launcherorder PRIVATE Qt6::Test Qt6::Gui KF6::ConfigCore KF6::Service PW::LibTaskManager) + add_test(NAME launcherorder COMMAND test-launcherorder -platform offscreen) + add_executable(test-keyboardlayout tests/test-keyboardlayout.cpp keyboardlayout.cpp diff --git a/plasma-task-group-shortcuts/main.cpp b/plasma-task-group-shortcuts/main.cpp index ea7f295..ef5aaae 100644 --- a/plasma-task-group-shortcuts/main.cpp +++ b/plasma-task-group-shortcuts/main.cpp @@ -317,7 +317,12 @@ private: } m_panelLocation = panel.location; - m_model.setLauncherList(config.readEntry("launchers", QStringList())); + const QStringList launchers = config.readEntry("launchers", QStringList()); + if (m_model.launcherList() != launchers) { + m_selection.cancel(); + m_lastShortcut = -1; + m_model.setLauncherList(launchers); + } m_model.setFilterByCurrentVirtualDesktop(config.readEntry("showOnlyCurrentDesktop", true)); m_model.setFilterByScreen(config.readEntry("showOnlyCurrentScreen", false)); m_model.setFilterByActivity(config.readEntry("showOnlyCurrentActivity", true)); diff --git a/plasma-task-group-shortcuts/plasma-task-group-shortcuts.spec b/plasma-task-group-shortcuts/plasma-task-group-shortcuts.spec index 4638bc1..918a90b 100644 --- a/plasma-task-group-shortcuts/plasma-task-group-shortcuts.spec +++ b/plasma-task-group-shortcuts/plasma-task-group-shortcuts.spec @@ -1,6 +1,6 @@ Name: plasma-task-group-shortcuts Version: 0.1.0 -Release: 21%{?dist} +Release: 22%{?dist} Summary: Windows-like application-group shortcuts for the Plasma Task Manager License: MIT @@ -62,6 +62,9 @@ install -Dpm 0644 %{SOURCE2} \ %{_sysconfdir}/xdg/autostart/se.ajpanton.plasma-task-group-shortcuts-autostart.desktop %changelog +* Tue Oct 20 2026 fedora-tools contributors - 0.1.0-22 +- Follow reordered taskbar pins without restarting the shortcut tool + * Sat Sep 12 2026 fedora-tools contributors - 0.1.0-21 - Validate group indices and reduce repeated launcher lookups - Refresh geometry resource hashes during incremental builds diff --git a/plasma-task-group-shortcuts/taskselection.cpp b/plasma-task-group-shortcuts/taskselection.cpp index 4c91f08..44daffd 100644 --- a/plasma-task-group-shortcuts/taskselection.cpp +++ b/plasma-task-group-shortcuts/taskselection.cpp @@ -6,12 +6,44 @@ #include #include #include +#include #include +#include #include using TaskManager::AbstractTasksModel; +QVector logicalTaskRows(const TaskManager::TasksModel &model, bool separateLaunchers) +{ + auto rows = logicalTaskRows(static_cast(model), separateLaunchers); + if (model.sortMode() != TaskManager::TasksModel::SortManual) { + return rows; + } + + // TasksModel keeps its manual window order when setLauncherList changes. + // Reorder only launcher-backed slots; leave unpinned tasks and children alone. + QVector pinnedSlots; + QVector pinnedRows; + const auto launcherPosition = [&](int row) { + return model.launcherPosition(model.index(row, 0).data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl()); + }; + for (int i = 0; i < rows.size(); ++i) { + if ((!separateLaunchers || model.index(rows.at(i), 0).data(AbstractTasksModel::IsLauncher).toBool()) + && launcherPosition(rows.at(i)) >= 0) { + pinnedSlots.append(i); + pinnedRows.append(rows.at(i)); + } + } + std::stable_sort(pinnedRows.begin(), pinnedRows.end(), [&](int left, int right) { + return launcherPosition(left) < launcherPosition(right); + }); + for (int i = 0; i < pinnedSlots.size(); ++i) { + rows[pinnedSlots.at(i)] = pinnedRows.at(i); + } + return rows; +} + QModelIndex taskToActivate(const QAbstractItemModel &model, int row, int cyclePosition) { const QModelIndex task = model.index(row, 0); diff --git a/plasma-task-group-shortcuts/taskselection.h b/plasma-task-group-shortcuts/taskselection.h index 59afa66..e03a80a 100644 --- a/plasma-task-group-shortcuts/taskselection.h +++ b/plasma-task-group-shortcuts/taskselection.h @@ -6,7 +6,11 @@ #include class QAbstractItemModel; +namespace TaskManager { +class TasksModel; +} QModelIndex taskToActivate(const QAbstractItemModel &model, int row, int cyclePosition); QVector logicalTaskRows(const QAbstractItemModel &model, bool separateLaunchers); +QVector logicalTaskRows(const TaskManager::TasksModel &model, bool separateLaunchers); int initialCyclePosition(const QAbstractItemModel &model, int row, bool startWithFirst, bool backwards); diff --git a/plasma-task-group-shortcuts/tests/test-launcherorder.cpp b/plasma-task-group-shortcuts/tests/test-launcherorder.cpp new file mode 100644 index 0000000..7c68d22 --- /dev/null +++ b/plasma-task-group-shortcuts/tests/test-launcherorder.cpp @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: MIT + +#include "../taskselection.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +using TaskManager::AbstractTasksModel; +using TaskManager::TasksModel; + +class LauncherOrderTest : public QObject +{ + Q_OBJECT + + QTemporaryDir m_directory; + QStringList m_launchers; + +private Q_SLOTS: + void initTestCase() + { + if (QGuiApplication::platformName() != QLatin1String("wayland")) { + QSKIP("Requires KWin's Wayland compositor and plasma-window-management protocol"); + } + QVERIFY(m_directory.isValid()); + for (const QString &name : {QStringLiteral("first"), QStringLiteral("second")}) { + QFile file(m_directory.filePath(name + QStringLiteral(".desktop"))); + QVERIFY(file.open(QIODevice::WriteOnly)); + const QByteArray contents = "[Desktop Entry]\nType=Application\nName=" + name.toUtf8() + + "\nExec=true\n"; + QCOMPARE(file.write(contents), contents.size()); + file.close(); + m_launchers.append(QUrl::fromLocalFile(file.fileName()).toString()); + } + QGuiApplication::setDesktopFileName(m_directory.filePath(QStringLiteral("second.desktop"))); + } + + void reordersLaunchers_data() + { + QTest::addColumn("separate"); + QTest::newRow("merged") << false; + QTest::newRow("separate") << true; + } + + void reordersLaunchers() + { + QFETCH(bool, separate); + TasksModel model; + model.setSortMode(TasksModel::SortManual); + model.setSeparateLaunchers(separate); + const QStringList original = m_launchers; + model.setLauncherList(original); + QTRY_COMPARE(model.rowCount(), 2); + const auto firstApp = [&] { + return model.index(logicalTaskRows(model, separate).first(), 0).data(AbstractTasksModel::AppId).toString(); + }; + const QString first = firstApp(); + const QString second = model.index(1, 0).data(AbstractTasksModel::AppId).toString(); + QVERIFY(!first.isEmpty()); + QVERIFY(first != second); + const QStringList reversed{original.at(1), original.at(0)}; + model.setLauncherList(reversed); + QCOMPARE(firstApp(), second); + model.setLauncherList(reversed); + QCOMPARE(firstApp(), second); + model.setLauncherList(original); + QCOMPARE(firstApp(), first); + + model.setSortMode(TasksModel::SortAlpha); + model.setLauncherList(reversed); + QCOMPARE(logicalTaskRows(model, separate), + logicalTaskRows(static_cast(model), separate)); + } + + void reordersRunningApplication() + { + TasksModel model; + model.setSortMode(TasksModel::SortManual); + model.setSeparateLaunchers(false); + model.setLaunchInPlace(false); + model.setHideActivatedLaunchers(true); + model.setGroupMode(TasksModel::GroupApplications); + model.setGroupInline(false); + model.setGroupingWindowTasksThreshold(-1); + const QStringList original = m_launchers; + model.setLauncherList(original); + QWindow window; + window.setTitle(QStringLiteral("Launcher order regression test")); + window.resize(300, 200); + window.show(); + QTRY_VERIFY(window.isExposed()); + const auto firstIsWindow = [&] { + const auto rows = logicalTaskRows(model, false); + return !rows.isEmpty() + && model.index(rows.first(), 0).data(AbstractTasksModel::IsWindow).toBool(); + }; + QTRY_VERIFY(model.match(model.index(0, 0), AbstractTasksModel::IsWindow, true).size() == 1); + QVERIFY(!firstIsWindow()); + QWindow secondWindow; + secondWindow.setTitle(QStringLiteral("Second window in the same group")); + secondWindow.resize(300, 200); + secondWindow.show(); + QTRY_VERIFY(secondWindow.isExposed()); + const auto group = [&] { + return model.match(model.index(0, 0), AbstractTasksModel::IsWindow, true).first(); + }; + QTRY_COMPARE(model.rowCount(group()), 2); + const auto firstWindowId = taskToActivate(model, group().row(), 0).data(AbstractTasksModel::WinIdList); + const auto secondWindowId = taskToActivate(model, group().row(), 1).data(AbstractTasksModel::WinIdList); + QVERIFY(firstWindowId != secondWindowId); + const QStringList reversed{original.at(1), original.at(0)}; + model.setLauncherList(reversed); + QTRY_VERIFY(firstIsWindow()); + const int selectedRow = logicalTaskRows(model, false).first(); + QCOMPARE(taskToActivate(model, selectedRow, 0).data(AbstractTasksModel::WinIdList), firstWindowId); + QCOMPARE(taskToActivate(model, selectedRow, 1).data(AbstractTasksModel::WinIdList), secondWindowId); + model.setLauncherList(reversed); + QVERIFY(firstIsWindow()); + model.setLauncherList(original); + QVERIFY(!firstIsWindow()); + } +}; + +QTEST_MAIN(LauncherOrderTest) +#include "test-launcherorder.moc"