From 06b0ee3a11f6f3d90ec2a2aebb7dfb2421c705c3 Mon Sep 17 00:00:00 2001 From: Usarin Heininga Date: Fri, 19 Mar 2021 14:32:32 +0100 Subject: [PATCH] Implement WaylandTasksModel LastActivated role. Window activation is tracked to implement a new front- end feature to activate the most recently active window (or fall through to stacking order otherwise) subsequently. CCBUG:370258 --- libtaskmanager/waylandtasksmodel.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libtaskmanager/waylandtasksmodel.cpp b/libtaskmanager/waylandtasksmodel.cpp index 6dd5daf5b..60868b921 100644 --- a/libtaskmanager/waylandtasksmodel.cpp +++ b/libtaskmanager/waylandtasksmodel.cpp @@ -48,6 +48,7 @@ public: Private(WaylandTasksModel *q); QList windows; QHash appDataCache; + QHash lastActivated; KWayland::Client::PlasmaWindowManagement *windowManagement = nullptr; KSharedConfig::Ptr rulesConfig; KDirWatch *configWatcher = nullptr; @@ -178,6 +179,7 @@ void WaylandTasksModel::Private::addWindow(KWayland::Client::PlasmaWindow *windo q->beginRemoveRows(QModelIndex(), row, row); windows.removeAt(row); appDataCache.remove(window); + lastActivated.remove(window); q->endRemoveRows(); } }; @@ -211,6 +213,9 @@ void WaylandTasksModel::Private::addWindow(KWayland::Client::PlasmaWindow *windo }); QObject::connect(window, &KWayland::Client::PlasmaWindow::activeChanged, q, [window, this] { + if (window->isActive()) { + lastActivated[window] = QTime::currentTime(); + } this->dataChanged(window, IsActive); }); @@ -452,6 +457,10 @@ QVariant WaylandTasksModel::data(const QModelIndex &index, int role) const return window->pid(); } else if (role == StackingOrder) { return d->windowManagement->stackingOrderUuids().indexOf(window->uuid()); + } else if (role == LastActivated) { + if (d->lastActivated.contains(window)) { + return d->lastActivated.value(window); + } } else if (role == ApplicationMenuObjectPath) { return window->applicationMenuObjectPath(); } else if (role == ApplicationMenuServiceName) {