i3/ipc: convert to bindable properties

This commit is contained in:
outfoxxed 2025-03-21 02:46:47 -07:00
parent 3b2d84caf0
commit 1a20c39fba
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 96 additions and 170 deletions

View file

@ -1,6 +1,7 @@
#include "workspace.hpp"
#include <qcontainerfwd.h>
#include <qproperty.h>
#include <qstring.h>
#include <qtmetamacros.h>
#include <qtypes.h>
@ -9,47 +10,20 @@
namespace qs::i3::ipc {
qint32 I3Workspace ::id() const { return this->mId; }
QString I3Workspace::name() const { return this->mName; }
qint32 I3Workspace ::num() const { return this->mNum; }
bool I3Workspace ::urgent() const { return this->mUrgent; }
bool I3Workspace::focused() const { return this->mFocused; }
I3Monitor* I3Workspace::monitor() const { return this->mMonitor; }
QVariantMap I3Workspace::lastIpcObject() const { return this->mLastIpcObject; }
void I3Workspace::updateFromObject(const QVariantMap& obj) {
auto id = obj.value("id").value<qint32>();
auto name = obj.value("name").value<QString>();
auto num = obj.value("num").value<qint32>();
auto urgent = obj.value("urgent").value<bool>();
auto focused = obj.value("focused").value<bool>();
Qt::beginPropertyUpdateGroup();
this->bId = obj.value("id").value<qint32>();
this->bName = obj.value("name").value<QString>();
this->bNum = obj.value("num").value<qint32>();
this->bUrgent = obj.value("urgent").value<bool>();
this->bFocused = obj.value("focused").value<bool>();
Qt::endPropertyUpdateGroup();
auto monitorName = obj.value("output").value<QString>();
if (id != this->mId) {
this->mId = id;
emit this->idChanged();
}
if (name != this->mName) {
this->mName = name;
emit this->nameChanged();
}
if (num != this->mNum) {
this->mNum = num;
emit this->numChanged();
}
if (urgent != this->mUrgent) {
this->mUrgent = urgent;
emit this->urgentChanged();
}
if (focused != this->mFocused) {
this->mFocused = focused;
emit this->focusedChanged();
}
if (obj != this->mLastIpcObject) {
this->mLastIpcObject = obj;
emit this->lastIpcObjectChanged();
@ -68,6 +42,4 @@ void I3Workspace::updateFromObject(const QVariantMap& obj) {
}
}
void I3Workspace::setFocus(bool focus) { this->mFocused = focus; }
} // namespace qs::i3::ipc