diff options
| author | outfoxxed <outfoxxed@outfoxxed.me> | 2025-06-26 09:32:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-26 18:32:44 +0200 |
| commit | 3bbdf9dc5ad2851f5d9f317362fc16705e4fd990 (patch) | |
| tree | 025d7a25435925b235f2e94d18e31931b622c0c0 /src/protocols/ExtWorkspace.hpp | |
| parent | 1f337a7a5e22ec45a77e275ce2e6ca165b298358 (diff) | |
protocols: add ext-workspace implementation (#10818)
Diffstat (limited to 'src/protocols/ExtWorkspace.hpp')
| -rw-r--r-- | src/protocols/ExtWorkspace.hpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/protocols/ExtWorkspace.hpp b/src/protocols/ExtWorkspace.hpp new file mode 100644 index 00000000..efaac3fe --- /dev/null +++ b/src/protocols/ExtWorkspace.hpp @@ -0,0 +1,117 @@ +#pragma once + +#include "WaylandProtocol.hpp" +#include "../desktop/DesktopTypes.hpp" +#include "ext-workspace-v1.hpp" +#include <cstdint> +#include <vector> +#include "../helpers/signal/Signal.hpp" +#include "../helpers/Monitor.hpp" + +class CExtWorkspaceManagerResource; + +class CExtWorkspaceGroupResource { + public: + CExtWorkspaceGroupResource(WP<CExtWorkspaceManagerResource> manager, UP<CExtWorkspaceGroupHandleV1> resource, PHLMONITORREF monitor); + + static WP<CExtWorkspaceGroupResource> fromResource(wl_resource*); + + [[nodiscard]] bool good() const; + + void workspaceEnter(const WP<CExtWorkspaceHandleV1>&); + void workspaceLeave(const WP<CExtWorkspaceHandleV1>&); + + PHLMONITORREF m_monitor; + + private: + WP<CExtWorkspaceGroupResource> m_self; + WP<CExtWorkspaceManagerResource> m_manager; + UP<CExtWorkspaceGroupHandleV1> m_resource; + + struct { + CHyprSignalListener destroyed; + CHyprSignalListener outputBound; + } m_listeners; + + friend class CExtWorkspaceManagerResource; +}; + +class CExtWorkspaceResource { + public: + CExtWorkspaceResource(WP<CExtWorkspaceManagerResource> manager, UP<CExtWorkspaceHandleV1> resource, PHLWORKSPACEREF workspace); + + [[nodiscard]] bool good() const; + + void commit(); + + private: + WP<CExtWorkspaceResource> m_self; + WP<CExtWorkspaceManagerResource> m_manager; + UP<CExtWorkspaceHandleV1> m_resource; + WP<CExtWorkspaceGroupResource> m_group; + PHLWORKSPACEREF m_workspace; + + [[nodiscard]] bool isActive() const; + + void sendState(); + void sendCapabilities(); + void sendGroup(); + + struct { + bool activate = false; + bool deactivate = false; + PHLMONITORREF targetMonitor; + } m_pendingState; + + struct { + CHyprSignalListener destroyed; + CHyprSignalListener activeChanged; + CHyprSignalListener monitorChanged; + CHyprSignalListener renamed; + } m_listeners; + + friend class CExtWorkspaceManagerResource; +}; + +class CExtWorkspaceManagerResource { + public: + CExtWorkspaceManagerResource(UP<CExtWorkspaceManagerV1> resource); + WP<CExtWorkspaceManagerResource> m_self; + + void init(WP<CExtWorkspaceManagerResource> self); + [[nodiscard]] bool good() const; + + void onMonitorCreated(const PHLMONITOR& monitor); + void onWorkspaceCreated(const PHLWORKSPACE& workspace); + + void scheduleDone(); + [[nodiscard]] WP<CExtWorkspaceGroupResource> findGroup(const PHLMONITORREF& monitor) const; + void sendGroupToWorkspaces(const WP<CExtWorkspaceGroupResource>& group); + + UP<CExtWorkspaceManagerV1> m_resource; + + private: + bool m_doneScheduled = false; +}; + +class CExtWorkspaceProtocol : public IWaylandProtocol { + public: + CExtWorkspaceProtocol(const wl_interface* iface, const int& var, const std::string& name); + + virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); + + void destroyManager(const WP<CExtWorkspaceManagerResource>& manager); + void destroyGroup(const WP<CExtWorkspaceGroupResource>& group); + void destroyWorkspace(const WP<CExtWorkspaceResource>& workspace); + + private: + std::vector<UP<CExtWorkspaceManagerResource>> m_managers; + std::vector<UP<CExtWorkspaceGroupResource>> m_groups; + std::vector<UP<CExtWorkspaceResource>> m_workspaces; + + friend class CExtWorkspaceManagerResource; +}; + +namespace PROTO { + inline UP<CExtWorkspaceProtocol> extWorkspace; +} |
