mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 08:45:58 +01:00
wayland-protocol: remove unused CWaylandResource
This commit is contained in:
parent
84ee839ca6
commit
1055e6bee6
2 changed files with 0 additions and 118 deletions
|
@ -1,96 +1,6 @@
|
|||
#include "WaylandProtocol.hpp"
|
||||
#include "../Compositor.hpp"
|
||||
|
||||
static void resourceDestroyNotify(wl_listener* listener, void* data) {
|
||||
CWaylandResource* pResource = wl_container_of(listener, pResource, m_liResourceDestroy);
|
||||
pResource->markDefunct();
|
||||
}
|
||||
|
||||
CWaylandResource::CWaylandResource(wl_client* client, const wl_interface* wlInterface, uint32_t version, uint32_t id) {
|
||||
m_pWLResource = wl_resource_create(client, wlInterface, version, id);
|
||||
|
||||
if (!m_pWLResource) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_set_user_data(m_pWLResource, this);
|
||||
|
||||
m_pWLClient = client;
|
||||
|
||||
wl_list_init(&m_liResourceDestroy.link);
|
||||
m_liResourceDestroy.notify = resourceDestroyNotify;
|
||||
wl_resource_add_destroy_listener(m_pWLResource, &m_liResourceDestroy);
|
||||
|
||||
Debug::log(TRACE, "[wl res {:x}] created", (uintptr_t)m_pWLResource);
|
||||
}
|
||||
|
||||
void CWaylandResource::markDefunct() {
|
||||
if (m_bDefunct)
|
||||
return;
|
||||
|
||||
Debug::log(TRACE, "[wl res {:x}] now defunct", (uintptr_t)m_pWLResource);
|
||||
m_bDefunct = true;
|
||||
|
||||
wl_resource_set_user_data(m_pWLResource, nullptr);
|
||||
|
||||
// we call it here because we need defunct to be set to true.
|
||||
// if this function destroys us, we can't call wl_resource_set_user_data or
|
||||
// destroy the resource.
|
||||
if (m_fOnDestroyHandler)
|
||||
m_fOnDestroyHandler(this);
|
||||
}
|
||||
|
||||
CWaylandResource::~CWaylandResource() {
|
||||
const bool DESTROY = m_pWLResource && !m_bDefunct;
|
||||
|
||||
wl_list_remove(&m_liResourceDestroy.link);
|
||||
wl_list_init(&m_liResourceDestroy.link);
|
||||
|
||||
Debug::log(TRACE, "[wl res {:x}] destroying (wl_resource_destroy will be {})", (uintptr_t)m_pWLResource, (DESTROY ? "sent" : "not sent"));
|
||||
|
||||
if (DESTROY)
|
||||
wl_resource_destroy(m_pWLResource);
|
||||
}
|
||||
|
||||
bool CWaylandResource::good() {
|
||||
return m_pWLResource && !m_bDefunct;
|
||||
}
|
||||
|
||||
wl_resource* CWaylandResource::resource() {
|
||||
return m_pWLResource;
|
||||
}
|
||||
|
||||
uint32_t CWaylandResource::version() {
|
||||
RASSERT(good(), "Attempted to call version() on a bad resource");
|
||||
|
||||
return wl_resource_get_version(m_pWLResource);
|
||||
}
|
||||
|
||||
void CWaylandResource::setImplementation(const void* impl, wl_resource_destroy_func_t df) {
|
||||
RASSERT(good(), "Attempted to call setImplementation() on a bad resource");
|
||||
RASSERT(!m_bImplementationSet, "Wayland Resource {:x} already has an implementation, cannot re-set!", (uintptr_t)m_pWLResource);
|
||||
|
||||
wl_resource_set_implementation(m_pWLResource, impl, this, df);
|
||||
|
||||
Debug::log(TRACE, "[wl res {:x}] set impl to {:x}", (uintptr_t)m_pWLResource, (uintptr_t)impl);
|
||||
|
||||
m_bImplementationSet = true;
|
||||
}
|
||||
|
||||
void CWaylandResource::setData(void* data) {
|
||||
Debug::log(TRACE, "[wl res {:x}] set data to {:x}", (uintptr_t)m_pWLResource, (uintptr_t)data);
|
||||
m_pData = data;
|
||||
}
|
||||
|
||||
void* CWaylandResource::data() {
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
void CWaylandResource::setOnDestroyHandler(std::function<void(CWaylandResource* res)> fn) {
|
||||
m_fOnDestroyHandler = fn;
|
||||
}
|
||||
|
||||
static void bindManagerInternal(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
||||
((IWaylandProtocol*)data)->bindManager(client, data, ver, id);
|
||||
}
|
||||
|
|
|
@ -14,34 +14,6 @@
|
|||
|
||||
#define PROTO NProtocols
|
||||
|
||||
class CWaylandResource {
|
||||
public:
|
||||
CWaylandResource(wl_client* client, const wl_interface* wlInterface, uint32_t version, uint32_t id);
|
||||
~CWaylandResource();
|
||||
|
||||
bool good();
|
||||
wl_resource* resource();
|
||||
uint32_t version();
|
||||
|
||||
void setImplementation(const void* impl, wl_resource_destroy_func_t df);
|
||||
|
||||
wl_listener m_liResourceDestroy; // private but has to be public
|
||||
void markDefunct();
|
||||
|
||||
void* data();
|
||||
void setData(void* data);
|
||||
|
||||
void setOnDestroyHandler(std::function<void(CWaylandResource* res)> fn);
|
||||
|
||||
private:
|
||||
bool m_bImplementationSet = false;
|
||||
bool m_bDefunct = false; // m_liResourceDestroy fired
|
||||
wl_client* m_pWLClient = nullptr;
|
||||
wl_resource* m_pWLResource = nullptr;
|
||||
void* m_pData = nullptr;
|
||||
std::function<void(CWaylandResource* res)> m_fOnDestroyHandler;
|
||||
};
|
||||
|
||||
class IWaylandProtocol {
|
||||
public:
|
||||
IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name);
|
||||
|
|
Loading…
Reference in a new issue