Follow reordered taskbar pins in group shortcuts
This commit is contained in:
1 parent
dc2372ef3f
commit
535ac5b480
6 files changed
+180
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,12 +6,44 @@
|
||||
#include <QHash>
|
||||
#include <QSet>
|
||||
#include <QUrl>
|
||||
#include <algorithm>
|
||||
|
||||
#include <abstracttasksmodel.h>
|
||||
#include <tasksmodel.h>
|
||||
#include <tasktools.h>
|
||||
|
||||
using TaskManager::AbstractTasksModel;
|
||||
|
||||
QVector<int> logicalTaskRows(const TaskManager::TasksModel &model, bool separateLaunchers)
|
||||
{
|
||||
auto rows = logicalTaskRows(static_cast<const QAbstractItemModel &>(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<int> pinnedSlots;
|
||||
QVector<int> 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);
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
#include <QVector>
|
||||
|
||||
class QAbstractItemModel;
|
||||
namespace TaskManager {
|
||||
class TasksModel;
|
||||
}
|
||||
|
||||
QModelIndex taskToActivate(const QAbstractItemModel &model, int row, int cyclePosition);
|
||||
QVector<int> logicalTaskRows(const QAbstractItemModel &model, bool separateLaunchers);
|
||||
QVector<int> logicalTaskRows(const TaskManager::TasksModel &model, bool separateLaunchers);
|
||||
int initialCyclePosition(const QAbstractItemModel &model, int row, bool startWithFirst, bool backwards);
|
||||
@@ -0,0 +1,130 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "../taskselection.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QFile>
|
||||
#include <QTemporaryDir>
|
||||
#include <QTest>
|
||||
#include <QUrl>
|
||||
#include <QWindow>
|
||||
#include <abstracttasksmodel.h>
|
||||
#include <tasksmodel.h>
|
||||
|
||||
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<bool>("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<const QAbstractItemModel &>(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"
|
||||
Reference in new issue
Block a user