Hyprland/src/protocols/WaylandProtocol.hpp
Tom Englund 9c38b0fdbe core: add a destructor to CHyprOpenglImpl and avoid wl_container_of undefined behaviour (#7101)
* protocols: avoid undefined behaviour in C macro

to safely use wl_container_of with a class the class has to be no
virtual functions, no inheritance, and uniform access control (e.g all
public)

work around this by putting this into a destroywrapper struct.

* opengl: clean memory on destruction

add a destructor and free the allocated memory and close the fd
2024-07-29 19:29:08 +02:00

40 lines
1.5 KiB
C++

#pragma once
#include "../defines.hpp"
#include <functional>
#define RESOURCE_OR_BAIL(resname) \
const auto resname = (CWaylandResource*)wl_resource_get_user_data(resource); \
if (!resname) \
return;
#define PROTO NProtocols
class IWaylandProtocol;
struct IWaylandProtocolDestroyWrapper {
wl_listener listener;
IWaylandProtocol* parent = nullptr;
};
class IWaylandProtocol {
public:
IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name);
virtual ~IWaylandProtocol();
virtual void onDisplayDestroy();
virtual void removeGlobal();
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) = 0;
template <typename... Args>
void protoLog(LogLevel level, std::format_string<Args...> fmt, Args&&... args) {
Debug::log(level, std::format("[{}] ", m_szName) + std::vformat(fmt.get(), std::make_format_args(args...)));
};
IWaylandProtocolDestroyWrapper m_liDisplayDestroy;
private:
std::string m_szName;
wl_global* m_pGlobal = nullptr;
};