hyprland/ipc: convert to bindable properties

This commit is contained in:
outfoxxed 2025-03-21 02:46:09 -07:00
parent eabf79ebb6
commit 3b2d84caf0
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
5 changed files with 105 additions and 160 deletions

View file

@ -3,6 +3,7 @@
#include <qcontainerfwd.h>
#include <qobject.h>
#include <qproperty.h>
#include <qtmetamacros.h>
#include <qtypes.h>
@ -10,52 +11,34 @@
namespace qs::hyprland::ipc {
qint32 HyprlandWorkspace::id() const { return this->mId; }
QString HyprlandWorkspace::name() const { return this->mName; }
void HyprlandWorkspace::setName(QString name) {
if (name == this->mName) return;
this->mName = std::move(name);
emit this->nameChanged();
}
QVariantMap HyprlandWorkspace::lastIpcObject() const { return this->mLastIpcObject; }
void HyprlandWorkspace::updateInitial(qint32 id, QString name) {
if (id != this->mId) {
this->mId = id;
emit this->idChanged();
}
if (name != this->mName) {
this->mName = std::move(name);
emit this->nameChanged();
}
void HyprlandWorkspace::updateInitial(qint32 id, const QString& name) {
Qt::beginPropertyUpdateGroup();
this->bId = id;
this->bName = name;
Qt::endPropertyUpdateGroup();
}
void HyprlandWorkspace::updateFromObject(QVariantMap object) {
auto name = object.value("name").value<QString>();
auto monitorId = object.value("monitorID").value<qint32>();
auto monitorName = object.value("monitor").value<QString>();
auto initial = this->mId = -1;
auto initial = this->bId == -1;
// ID cannot be updated after creation
if (initial) {
this->mId = object.value("id").value<qint32>();
emit this->idChanged();
this->bId = object.value("id").value<qint32>();
}
// No events we currently handle give a workspace id but not a name,
// so we shouldn't set this if it isn't an initial query
if (initial && name != this->mName) {
this->mName = name;
emit this->nameChanged();
if (initial) {
this->bName = object.value("name").value<QString>();
}
if (!monitorName.isEmpty()
&& (this->mMonitor == nullptr || this->mMonitor->name() != monitorName))
&& (this->mMonitor == nullptr || this->mMonitor->bindableName().value() != monitorName))
{
auto* monitor = this->ipc->findMonitorByName(monitorName, true, monitorId);
this->setMonitor(monitor);