summaryrefslogtreecommitdiff
path: root/src/protocols
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-04-21 22:22:06 +0100
committerVaxry <vaxry@vaxry.net>2025-04-21 22:30:27 +0100
commita4f7d7c594c70408f299ec8b794211c534709eaa (patch)
tree1365c77e4789f054550876a1720b2aa890271f04 /src/protocols
parent55e953b383f6b658b20ede1fea7772d2a88e7c65 (diff)
protocols: add xdg_toplevel_tag_v1 support
Adds a new windowrule to target windows by xdgTag, xdgtag:
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/XDGShell.hpp2
-rw-r--r--src/protocols/XDGTag.cpp54
-rw-r--r--src/protocols/XDGTag.hpp36
3 files changed, 92 insertions, 0 deletions
diff --git a/src/protocols/XDGShell.hpp b/src/protocols/XDGShell.hpp
index b46e0236..12f76774 100644
--- a/src/protocols/XDGShell.hpp
+++ b/src/protocols/XDGShell.hpp
@@ -141,6 +141,8 @@ class CXDGToplevelResource {
WP<CXDGToplevelResource> parent;
WP<CXDGDialogV1Resource> dialog;
+ std::optional<std::string> m_toplevelTag, m_toplevelDescription;
+
bool anyChildModal();
std::vector<WP<CXDGToplevelResource>> children;
diff --git a/src/protocols/XDGTag.cpp b/src/protocols/XDGTag.cpp
new file mode 100644
index 00000000..9176882e
--- /dev/null
+++ b/src/protocols/XDGTag.cpp
@@ -0,0 +1,54 @@
+#include "XDGTag.hpp"
+#include "XDGShell.hpp"
+
+CXDGToplevelTagManagerResource::CXDGToplevelTagManagerResource(UP<CXdgToplevelTagManagerV1>&& resource) : m_resource(std::move(resource)) {
+ if UNLIKELY (!good())
+ return;
+
+ m_resource->setDestroy([this](CXdgToplevelTagManagerV1* r) { PROTO::xdgTag->destroyResource(this); });
+ m_resource->setOnDestroy([this](CXdgToplevelTagManagerV1* r) { PROTO::xdgTag->destroyResource(this); });
+
+ resource->setSetToplevelTag([](CXdgToplevelTagManagerV1* r, wl_resource* toplevel, const char* tag) {
+ auto TOPLEVEL = CXDGToplevelResource::fromResource(toplevel);
+
+ if (!TOPLEVEL) {
+ r->error(-1, "Invalid toplevel handle");
+ return;
+ }
+
+ TOPLEVEL->m_toplevelTag = tag;
+ });
+
+ resource->setSetToplevelDescription([](CXdgToplevelTagManagerV1* r, wl_resource* toplevel, const char* description) {
+ auto TOPLEVEL = CXDGToplevelResource::fromResource(toplevel);
+
+ if (!TOPLEVEL) {
+ r->error(-1, "Invalid toplevel handle");
+ return;
+ }
+
+ TOPLEVEL->m_toplevelDescription = description;
+ });
+}
+
+bool CXDGToplevelTagManagerResource::good() {
+ return m_resource->resource();
+}
+
+CXDGToplevelTagProtocol::CXDGToplevelTagProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
+ ;
+}
+
+void CXDGToplevelTagProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
+ const auto RESOURCE =
+ WP<CXDGToplevelTagManagerResource>{m_vManagers.emplace_back(makeUnique<CXDGToplevelTagManagerResource>(makeUnique<CXdgToplevelTagManagerV1>(client, ver, id)))};
+
+ if UNLIKELY (!RESOURCE->good()) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+}
+
+void CXDGToplevelTagProtocol::destroyResource(CXDGToplevelTagManagerResource* res) {
+ std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == res; });
+}
diff --git a/src/protocols/XDGTag.hpp b/src/protocols/XDGTag.hpp
new file mode 100644
index 00000000..cff4da03
--- /dev/null
+++ b/src/protocols/XDGTag.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <vector>
+#include "WaylandProtocol.hpp"
+#include "xdg-toplevel-tag-v1.hpp"
+
+class CXDGToplevelResource;
+
+class CXDGToplevelTagManagerResource {
+ public:
+ CXDGToplevelTagManagerResource(UP<CXdgToplevelTagManagerV1>&& resource);
+
+ bool good();
+
+ private:
+ UP<CXdgToplevelTagManagerV1> m_resource;
+};
+
+class CXDGToplevelTagProtocol : public IWaylandProtocol {
+ public:
+ CXDGToplevelTagProtocol(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 destroyResource(CXDGToplevelTagManagerResource* res);
+
+ //
+ std::vector<UP<CXDGToplevelTagManagerResource>> m_vManagers;
+
+ friend class CXDGToplevelTagManagerResource;
+};
+
+namespace PROTO {
+ inline UP<CXDGToplevelTagProtocol> xdgTag;
+};