mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-21 23:13:49 -07:00
xdg-decoration: move to new impl
This commit is contained in:
75
src/protocols/XDGDecoration.cpp
Normal file
75
src/protocols/XDGDecoration.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "XDGDecoration.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
CXDGDecoration::CXDGDecoration(SP<CZxdgToplevelDecorationV1> resource_, wl_resource* toplevel) : resource(resource_), pToplevelResource(toplevel) {
|
||||
if (!resource->resource())
|
||||
return;
|
||||
|
||||
resource->setDestroy([this](CZxdgToplevelDecorationV1* pMgr) { PROTO::xdgDecoration->destroyDecoration(this); });
|
||||
resource->setOnDestroy([this](CZxdgToplevelDecorationV1* pMgr) { PROTO::xdgDecoration->destroyDecoration(this); });
|
||||
|
||||
resource->setSetMode([this](CZxdgToplevelDecorationV1*, zxdgToplevelDecorationV1Mode mode) {
|
||||
std::string modeString;
|
||||
switch (mode) {
|
||||
case zxdgToplevelDecorationV1Mode::MODE_CLIENT_SIDE: modeString = "MODE_CLIENT_SIDE"; break;
|
||||
case zxdgToplevelDecorationV1Mode::MODE_SERVER_SIDE: modeString = "MODE_SERVER_SIDE"; break;
|
||||
default: modeString = "INVALID"; break;
|
||||
}
|
||||
|
||||
Debug::log(LOG, "[xdgDecoration] setMode: {}. {} MODE_SERVER_SIDE as reply.", modeString,
|
||||
(mode == zxdgToplevelDecorationV1Mode::MODE_SERVER_SIDE ? "Sending" : "Ignoring and sending"));
|
||||
resource->sendConfigure(zxdgToplevelDecorationV1Mode::MODE_SERVER_SIDE);
|
||||
});
|
||||
|
||||
resource->setUnsetMode([this](CZxdgToplevelDecorationV1*) {
|
||||
Debug::log(LOG, "[xdgDecoration] unsetMode. Sending MODE_SERVER_SIDE.");
|
||||
resource->sendConfigure(zxdgToplevelDecorationV1Mode::MODE_SERVER_SIDE);
|
||||
});
|
||||
}
|
||||
|
||||
bool CXDGDecoration::good() {
|
||||
return resource->resource();
|
||||
}
|
||||
|
||||
wl_resource* CXDGDecoration::toplevelResource() {
|
||||
return pToplevelResource;
|
||||
}
|
||||
|
||||
CXDGDecorationProtocol::CXDGDecorationProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
||||
;
|
||||
}
|
||||
|
||||
void CXDGDecorationProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
||||
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CZxdgDecorationManagerV1>(client, ver, id)).get();
|
||||
RESOURCE->setOnDestroy([this](CZxdgDecorationManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
|
||||
|
||||
RESOURCE->setDestroy([this](CZxdgDecorationManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
|
||||
RESOURCE->setGetToplevelDecoration([this](CZxdgDecorationManagerV1* pMgr, uint32_t id, wl_resource* xdgToplevel) { this->onGetDecoration(pMgr, id, xdgToplevel); });
|
||||
}
|
||||
|
||||
void CXDGDecorationProtocol::onManagerResourceDestroy(wl_resource* res) {
|
||||
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
|
||||
}
|
||||
|
||||
void CXDGDecorationProtocol::destroyDecoration(CXDGDecoration* decoration) {
|
||||
m_mDecorations.erase(decoration->toplevelResource());
|
||||
}
|
||||
|
||||
void CXDGDecorationProtocol::onGetDecoration(CZxdgDecorationManagerV1* pMgr, uint32_t id, wl_resource* xdgToplevel) {
|
||||
if (m_mDecorations.contains(xdgToplevel)) {
|
||||
wl_resource_post_error(pMgr->resource(), zxdgToplevelDecorationV1Error::ERROR_ALREADY_CONSTRUCTED, "Decoration object already exists");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto CLIENT = wl_resource_get_client(pMgr->resource());
|
||||
const auto RESOURCE =
|
||||
m_mDecorations
|
||||
.emplace(xdgToplevel, std::make_unique<CXDGDecoration>(std::make_shared<CZxdgToplevelDecorationV1>(CLIENT, wl_resource_get_version(pMgr->resource()), id), xdgToplevel))
|
||||
.first->second.get();
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
wl_resource_post_no_memory(pMgr->resource());
|
||||
m_mDecorations.erase(xdgToplevel);
|
||||
return;
|
||||
}
|
||||
}
|
41
src/protocols/XDGDecoration.hpp
Normal file
41
src/protocols/XDGDecoration.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "WaylandProtocol.hpp"
|
||||
#include "xdg-decoration-unstable-v1.hpp"
|
||||
|
||||
class CXDGDecoration {
|
||||
public:
|
||||
CXDGDecoration(SP<CZxdgToplevelDecorationV1> resource_, wl_resource* toplevel);
|
||||
|
||||
bool good();
|
||||
wl_resource* toplevelResource();
|
||||
|
||||
private:
|
||||
SP<CZxdgToplevelDecorationV1> resource;
|
||||
wl_resource* pToplevelResource = nullptr; // READ-ONLY.
|
||||
};
|
||||
|
||||
class CXDGDecorationProtocol : public IWaylandProtocol {
|
||||
public:
|
||||
CXDGDecorationProtocol(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 destroyDecoration(CXDGDecoration* decoration);
|
||||
void onGetDecoration(CZxdgDecorationManagerV1* pMgr, uint32_t id, wl_resource* xdgToplevel);
|
||||
|
||||
//
|
||||
std::vector<UP<CZxdgDecorationManagerV1>> m_vManagers;
|
||||
std::unordered_map<wl_resource*, UP<CXDGDecoration>> m_mDecorations; // xdg_toplevel -> deco
|
||||
|
||||
friend class CXDGDecoration;
|
||||
};
|
||||
|
||||
namespace PROTO {
|
||||
inline UP<CXDGDecorationProtocol> xdgDecoration;
|
||||
};
|
Reference in New Issue
Block a user