waybar/include/modules/hyprland/backend.hpp

40 lines
867 B
C++
Raw Normal View History

2022-07-01 12:46:28 +02:00
#pragma once
#include <functional>
2022-11-24 12:28:52 +01:00
#include <list>
#include <memory>
#include <mutex>
#include <string>
2022-07-01 12:46:28 +02:00
#include <thread>
2023-06-28 01:52:01 +02:00
#include "util/json.hpp"
2022-07-01 12:46:28 +02:00
namespace waybar::modules::hyprland {
2022-11-09 09:34:19 +01:00
class EventHandler {
2022-11-24 12:28:52 +01:00
public:
2022-11-09 09:34:19 +01:00
virtual void onEvent(const std::string& ev) = 0;
virtual ~EventHandler() = default;
};
2022-07-01 12:46:28 +02:00
class IPC {
public:
2022-07-01 12:46:28 +02:00
IPC() { startIPC(); }
2022-11-09 09:34:19 +01:00
void registerForIPC(const std::string&, EventHandler*);
void unregisterForIPC(EventHandler*);
2022-07-01 12:46:28 +02:00
std::string getSocket1Reply(const std::string& rq);
2023-06-28 01:52:01 +02:00
Json::Value getSocket1JsonReply(const std::string& rq);
2022-07-01 12:46:28 +02:00
private:
void startIPC();
void parseIPC(const std::string&);
2022-07-01 12:46:28 +02:00
std::mutex callbackMutex;
2023-06-28 01:52:01 +02:00
util::JsonParser parser_;
2022-11-09 09:34:19 +01:00
std::list<std::pair<std::string, EventHandler*>> callbacks;
2022-07-01 12:46:28 +02:00
};
inline std::unique_ptr<IPC> gIPC;
inline bool modulesReady = false;
}; // namespace waybar::modules::hyprland