i3/ipc: convert to bindable properties

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

View file

@ -1,6 +1,7 @@
#include "monitor.hpp"
#include <qcontainerfwd.h>
#include <qproperty.h>
#include <qstring.h>
#include <qtmetamacros.h>
#include <qtypes.h>
@ -9,45 +10,24 @@
namespace qs::i3::ipc {
qint32 I3Monitor::id() const { return this->mId; };
QString I3Monitor::name() const { return this->mName; };
bool I3Monitor::power() const { return this->mPower; };
I3Workspace* I3Monitor::focusedWorkspace() const { return this->mFocusedWorkspace; };
qint32 I3Monitor::x() const { return this->mX; };
qint32 I3Monitor::y() const { return this->mY; };
qint32 I3Monitor::width() const { return this->mWidth; };
qint32 I3Monitor::height() const { return this->mHeight; };
qreal I3Monitor::scale() const { return this->mScale; };
bool I3Monitor::focused() const { return this->mFocused; };
QVariantMap I3Monitor::lastIpcObject() const { return this->mLastIpcObject; };
void I3Monitor::updateFromObject(const QVariantMap& obj) {
auto id = obj.value("id").value<qint32>();
auto name = obj.value("name").value<QString>();
auto power = obj.value("power").value<bool>();
auto activeWorkspaceId = obj.value("current_workspace").value<QString>();
auto rect = obj.value("rect").toMap();
auto x = rect.value("x").value<qint32>();
auto y = rect.value("y").value<qint32>();
auto width = rect.value("width").value<qint32>();
auto height = rect.value("height").value<qint32>();
auto scale = obj.value("scale").value<qreal>();
auto focused = obj.value("focused").value<bool>();
if (id != this->mId) {
this->mId = id;
emit this->idChanged();
}
if (name != this->mName) {
this->mName = name;
emit this->nameChanged();
}
if (power != this->mPower) {
this->mPower = power;
this->powerChanged();
}
Qt::beginPropertyUpdateGroup();
this->bId = obj.value("id").value<qint32>();
this->bName = obj.value("name").value<QString>();
this->bPower = obj.value("power").value<bool>();
this->bX = rect.value("x").value<qint32>();
this->bY = rect.value("y").value<qint32>();
this->bWidth = rect.value("width").value<qint32>();
this->bHeight = rect.value("height").value<qint32>();
this->bScale = obj.value("scale").value<qreal>();
this->bFocused = obj.value("focused").value<bool>();
Qt::endPropertyUpdateGroup();
if (activeWorkspaceId != this->mFocusedWorkspaceName) {
auto* workspace = this->ipc->findWorkspaceByName(activeWorkspaceId);
@ -61,50 +41,15 @@ void I3Monitor::updateFromObject(const QVariantMap& obj) {
emit this->focusedWorkspaceChanged();
};
if (x != this->mX) {
this->mX = x;
emit this->xChanged();
}
if (y != this->mY) {
this->mY = y;
emit this->yChanged();
}
if (width != this->mWidth) {
this->mWidth = width;
emit this->widthChanged();
}
if (height != this->mHeight) {
this->mHeight = height;
emit this->heightChanged();
}
if (scale != this->mScale) {
this->mScale = scale;
emit this->scaleChanged();
}
if (focused != this->mFocused) {
this->mFocused = focused;
emit this->focusedChanged();
}
if (obj != this->mLastIpcObject) {
this->mLastIpcObject = obj;
emit this->lastIpcObjectChanged();
}
}
void I3Monitor::setFocus(bool focused) {
this->mFocused = focused;
emit this->focusedChanged();
}
void I3Monitor::setFocusedWorkspace(I3Workspace* workspace) {
this->mFocusedWorkspace = workspace;
this->mFocusedWorkspaceName = workspace->name();
this->mFocusedWorkspaceName = workspace->bindableName().value();
emit this->focusedWorkspaceChanged();
};