diff --git a/src/wayland/hyprland/ipc/connection.cpp b/src/wayland/hyprland/ipc/connection.cpp index 993f3bcf..29a9cf44 100644 --- a/src/wayland/hyprland/ipc/connection.cpp +++ b/src/wayland/hyprland/ipc/connection.cpp @@ -50,6 +50,11 @@ HyprlandIpc::HyprlandIpc() { return; } + this->bFocusedWorkspace.setBinding([this]() -> HyprlandWorkspace* { + if (!this->bFocusedMonitor) return nullptr; + return this->bFocusedMonitor->bindableActiveWorkspace().value(); + }); + this->mRequestSocketPath = hyprlandDir + "/.socket.sock"; this->mEventSocketPath = hyprlandDir + "/.socket2.sock"; diff --git a/src/wayland/hyprland/ipc/connection.hpp b/src/wayland/hyprland/ipc/connection.hpp index e7c981f4..b25643b1 100644 --- a/src/wayland/hyprland/ipc/connection.hpp +++ b/src/wayland/hyprland/ipc/connection.hpp @@ -81,6 +81,10 @@ public: return &this->bFocusedMonitor; } + [[nodiscard]] QBindable bindableFocusedWorkspace() const { + return &this->bFocusedWorkspace; + } + void setFocusedMonitor(HyprlandMonitor* monitor); [[nodiscard]] ObjectModel* monitors(); @@ -102,6 +106,7 @@ signals: void rawEvent(HyprlandIpcEvent* event); void focusedMonitorChanged(); + void focusedWorkspaceChanged(); private slots: void eventSocketError(QLocalSocket::LocalSocketError error) const; @@ -134,6 +139,13 @@ private: bFocusedMonitor, &HyprlandIpc::focusedMonitorChanged ); + + Q_OBJECT_BINDABLE_PROPERTY( + HyprlandIpc, + HyprlandWorkspace*, + bFocusedWorkspace, + &HyprlandIpc::focusedWorkspaceChanged + ); }; } // namespace qs::hyprland::ipc diff --git a/src/wayland/hyprland/ipc/qml.cpp b/src/wayland/hyprland/ipc/qml.cpp index 35bf4eab..a497ab35 100644 --- a/src/wayland/hyprland/ipc/qml.cpp +++ b/src/wayland/hyprland/ipc/qml.cpp @@ -1,6 +1,7 @@ #include "qml.hpp" #include +#include #include "../../../core/model.hpp" #include "../../../core/qmlscreen.hpp" @@ -13,6 +14,14 @@ HyprlandIpcQml::HyprlandIpcQml() { auto* instance = HyprlandIpc::instance(); QObject::connect(instance, &HyprlandIpc::rawEvent, this, &HyprlandIpcQml::rawEvent); + + QObject::connect( + instance, + &HyprlandIpc::focusedMonitorChanged, + this, + &HyprlandIpcQml::focusedMonitorChanged + ); + QObject::connect( instance, &HyprlandIpc::focusedMonitorChanged, @@ -30,15 +39,16 @@ HyprlandMonitor* HyprlandIpcQml::monitorFor(QuickshellScreenInfo* screen) { } void HyprlandIpcQml::refreshMonitors() { HyprlandIpc::instance()->refreshMonitors(false); } - void HyprlandIpcQml::refreshWorkspaces() { HyprlandIpc::instance()->refreshWorkspaces(false); } - QString HyprlandIpcQml::requestSocketPath() { return HyprlandIpc::instance()->requestSocketPath(); } - QString HyprlandIpcQml::eventSocketPath() { return HyprlandIpc::instance()->eventSocketPath(); } -HyprlandMonitor* HyprlandIpcQml::focusedMonitor() { - return HyprlandIpc::instance()->bindableFocusedMonitor().value(); +QBindable HyprlandIpcQml::bindableFocusedMonitor() { + return HyprlandIpc::instance()->bindableFocusedMonitor(); +} + +QBindable HyprlandIpcQml::bindableFocusedWorkspace() { + return HyprlandIpc::instance()->bindableFocusedWorkspace(); } ObjectModel* HyprlandIpcQml::monitors() { diff --git a/src/wayland/hyprland/ipc/qml.hpp b/src/wayland/hyprland/ipc/qml.hpp index 1fc93c38..bab90602 100644 --- a/src/wayland/hyprland/ipc/qml.hpp +++ b/src/wayland/hyprland/ipc/qml.hpp @@ -21,7 +21,9 @@ class HyprlandIpcQml: public QObject { /// Path to the event socket (.socket2.sock) Q_PROPERTY(QString eventSocketPath READ eventSocketPath CONSTANT); /// 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. QSDOC_TYPE_OVERRIDE(ObjectModel*); Q_PROPERTY(UntypedObjectModel* monitors READ monitors CONSTANT); @@ -55,7 +57,8 @@ public: [[nodiscard]] static QString requestSocketPath(); [[nodiscard]] static QString eventSocketPath(); - [[nodiscard]] static HyprlandMonitor* focusedMonitor(); + [[nodiscard]] static QBindable bindableFocusedMonitor(); + [[nodiscard]] static QBindable bindableFocusedWorkspace(); [[nodiscard]] static ObjectModel* monitors(); [[nodiscard]] static ObjectModel* workspaces(); @@ -66,6 +69,7 @@ signals: void rawEvent(qs::hyprland::ipc::HyprlandIpcEvent* event); void focusedMonitorChanged(); + void focusedWorkspaceChanged(); }; } // namespace qs::hyprland::ipc diff --git a/src/wayland/hyprland/ipc/workspace.cpp b/src/wayland/hyprland/ipc/workspace.cpp index 3aefdde0..d8f00e3d 100644 --- a/src/wayland/hyprland/ipc/workspace.cpp +++ b/src/wayland/hyprland/ipc/workspace.cpp @@ -22,7 +22,7 @@ HyprlandWorkspace::HyprlandWorkspace(HyprlandIpc* ipc): QObject(ipc), ipc(ipc) { }); this->bFocused.setBinding([this]() { - return this->bActive.value() && this->bMonitor->bindableFocused().value(); + return this->ipc->bindableFocusedWorkspace().value() == this; }); Qt::endPropertyUpdateGroup();