hyprland/ipc: convert to bindable properties

This commit is contained in:
outfoxxed 2025-03-21 02:46:09 -07:00
parent eabf79ebb6
commit 3b2d84caf0
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 105 additions and 160 deletions

View file

@ -3,6 +3,7 @@
#include <qbytearrayview.h>
#include <qcontainerfwd.h>
#include <qobject.h>
#include <qproperty.h>
#include <qqmlintegration.h>
#include <qtmetamacros.h>
#include <qtypes.h>
@ -14,14 +15,14 @@ namespace qs::hyprland::ipc {
class HyprlandMonitor: public QObject {
Q_OBJECT;
// clang-format off
Q_PROPERTY(qint32 id READ id NOTIFY idChanged);
Q_PROPERTY(QString name READ name NOTIFY nameChanged);
Q_PROPERTY(QString description READ description NOTIFY descriptionChanged);
Q_PROPERTY(qint32 x READ x NOTIFY xChanged);
Q_PROPERTY(qint32 y READ y NOTIFY yChanged);
Q_PROPERTY(qint32 width READ width NOTIFY widthChanged);
Q_PROPERTY(qint32 height READ height NOTIFY heightChanged);
Q_PROPERTY(qreal scale READ scale NOTIFY scaleChanged);
Q_PROPERTY(qint32 id READ default NOTIFY idChanged BINDABLE bindableId);
Q_PROPERTY(QString name READ default NOTIFY nameChanged BINDABLE bindableName);
Q_PROPERTY(QString description READ default NOTIFY descriptionChanged BINDABLE bindableDescription);
Q_PROPERTY(qint32 x READ default NOTIFY xChanged BINDABLE bindableX);
Q_PROPERTY(qint32 y READ default NOTIFY yChanged BINDABLE bindableY);
Q_PROPERTY(qint32 width READ default NOTIFY widthChanged BINDABLE bindableWidth);
Q_PROPERTY(qint32 height READ default NOTIFY heightChanged BINDABLE bindableHeight);
Q_PROPERTY(qreal scale READ default NOTIFY scaleChanged BINDABLE bindableScale);
/// Last json returned for this monitor, as a javascript object.
///
/// > [!WARNING] This is *not* updated unless the monitor object is fetched again from
@ -37,17 +38,18 @@ class HyprlandMonitor: public QObject {
public:
explicit HyprlandMonitor(HyprlandIpc* ipc): QObject(ipc), ipc(ipc) {}
void updateInitial(qint32 id, QString name, QString description);
void updateInitial(qint32 id, const QString& name, const QString& description);
void updateFromObject(QVariantMap object);
[[nodiscard]] qint32 id() const;
[[nodiscard]] QString name() const;
[[nodiscard]] QString description() const;
[[nodiscard]] qint32 x() const;
[[nodiscard]] qint32 y() const;
[[nodiscard]] qint32 width() const;
[[nodiscard]] qint32 height() const;
[[nodiscard]] qreal scale() const;
[[nodiscard]] QBindable<qint32> bindableId() { return &this->bId; }
[[nodiscard]] QBindable<QString> bindableName() { return &this->bName; }
[[nodiscard]] QBindable<QString> bindableDescription() { return &this->bDescription; }
[[nodiscard]] QBindable<qint32> bindableX() { return &this->bX; }
[[nodiscard]] QBindable<qint32> bindableY() { return &this->bY; }
[[nodiscard]] QBindable<qint32> bindableWidth() { return &this->bWidth; }
[[nodiscard]] QBindable<qint32> bindableHeight() { return &this->bHeight; }
[[nodiscard]] QBindable<qreal> bindableScale() { return &this->bScale; }
[[nodiscard]] QVariantMap lastIpcObject() const;
void setActiveWorkspace(HyprlandWorkspace* workspace);
@ -71,17 +73,19 @@ private slots:
private:
HyprlandIpc* ipc;
qint32 mId = -1;
QString mName;
QString mDescription;
qint32 mX = 0;
qint32 mY = 0;
qint32 mWidth = 0;
qint32 mHeight = 0;
qreal mScale = 0;
QVariantMap mLastIpcObject;
HyprlandWorkspace* mActiveWorkspace = nullptr;
// clang-format off
Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(HyprlandMonitor, qint32, bId, -1, &HyprlandMonitor::idChanged);
Q_OBJECT_BINDABLE_PROPERTY(HyprlandMonitor, QString, bName, &HyprlandMonitor::nameChanged);
Q_OBJECT_BINDABLE_PROPERTY(HyprlandMonitor, QString, bDescription, &HyprlandMonitor::descriptionChanged);
Q_OBJECT_BINDABLE_PROPERTY(HyprlandMonitor, qint32, bX, &HyprlandMonitor::xChanged);
Q_OBJECT_BINDABLE_PROPERTY(HyprlandMonitor, qint32, bY, &HyprlandMonitor::yChanged);
Q_OBJECT_BINDABLE_PROPERTY(HyprlandMonitor, qint32, bWidth, &HyprlandMonitor::widthChanged);
Q_OBJECT_BINDABLE_PROPERTY(HyprlandMonitor, qint32, bHeight, &HyprlandMonitor::heightChanged);
Q_OBJECT_BINDABLE_PROPERTY(HyprlandMonitor, qreal, bScale, &HyprlandMonitor::scaleChanged);
// clang-format on
};
} // namespace qs::hyprland::ipc