mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-05 22:05:58 +01:00
1ed1ce9506
moves std::shared_ptrs to a new implementation Advantages: - you can dereference a weak_ptr directly. This will obviously segfault on a nullptr deref if it's expired. - this is useful to avoid the .lock() hell where we are 100% sure the pointer _should_ be valid. (and if it isn't, it should throw.) - weak_ptrs are still valid while the SP is being destroyed. - reasoning: while an object (e.g. CWindow) is being destroyed, its `weak_ptr self` should be accessible (the sp is still alive, and so is CWindow), but it's not because by stl it's already expired (to prevent resurrection) - this impl solves it differently. w_p is expired, but can still be dereferenced and used. Creating `s_p`s is not possible anymore, though. - this is useful in destructors and callbacks.
52 lines
2.4 KiB
C++
52 lines
2.4 KiB
C++
#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>(makeShared<COrgKdeKwinServerDecoration>(CLIENT, pMgr->version(), id), wlr_surface_from_resource(surf))).get();
|
|
|
|
if (!RESOURCE->good()) {
|
|
pMgr->noMemory();
|
|
m_vDecos.pop_back();
|
|
return;
|
|
}
|
|
}
|