Improves focused-window geometry so chrome placement stays stable across workspaces and floating containers. WindowService now exposes focused workspace X/Y, resolves workspace by name, and publishes those offsets with focused geometry. The Sway backend now tracks the active floating frame through recursion and consistently derives frame/deco/content rects from that frame. QML chrome placement was updated to use workspace-relative coordinates and simpler direct margins (removing interpolation behaviors), with safer title-bar height handling for vertical centering.
96 lines
2.3 KiB
C++
96 lines
2.3 KiB
C++
#include "WorkspaceModel.hpp"
|
|
|
|
#include <utility>
|
|
|
|
WorkspaceModel::WorkspaceModel(QObject *parent)
|
|
: QAbstractListModel(parent)
|
|
{
|
|
}
|
|
|
|
int WorkspaceModel::rowCount(const QModelIndex &parent) const
|
|
{
|
|
if (parent.isValid())
|
|
return 0;
|
|
return m_workspaces.size();
|
|
}
|
|
|
|
int WorkspaceModel::count() const
|
|
{
|
|
return m_workspaces.size();
|
|
}
|
|
|
|
QVariant WorkspaceModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (!index.isValid() || index.row() < 0 || index.row() >= m_workspaces.size())
|
|
return {};
|
|
|
|
const WorkspaceInfo &workspace = m_workspaces.at(index.row());
|
|
switch (role) {
|
|
case WorkspaceIdRole:
|
|
return workspace.id;
|
|
case NameRole:
|
|
case Qt::DisplayRole:
|
|
return workspace.name;
|
|
case NumberRole:
|
|
return workspace.number;
|
|
case FocusedRole:
|
|
return workspace.focused;
|
|
case VisibleRole:
|
|
return workspace.visible;
|
|
case OutputRole:
|
|
return workspace.output;
|
|
case WindowCountRole:
|
|
return workspace.windowCount;
|
|
default:
|
|
return {};
|
|
}
|
|
}
|
|
|
|
QHash<int, QByteArray> WorkspaceModel::roleNames() const
|
|
{
|
|
return {
|
|
{WorkspaceIdRole, QByteArrayLiteral("workspaceId")},
|
|
{NameRole, QByteArrayLiteral("name")},
|
|
{NumberRole, QByteArrayLiteral("number")},
|
|
{FocusedRole, QByteArrayLiteral("focused")},
|
|
{VisibleRole, QByteArrayLiteral("visible")},
|
|
{OutputRole, QByteArrayLiteral("output")},
|
|
{WindowCountRole, QByteArrayLiteral("windowCount")},
|
|
};
|
|
}
|
|
|
|
void WorkspaceModel::setWorkspaces(QVector<WorkspaceInfo> workspaces)
|
|
{
|
|
beginResetModel();
|
|
m_workspaces = std::move(workspaces);
|
|
endResetModel();
|
|
emit countChanged();
|
|
}
|
|
|
|
const WorkspaceInfo *WorkspaceModel::workspaceAt(int row) const
|
|
{
|
|
if (row < 0 || row >= m_workspaces.size())
|
|
return nullptr;
|
|
return &m_workspaces.at(row);
|
|
}
|
|
|
|
const WorkspaceInfo *WorkspaceModel::focusedWorkspace() const
|
|
{
|
|
for (const WorkspaceInfo &workspace : m_workspaces) {
|
|
if (workspace.focused)
|
|
return &workspace;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const WorkspaceInfo *WorkspaceModel::workspaceByName(const QString &name) const
|
|
{
|
|
if (name.isEmpty())
|
|
return nullptr;
|
|
for (const WorkspaceInfo &workspace : m_workspaces) {
|
|
if (workspace.name == name)
|
|
return &workspace;
|
|
}
|
|
return nullptr;
|
|
}
|