Hyprland/src/protocols/GlobalShortcuts.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

48 lines
1.7 KiB
C++

#pragma once
#include "../defines.hpp"
#include "hyprland-global-shortcuts-v1-protocol.h"
#include <vector>
struct SShortcut {
wl_resource* resource;
std::string id, description, appid;
uint32_t shortcut = 0;
};
struct SShortcutClient {
wl_client* client = nullptr;
std::vector<std::unique_ptr<SShortcut>> shortcuts;
};
class CGlobalShortcutsProtocolManager;
struct CGlobalShortcutsProtocolManagerDestroyWrapper {
wl_listener listener;
CGlobalShortcutsProtocolManager* parent = nullptr;
};
class CGlobalShortcutsProtocolManager {
public:
CGlobalShortcutsProtocolManager();
~CGlobalShortcutsProtocolManager();
void bindManager(wl_client* client, void* data, uint32_t version, uint32_t id);
void displayDestroy();
void registerShortcut(wl_client* client, wl_resource* resource, uint32_t shortcut, const char* id, const char* app_id, const char* description,
const char* trigger_description);
void destroyShortcut(wl_resource* resource);
bool globalShortcutExists(std::string appid, std::string trigger);
void sendGlobalShortcutEvent(std::string appid, std::string trigger, bool pressed);
std::vector<SShortcut> getAllShortcuts();
CGlobalShortcutsProtocolManagerDestroyWrapper m_liDisplayDestroy;
private:
std::vector<std::unique_ptr<SShortcutClient>> m_vClients;
SShortcutClient* clientFromWlClient(wl_client* client);
wl_global* m_pGlobal = nullptr;
};