2022-07-01 10:46:28 +00:00
|
|
|
#pragma once
|
2023-09-02 20:22:26 +00:00
|
|
|
|
2022-11-24 11:28:52 +00:00
|
|
|
#include <list>
|
2021-05-27 13:40:54 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
2023-09-02 20:22:26 +00:00
|
|
|
#include <utility>
|
2023-07-01 09:12:14 +00:00
|
|
|
|
2023-06-27 23:52:01 +00:00
|
|
|
#include "util/json.hpp"
|
2022-07-01 10:46:28 +00:00
|
|
|
|
|
|
|
namespace waybar::modules::hyprland {
|
2022-11-09 08:34:19 +00:00
|
|
|
|
|
|
|
class EventHandler {
|
2022-11-24 11:28:52 +00:00
|
|
|
public:
|
2022-11-09 08:34:19 +00:00
|
|
|
virtual void onEvent(const std::string& ev) = 0;
|
|
|
|
virtual ~EventHandler() = default;
|
|
|
|
};
|
|
|
|
|
2022-07-01 10:46:28 +00:00
|
|
|
class IPC {
|
2021-05-27 13:40:54 +00:00
|
|
|
public:
|
2022-07-01 10:46:28 +00:00
|
|
|
IPC() { startIPC(); }
|
|
|
|
|
2024-02-25 11:11:22 +00:00
|
|
|
void registerForIPC(const std::string& ev, EventHandler* ev_handler);
|
|
|
|
void unregisterForIPC(EventHandler* handler);
|
2022-07-01 10:46:28 +00:00
|
|
|
|
2024-01-06 04:57:27 +00:00
|
|
|
static std::string getSocket1Reply(const std::string& rq);
|
2023-06-27 23:52:01 +00:00
|
|
|
Json::Value getSocket1JsonReply(const std::string& rq);
|
2022-07-01 10:46:28 +00:00
|
|
|
|
2021-05-27 13:40:54 +00:00
|
|
|
private:
|
|
|
|
void startIPC();
|
|
|
|
void parseIPC(const std::string&);
|
2022-07-01 10:46:28 +00:00
|
|
|
|
2024-02-25 11:11:22 +00:00
|
|
|
std::mutex callbackMutex_;
|
|
|
|
util::JsonParser parser_;
|
|
|
|
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;
|
2021-05-27 13:40:54 +00:00
|
|
|
}; // namespace waybar::modules::hyprland
|