Compare commits

..

1 commit

Author SHA1 Message Date
cad9198241
core/colorquant: add ColorQuantizer 2025-01-27 21:17:20 -05:00
4 changed files with 27 additions and 62 deletions

View file

@ -333,7 +333,6 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
auto* monitor = this->findMonitorByName(name, true); auto* monitor = this->findMonitorByName(name, true);
this->setFocusedMonitor(monitor); this->setFocusedMonitor(monitor);
monitor->setActiveWorkspace(workspace); monitor->setActiveWorkspace(workspace);
qCDebug(logHyprlandIpc) << "Monitor" << name << "focused with workspace" << workspace->id();
} else if (event->name == "workspacev2") { } else if (event->name == "workspacev2") {
auto args = event->parseView(2); auto args = event->parseView(2);
auto id = args.at(0).toInt(); auto id = args.at(0).toInt();
@ -342,8 +341,6 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
if (this->mFocusedMonitor != nullptr) { if (this->mFocusedMonitor != nullptr) {
auto* workspace = this->findWorkspaceByName(name, true, id); auto* workspace = this->findWorkspaceByName(name, true, id);
this->mFocusedMonitor->setActiveWorkspace(workspace); this->mFocusedMonitor->setActiveWorkspace(workspace);
qCDebug(logHyprlandIpc) << "Workspace" << id << "activated on"
<< this->mFocusedMonitor->name();
} }
} else if (event->name == "moveworkspacev2") { } else if (event->name == "moveworkspacev2") {
auto args = event->parseView(3); auto args = event->parseView(3);
@ -354,7 +351,6 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
auto* workspace = this->findWorkspaceByName(name, true, id); auto* workspace = this->findWorkspaceByName(name, true, id);
auto* monitor = this->findMonitorByName(monitorName, true); auto* monitor = this->findMonitorByName(monitorName, true);
qCDebug(logHyprlandIpc) << "Workspace" << id << "moved to monitor" << monitorName;
workspace->setMonitor(monitor); workspace->setMonitor(monitor);
} else if (event->name == "renameworkspace") { } else if (event->name == "renameworkspace") {
auto args = event->parseView(2); auto args = event->parseView(2);
@ -378,28 +374,15 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) {
HyprlandWorkspace* HyprlandWorkspace*
HyprlandIpc::findWorkspaceByName(const QString& name, bool createIfMissing, qint32 id) { HyprlandIpc::findWorkspaceByName(const QString& name, bool createIfMissing, qint32 id) {
const auto& mList = this->mWorkspaces.valueList(); const auto& mList = this->mWorkspaces.valueList();
HyprlandWorkspace* workspace = nullptr;
if (id != -1) { auto workspaceIter =
auto workspaceIter = std::ranges::find_if(mList, [name](const HyprlandWorkspace* m) { return m->name() == name; });
std::ranges::find_if(mList, [&](const HyprlandWorkspace* m) { return m->id() == id; });
workspace = workspaceIter == mList.end() ? nullptr : *workspaceIter; if (workspaceIter != mList.end()) {
} return *workspaceIter;
if (!workspace) {
auto workspaceIter =
std::ranges::find_if(mList, [&](const HyprlandWorkspace* m) { return m->name() == name; });
workspace = workspaceIter == mList.end() ? nullptr : *workspaceIter;
}
if (workspace) {
return workspace;
} else if (createIfMissing) { } else if (createIfMissing) {
qCDebug(logHyprlandIpc) << "Workspace" << name qCDebug(logHyprlandIpc) << "Workspace" << name
<< "requested before creation, performing early init with id" << id; << "requested before creation, performing early init";
auto* workspace = new HyprlandWorkspace(this); auto* workspace = new HyprlandWorkspace(this);
workspace->updateInitial(id, name); workspace->updateInitial(id, name);
this->mWorkspaces.insertObject(workspace); this->mWorkspaces.insertObject(workspace);
@ -417,34 +400,24 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) {
this->requestingWorkspaces = false; this->requestingWorkspaces = false;
if (!success) return; if (!success) return;
qCDebug(logHyprlandIpc) << "Parsing workspaces response"; qCDebug(logHyprlandIpc) << "parsing workspaces response";
auto json = QJsonDocument::fromJson(resp).array(); auto json = QJsonDocument::fromJson(resp).array();
const auto& mList = this->mWorkspaces.valueList(); const auto& mList = this->mWorkspaces.valueList();
auto ids = QVector<quint32>(); auto names = QVector<QString>();
for (auto entry: json) { for (auto entry: json) {
auto object = entry.toObject().toVariantMap(); auto object = entry.toObject().toVariantMap();
auto name = object.value("name").toString();
auto id = object.value("id").toInt(); auto workspaceIter = std::ranges::find_if(mList, [name](const HyprlandWorkspace* m) {
return m->name() == name;
auto workspaceIter = });
std::ranges::find_if(mList, [&](const HyprlandWorkspace* m) { return m->id() == id; });
// Only fall back to name-based filtering as a last resort, for workspaces where
// no ID has been determined yet.
if (workspaceIter == mList.end()) {
auto name = object.value("name").toString();
workspaceIter = std::ranges::find_if(mList, [&](const HyprlandWorkspace* m) {
return m->id() == -1 && m->name() == name;
});
}
auto* workspace = workspaceIter == mList.end() ? nullptr : *workspaceIter; auto* workspace = workspaceIter == mList.end() ? nullptr : *workspaceIter;
auto existed = workspace != nullptr; auto existed = workspace != nullptr;
if (!existed) { if (workspace == nullptr) {
if (!canCreate) continue; if (!canCreate) continue;
workspace = new HyprlandWorkspace(this); workspace = new HyprlandWorkspace(this);
} }
@ -455,22 +428,20 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) {
this->mWorkspaces.insertObject(workspace); this->mWorkspaces.insertObject(workspace);
} }
ids.push_back(id); names.push_back(name);
} }
if (canCreate) { auto removedWorkspaces = QVector<HyprlandWorkspace*>();
auto removedWorkspaces = QVector<HyprlandWorkspace*>();
for (auto* workspace: mList) { for (auto* workspace: mList) {
if (!ids.contains(workspace->id())) { if (!names.contains(workspace->name())) {
removedWorkspaces.push_back(workspace); removedWorkspaces.push_back(workspace);
}
} }
}
for (auto* workspace: removedWorkspaces) { for (auto* workspace: removedWorkspaces) {
this->mWorkspaces.removeObject(workspace); this->mWorkspaces.removeObject(workspace);
delete workspace; delete workspace;
}
} }
}); });
} }

View file

@ -81,7 +81,7 @@ public:
[[nodiscard]] ObjectModel<HyprlandWorkspace>* workspaces(); [[nodiscard]] ObjectModel<HyprlandWorkspace>* workspaces();
// No byId because these preemptively create objects. The given id is set if created. // No byId because these preemptively create objects. The given id is set if created.
HyprlandWorkspace* findWorkspaceByName(const QString& name, bool createIfMissing, qint32 id = -1); HyprlandWorkspace* findWorkspaceByName(const QString& name, bool createIfMissing, qint32 id = 0);
HyprlandMonitor* findMonitorByName(const QString& name, bool createIfMissing, qint32 id = -1); HyprlandMonitor* findMonitorByName(const QString& name, bool createIfMissing, qint32 id = -1);
// canCreate avoids making ghost workspaces when the connection races // canCreate avoids making ghost workspaces when the connection races

View file

@ -117,8 +117,6 @@ void HyprlandMonitor::setActiveWorkspace(HyprlandWorkspace* workspace) {
this->mActiveWorkspace = workspace; this->mActiveWorkspace = workspace;
if (workspace != nullptr) { if (workspace != nullptr) {
workspace->setMonitor(this);
QObject::connect( QObject::connect(
workspace, workspace,
&QObject::destroyed, &QObject::destroyed,

View file

@ -35,22 +35,18 @@ void HyprlandWorkspace::updateInitial(qint32 id, QString name) {
} }
void HyprlandWorkspace::updateFromObject(QVariantMap object) { void HyprlandWorkspace::updateFromObject(QVariantMap object) {
auto id = object.value("id").value<qint32>();
auto name = object.value("name").value<QString>(); auto name = object.value("name").value<QString>();
auto monitorId = object.value("monitorID").value<qint32>(); auto monitorId = object.value("monitorID").value<qint32>();
auto monitorName = object.value("monitor").value<QString>(); auto monitorName = object.value("monitor").value<QString>();
auto initial = this->mId = -1; if (id != this->mId) {
this->mId = id;
// ID cannot be updated after creation
if (initial) {
this->mId = object.value("id").value<qint32>();
emit this->idChanged(); emit this->idChanged();
} }
// No events we currently handle give a workspace id but not a name, if (name != this->mName) {
// so we shouldn't set this if it isn't an initial query this->mName = std::move(name);
if (initial && name != this->mName) {
this->mName = name;
emit this->nameChanged(); emit this->nameChanged();
} }