2025-04-21 22:22:06 +01:00
|
|
|
#include "XDGTag.hpp"
|
|
|
|
|
#include "XDGShell.hpp"
|
2025-11-17 18:34:02 +00:00
|
|
|
#include "../desktop/Window.hpp"
|
2025-04-21 22:22:06 +01:00
|
|
|
|
|
|
|
|
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); });
|
|
|
|
|
|
2025-04-29 19:48:52 +01:00
|
|
|
m_resource->setSetToplevelTag([](CXdgToplevelTagManagerV1* r, wl_resource* toplevel, const char* tag) {
|
2025-04-21 22:22:06 +01:00
|
|
|
auto TOPLEVEL = CXDGToplevelResource::fromResource(toplevel);
|
|
|
|
|
|
|
|
|
|
if (!TOPLEVEL) {
|
|
|
|
|
r->error(-1, "Invalid toplevel handle");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TOPLEVEL->m_toplevelTag = tag;
|
2025-11-17 18:34:02 +00:00
|
|
|
if (TOPLEVEL->m_window)
|
|
|
|
|
TOPLEVEL->m_window->m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_XDG_TAG);
|
2025-04-21 22:22:06 +01:00
|
|
|
});
|
|
|
|
|
|
2025-04-29 19:48:52 +01:00
|
|
|
m_resource->setSetToplevelDescription([](CXdgToplevelTagManagerV1* r, wl_resource* toplevel, const char* description) {
|
2025-04-21 22:22:06 +01:00
|
|
|
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 =
|
2025-05-04 23:39:00 +02:00
|
|
|
WP<CXDGToplevelTagManagerResource>{m_managers.emplace_back(makeUnique<CXDGToplevelTagManagerResource>(makeUnique<CXdgToplevelTagManagerV1>(client, ver, id)))};
|
2025-04-21 22:22:06 +01:00
|
|
|
|
|
|
|
|
if UNLIKELY (!RESOURCE->good()) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CXDGToplevelTagProtocol::destroyResource(CXDGToplevelTagManagerResource* res) {
|
2025-05-04 23:39:00 +02:00
|
|
|
std::erase_if(m_managers, [&](const auto& other) { return other.get() == res; });
|
2025-04-21 22:22:06 +01:00
|
|
|
}
|