summaryrefslogtreecommitdiff
path: root/src/protocols
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-05-05 01:07:46 +0100
committerVaxry <vaxry@vaxry.net>2024-05-05 02:00:55 +0100
commit62eadad20fe10ffaf13d9c65ee68608996d93df0 (patch)
tree2a258a4d8e249c3bd2c511e409c23518d916b3f6 /src/protocols
parent0b215c5f246d3fde6c023e78b3e3579f7498c172 (diff)
kde-server-decoration: move to new impl
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/ServerDecorationKDE.cpp53
-rw-r--r--src/protocols/ServerDecorationKDE.hpp40
2 files changed, 93 insertions, 0 deletions
diff --git a/src/protocols/ServerDecorationKDE.cpp b/src/protocols/ServerDecorationKDE.cpp
new file mode 100644
index 00000000..8d0e423b
--- /dev/null
+++ b/src/protocols/ServerDecorationKDE.cpp
@@ -0,0 +1,53 @@
+#include "ServerDecorationKDE.hpp"
+
+#define LOGM PROTO::serverDecorationKDE->protoLog
+
+CServerDecorationKDE::CServerDecorationKDE(SP<COrgKdeKwinServerDecoration> resource_, wlr_surface* surf) : resource(resource_) {
+ if (!good())
+ return;
+
+ resource->setRelease([this](COrgKdeKwinServerDecoration* pMgr) { PROTO::serverDecorationKDE->destroyResource(this); });
+ resource->setOnDestroy([this](COrgKdeKwinServerDecoration* pMgr) { PROTO::serverDecorationKDE->destroyResource(this); });
+
+ // we send this and ignore request_mode.
+ resource->sendMode(ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER);
+}
+
+bool CServerDecorationKDE::good() {
+ return resource->resource();
+}
+
+CServerDecorationKDEProtocol::CServerDecorationKDEProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
+ ;
+}
+
+void CServerDecorationKDEProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
+ const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<COrgKdeKwinServerDecorationManager>(client, ver, id)).get();
+ RESOURCE->setOnDestroy([this](COrgKdeKwinServerDecorationManager* p) { this->onManagerResourceDestroy(p->resource()); });
+
+ RESOURCE->setCreate([this](COrgKdeKwinServerDecorationManager* pMgr, uint32_t id, wl_resource* pointer) { this->createDecoration(pMgr, id, pointer); });
+
+ // send default mode of SSD, as Hyprland will never ask for CSD. Screw Gnome and GTK.
+ RESOURCE->sendDefaultMode(ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER);
+}
+
+void CServerDecorationKDEProtocol::onManagerResourceDestroy(wl_resource* res) {
+ std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
+}
+
+void CServerDecorationKDEProtocol::destroyResource(CServerDecorationKDE* hayperlaaaand) {
+ std::erase_if(m_vDecos, [&](const auto& other) { return other.get() == hayperlaaaand; });
+}
+
+void CServerDecorationKDEProtocol::createDecoration(COrgKdeKwinServerDecorationManager* pMgr, uint32_t id, wl_resource* surf) {
+ const auto CLIENT = pMgr->client();
+ const auto RESOURCE =
+ m_vDecos.emplace_back(std::make_unique<CServerDecorationKDE>(std::make_shared<COrgKdeKwinServerDecoration>(CLIENT, pMgr->version(), id), wlr_surface_from_resource(surf)))
+ .get();
+
+ if (!RESOURCE->good()) {
+ pMgr->noMemory();
+ m_vDecos.pop_back();
+ return;
+ }
+}
diff --git a/src/protocols/ServerDecorationKDE.hpp b/src/protocols/ServerDecorationKDE.hpp
new file mode 100644
index 00000000..ec7a852f
--- /dev/null
+++ b/src/protocols/ServerDecorationKDE.hpp
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <memory>
+#include <vector>
+#include <cstdint>
+#include "WaylandProtocol.hpp"
+#include "kde-server-decoration.hpp"
+
+class CServerDecorationKDE {
+ public:
+ CServerDecorationKDE(SP<COrgKdeKwinServerDecoration> resource_, wlr_surface* surf);
+
+ bool good();
+
+ private:
+ SP<COrgKdeKwinServerDecoration> resource;
+};
+
+class CServerDecorationKDEProtocol : public IWaylandProtocol {
+ public:
+ CServerDecorationKDEProtocol(const wl_interface* iface, const int& ver, const std::string& name);
+
+ virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
+
+ private:
+ void onManagerResourceDestroy(wl_resource* res);
+ void destroyResource(CServerDecorationKDE* deco);
+
+ void createDecoration(COrgKdeKwinServerDecorationManager* pMgr, uint32_t id, wl_resource* surf);
+
+ //
+ std::vector<UP<COrgKdeKwinServerDecorationManager>> m_vManagers;
+ std::vector<UP<CServerDecorationKDE>> m_vDecos;
+
+ friend class CServerDecorationKDE;
+};
+
+namespace PROTO {
+ inline UP<CServerDecorationKDEProtocol> serverDecorationKDE;
+};