#include "WindowModel.hpp" #include WindowModel::WindowModel(QObject *parent) : QAbstractListModel(parent) { } int WindowModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; return m_windows.size(); } int WindowModel::count() const { return m_windows.size(); } QVariant WindowModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() < 0 || index.row() >= m_windows.size()) return {}; const WindowInfo &window = m_windows.at(index.row()); switch (role) { case WindowIdRole: return QString::number(window.id); case TitleRole: return window.title; case AppIdRole: return window.appId; case WindowClassRole: return window.windowClass; case WorkspaceRole: return window.workspace; case FocusedRole: return window.focused; case FloatingRole: return window.floating; case FullscreenRole: return window.fullscreen; case XRole: return window.x; case YRole: return window.y; case WidthRole: return window.width; case HeightRole: return window.height; case DisplayNameRole: case Qt::DisplayRole: return window.displayName.isEmpty() ? window.title : window.displayName; case IconNameRole: return window.iconName; case MinimizedRole: return window.minimized; case MaximizedRole: return window.maximized; case OutputRole: return window.output; default: return {}; } } QHash WindowModel::roleNames() const { return { {WindowIdRole, QByteArrayLiteral("windowId")}, {TitleRole, QByteArrayLiteral("title")}, {AppIdRole, QByteArrayLiteral("appId")}, {WindowClassRole, QByteArrayLiteral("windowClass")}, {WorkspaceRole, QByteArrayLiteral("workspace")}, {FocusedRole, QByteArrayLiteral("focused")}, {FloatingRole, QByteArrayLiteral("floating")}, {FullscreenRole, QByteArrayLiteral("fullscreen")}, {XRole, QByteArrayLiteral("x")}, {YRole, QByteArrayLiteral("y")}, {WidthRole, QByteArrayLiteral("width")}, {HeightRole, QByteArrayLiteral("height")}, {DisplayNameRole, QByteArrayLiteral("displayName")}, {IconNameRole, QByteArrayLiteral("iconName")}, {MinimizedRole, QByteArrayLiteral("minimized")}, {MaximizedRole, QByteArrayLiteral("maximized")}, {OutputRole, QByteArrayLiteral("output")}, }; } void WindowModel::setWindows(QVector windows) { beginResetModel(); m_windows = std::move(windows); endResetModel(); emit countChanged(); } const WindowInfo *WindowModel::windowAt(int row) const { if (row < 0 || row >= m_windows.size()) return nullptr; return &m_windows.at(row); } const WindowInfo *WindowModel::windowById(qint64 windowId) const { for (const WindowInfo &window : m_windows) { if (window.id == windowId) return &window; } return nullptr; }