From 3bbdf9dc5ad2851f5d9f317362fc16705e4fd990 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 26 Jun 2025 09:32:44 -0700 Subject: protocols: add ext-workspace implementation (#10818) --- src/protocols/ExtWorkspace.hpp | 117 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/protocols/ExtWorkspace.hpp (limited to 'src/protocols/ExtWorkspace.hpp') 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 +#include +#include "../helpers/signal/Signal.hpp" +#include "../helpers/Monitor.hpp" + +class CExtWorkspaceManagerResource; + +class CExtWorkspaceGroupResource { + public: + CExtWorkspaceGroupResource(WP manager, UP resource, PHLMONITORREF monitor); + + static WP fromResource(wl_resource*); + + [[nodiscard]] bool good() const; + + void workspaceEnter(const WP&); + void workspaceLeave(const WP&); + + PHLMONITORREF m_monitor; + + private: + WP m_self; + WP m_manager; + UP m_resource; + + struct { + CHyprSignalListener destroyed; + CHyprSignalListener outputBound; + } m_listeners; + + friend class CExtWorkspaceManagerResource; +}; + +class CExtWorkspaceResource { + public: + CExtWorkspaceResource(WP manager, UP resource, PHLWORKSPACEREF workspace); + + [[nodiscard]] bool good() const; + + void commit(); + + private: + WP m_self; + WP m_manager; + UP m_resource; + WP 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 resource); + WP m_self; + + void init(WP self); + [[nodiscard]] bool good() const; + + void onMonitorCreated(const PHLMONITOR& monitor); + void onWorkspaceCreated(const PHLWORKSPACE& workspace); + + void scheduleDone(); + [[nodiscard]] WP findGroup(const PHLMONITORREF& monitor) const; + void sendGroupToWorkspaces(const WP& group); + + UP 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& manager); + void destroyGroup(const WP& group); + void destroyWorkspace(const WP& workspace); + + private: + std::vector> m_managers; + std::vector> m_groups; + std::vector> m_workspaces; + + friend class CExtWorkspaceManagerResource; +}; + +namespace PROTO { + inline UP extWorkspace; +} -- cgit v1.2.3