hyprland/ipc: further cleanup + add Hyprland.focusedWorkspace

This commit is contained in:
outfoxxed 2025-03-27 00:25:21 -07:00
parent 67b2682604
commit 392f56c40e
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 39 additions and 8 deletions

View file

@ -50,6 +50,11 @@ HyprlandIpc::HyprlandIpc() {
return; return;
} }
this->bFocusedWorkspace.setBinding([this]() -> HyprlandWorkspace* {
if (!this->bFocusedMonitor) return nullptr;
return this->bFocusedMonitor->bindableActiveWorkspace().value();
});
this->mRequestSocketPath = hyprlandDir + "/.socket.sock"; this->mRequestSocketPath = hyprlandDir + "/.socket.sock";
this->mEventSocketPath = hyprlandDir + "/.socket2.sock"; this->mEventSocketPath = hyprlandDir + "/.socket2.sock";

View file

@ -81,6 +81,10 @@ public:
return &this->bFocusedMonitor; return &this->bFocusedMonitor;
} }
[[nodiscard]] QBindable<HyprlandWorkspace*> bindableFocusedWorkspace() const {
return &this->bFocusedWorkspace;
}
void setFocusedMonitor(HyprlandMonitor* monitor); void setFocusedMonitor(HyprlandMonitor* monitor);
[[nodiscard]] ObjectModel<HyprlandMonitor>* monitors(); [[nodiscard]] ObjectModel<HyprlandMonitor>* monitors();
@ -102,6 +106,7 @@ signals:
void rawEvent(HyprlandIpcEvent* event); void rawEvent(HyprlandIpcEvent* event);
void focusedMonitorChanged(); void focusedMonitorChanged();
void focusedWorkspaceChanged();
private slots: private slots:
void eventSocketError(QLocalSocket::LocalSocketError error) const; void eventSocketError(QLocalSocket::LocalSocketError error) const;
@ -134,6 +139,13 @@ private:
bFocusedMonitor, bFocusedMonitor,
&HyprlandIpc::focusedMonitorChanged &HyprlandIpc::focusedMonitorChanged
); );
Q_OBJECT_BINDABLE_PROPERTY(
HyprlandIpc,
HyprlandWorkspace*,
bFocusedWorkspace,
&HyprlandIpc::focusedWorkspaceChanged
);
}; };
} // namespace qs::hyprland::ipc } // namespace qs::hyprland::ipc

View file

@ -1,6 +1,7 @@
#include "qml.hpp" #include "qml.hpp"
#include <qobject.h> #include <qobject.h>
#include <qproperty.h>
#include "../../../core/model.hpp" #include "../../../core/model.hpp"
#include "../../../core/qmlscreen.hpp" #include "../../../core/qmlscreen.hpp"
@ -13,6 +14,14 @@ HyprlandIpcQml::HyprlandIpcQml() {
auto* instance = HyprlandIpc::instance(); auto* instance = HyprlandIpc::instance();
QObject::connect(instance, &HyprlandIpc::rawEvent, this, &HyprlandIpcQml::rawEvent); QObject::connect(instance, &HyprlandIpc::rawEvent, this, &HyprlandIpcQml::rawEvent);
QObject::connect(
instance,
&HyprlandIpc::focusedMonitorChanged,
this,
&HyprlandIpcQml::focusedMonitorChanged
);
QObject::connect( QObject::connect(
instance, instance,
&HyprlandIpc::focusedMonitorChanged, &HyprlandIpc::focusedMonitorChanged,
@ -30,15 +39,16 @@ HyprlandMonitor* HyprlandIpcQml::monitorFor(QuickshellScreenInfo* screen) {
} }
void HyprlandIpcQml::refreshMonitors() { HyprlandIpc::instance()->refreshMonitors(false); } void HyprlandIpcQml::refreshMonitors() { HyprlandIpc::instance()->refreshMonitors(false); }
void HyprlandIpcQml::refreshWorkspaces() { HyprlandIpc::instance()->refreshWorkspaces(false); } void HyprlandIpcQml::refreshWorkspaces() { HyprlandIpc::instance()->refreshWorkspaces(false); }
QString HyprlandIpcQml::requestSocketPath() { return HyprlandIpc::instance()->requestSocketPath(); } QString HyprlandIpcQml::requestSocketPath() { return HyprlandIpc::instance()->requestSocketPath(); }
QString HyprlandIpcQml::eventSocketPath() { return HyprlandIpc::instance()->eventSocketPath(); } QString HyprlandIpcQml::eventSocketPath() { return HyprlandIpc::instance()->eventSocketPath(); }
HyprlandMonitor* HyprlandIpcQml::focusedMonitor() { QBindable<HyprlandMonitor*> HyprlandIpcQml::bindableFocusedMonitor() {
return HyprlandIpc::instance()->bindableFocusedMonitor().value(); return HyprlandIpc::instance()->bindableFocusedMonitor();
}
QBindable<HyprlandWorkspace*> HyprlandIpcQml::bindableFocusedWorkspace() {
return HyprlandIpc::instance()->bindableFocusedWorkspace();
} }
ObjectModel<HyprlandMonitor>* HyprlandIpcQml::monitors() { ObjectModel<HyprlandMonitor>* HyprlandIpcQml::monitors() {

View file

@ -21,7 +21,9 @@ class HyprlandIpcQml: public QObject {
/// Path to the event socket (.socket2.sock) /// Path to the event socket (.socket2.sock)
Q_PROPERTY(QString eventSocketPath READ eventSocketPath CONSTANT); Q_PROPERTY(QString eventSocketPath READ eventSocketPath CONSTANT);
/// The currently focused hyprland monitor. May be null. /// The currently focused hyprland monitor. May be null.
Q_PROPERTY(qs::hyprland::ipc::HyprlandMonitor* focusedMonitor READ focusedMonitor NOTIFY focusedMonitorChanged); Q_PROPERTY(qs::hyprland::ipc::HyprlandMonitor* focusedMonitor READ default NOTIFY focusedMonitorChanged BINDABLE bindableFocusedMonitor);
/// The currently focused hyprland workspace. May be null.
Q_PROPERTY(qs::hyprland::ipc::HyprlandWorkspace* focusedWorkspace READ default NOTIFY focusedWorkspaceChanged BINDABLE bindableFocusedWorkspace);
/// All hyprland monitors. /// All hyprland monitors.
QSDOC_TYPE_OVERRIDE(ObjectModel<qs::hyprland::ipc::HyprlandMonitor>*); QSDOC_TYPE_OVERRIDE(ObjectModel<qs::hyprland::ipc::HyprlandMonitor>*);
Q_PROPERTY(UntypedObjectModel* monitors READ monitors CONSTANT); Q_PROPERTY(UntypedObjectModel* monitors READ monitors CONSTANT);
@ -55,7 +57,8 @@ public:
[[nodiscard]] static QString requestSocketPath(); [[nodiscard]] static QString requestSocketPath();
[[nodiscard]] static QString eventSocketPath(); [[nodiscard]] static QString eventSocketPath();
[[nodiscard]] static HyprlandMonitor* focusedMonitor(); [[nodiscard]] static QBindable<HyprlandMonitor*> bindableFocusedMonitor();
[[nodiscard]] static QBindable<HyprlandWorkspace*> bindableFocusedWorkspace();
[[nodiscard]] static ObjectModel<HyprlandMonitor>* monitors(); [[nodiscard]] static ObjectModel<HyprlandMonitor>* monitors();
[[nodiscard]] static ObjectModel<HyprlandWorkspace>* workspaces(); [[nodiscard]] static ObjectModel<HyprlandWorkspace>* workspaces();
@ -66,6 +69,7 @@ signals:
void rawEvent(qs::hyprland::ipc::HyprlandIpcEvent* event); void rawEvent(qs::hyprland::ipc::HyprlandIpcEvent* event);
void focusedMonitorChanged(); void focusedMonitorChanged();
void focusedWorkspaceChanged();
}; };
} // namespace qs::hyprland::ipc } // namespace qs::hyprland::ipc

View file

@ -22,7 +22,7 @@ HyprlandWorkspace::HyprlandWorkspace(HyprlandIpc* ipc): QObject(ipc), ipc(ipc) {
}); });
this->bFocused.setBinding([this]() { this->bFocused.setBinding([this]() {
return this->bActive.value() && this->bMonitor->bindableFocused().value(); return this->ipc->bindableFocusedWorkspace().value() == this;
}); });
Qt::endPropertyUpdateGroup(); Qt::endPropertyUpdateGroup();