shift-shell/kwin/mobiletaskswitcher/taskmodel.h
Devin Lin 3d4b31c26b taskswitcher: Sort tasks by last activation
Fixes https://invent.kde.org/plasma/plasma-mobile/-/issues/343

This restores the sorting of tasks by their last activation. The task model now becomes a singleton and retains state even while the effect is not active, while the filter/sort proxy model is still initialized at task switcher load.
2024-07-02 21:42:13 +00:00

43 lines
No EOL
1.1 KiB
C++

// SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
// SPDX-FileCopyrightText: 2024 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <window.h>
#include <QAbstractListModel>
#include <QHash>
#include <QSortFilterProxyModel>
#include <QVariant>
namespace KWin
{
class TaskModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles { WindowRole = Qt::UserRole + 1, OutputRole, DesktopRole, ActivityRole, LastActivatedRole };
explicit TaskModel(QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
private:
void markRoleChanged(Window *window, int role);
void handleWindowAdded(Window *window);
void handleWindowRemoved(Window *window);
void setupWindowConnections(Window *window);
void handleActiveWindowChanged();
// qint64 - Last activated timestamp
QList<std::pair<Window *, qint64>> m_windows;
};
}; // namespace KWin