Waybar/include/modules/hyprland/backend.hpp

37 lines
755 B
C++
Raw Normal View History

2022-07-01 10:46:28 +00:00
#pragma once
2022-11-09 08:34:19 +00:00
#include <list>
2022-07-01 10:46:28 +00:00
#include <functional>
#include <memory>
#include <mutex>
#include <string>
2022-07-01 10:46:28 +00:00
#include <thread>
namespace waybar::modules::hyprland {
2022-11-09 08:34:19 +00:00
class EventHandler {
public:
virtual void onEvent(const std::string& ev) = 0;
virtual ~EventHandler() = default;
};
2022-07-01 10:46:28 +00:00
class IPC {
public:
2022-07-01 10:46:28 +00:00
IPC() { startIPC(); }
2022-11-09 08:34:19 +00:00
void registerForIPC(const std::string&, EventHandler*);
void unregisterForIPC(EventHandler*);
2022-07-01 10:46:28 +00:00
std::string getSocket1Reply(const std::string& rq);
private:
void startIPC();
void parseIPC(const std::string&);
2022-07-01 10:46:28 +00:00
std::mutex callbackMutex;
2022-11-09 08:34:19 +00:00
std::list<std::pair<std::string, EventHandler*>> callbacks;
2022-07-01 10:46:28 +00:00
};
inline std::unique_ptr<IPC> gIPC;
inline bool modulesReady = false;
}; // namespace waybar::modules::hyprland