i3/ipc: general cleanup + add active property

Brings the I3 ipc interface inline with the Hyprland one.
This commit is contained in:
outfoxxed 2025-03-27 00:05:05 -07:00
parent 8f11d60999
commit 67b2682604
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
8 changed files with 153 additions and 135 deletions

View file

@ -1,45 +1,62 @@
#include "workspace.hpp"
#include <qcontainerfwd.h>
#include <qobject.h>
#include <qproperty.h>
#include <qstring.h>
#include <qtmetamacros.h>
#include <qtypes.h>
#include "connection.hpp"
#include "monitor.hpp"
namespace qs::i3::ipc {
I3Monitor* I3Workspace::monitor() const { return this->mMonitor; }
I3Workspace::I3Workspace(I3Ipc* ipc): QObject(ipc), ipc(ipc) {
Qt::beginPropertyUpdateGroup();
this->bActive.setBinding([this]() {
return this->bMonitor.value() && this->bMonitor->bindableActiveWorkspace().value() == this;
});
this->bFocused.setBinding([this]() {
return this->ipc->bindableFocusedWorkspace().value() == this;
});
Qt::endPropertyUpdateGroup();
}
QVariantMap I3Workspace::lastIpcObject() const { return this->mLastIpcObject; }
void I3Workspace::updateFromObject(const QVariantMap& obj) {
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 (obj != this->mLastIpcObject) {
this->mLastIpcObject = obj;
emit this->lastIpcObjectChanged();
}
if (monitorName != this->mMonitorName) {
Qt::beginPropertyUpdateGroup();
this->bId = obj.value("id").value<qint32>();
this->bName = obj.value("name").value<QString>();
this->bNumber = obj.value("num").value<qint32>();
this->bUrgent = obj.value("urgent").value<bool>();
auto monitorName = obj.value("output").value<QString>();
if (!this->bMonitor || monitorName != this->bMonitor->bindableName().value()) {
auto* monitor = this->ipc->findMonitorByName(monitorName);
if (monitorName.isEmpty() || monitor == nullptr) { // is null when output is disabled
this->mMonitor = nullptr;
this->mMonitorName = "";
this->bMonitor = nullptr;
} else {
this->mMonitorName = monitorName;
this->mMonitor = monitor;
this->bMonitor = monitor;
}
emit this->monitorChanged();
}
Qt::endPropertyUpdateGroup();
}
void I3Workspace::activate() {
this->ipc->dispatch(QString("workspace number %1").arg(this->bNumber.value()));
}
} // namespace qs::i3::ipc