Files
waybar/include/modules/hyprland/backend.hpp
yangyingchao bdd7271da9 Improvements for Hyprland backend
1. Fix warnings reported by clang tidy
2. Use unique lock instead of manully lock/unlock on mutex.
   The RAII style locking makes sure mutex is unlocked when exceptions are thrown
2024-01-08 09:26:16 +08:00

41 lines
860 B
C++

#pragma once
#include <list>
#include <memory>
#include <mutex>
#include <string>
#include <utility>
#include "util/json.hpp"
namespace waybar::modules::hyprland {
class EventHandler {
public:
virtual void onEvent(const std::string& ev) = 0;
virtual ~EventHandler() = default;
};
class IPC {
public:
IPC() { startIPC(); }
void registerForIPC(const std::string&, EventHandler*);
void unregisterForIPC(EventHandler*);
static std::string getSocket1Reply(const std::string& rq);
Json::Value getSocket1JsonReply(const std::string& rq);
private:
void startIPC();
void parseIPC(const std::string&);
std::mutex m_callbackMutex;
util::JsonParser m_parser;
std::list<std::pair<std::string, EventHandler*>> m_callbacks;
};
inline std::unique_ptr<IPC> gIPC;
inline bool modulesReady = false;
}; // namespace waybar::modules::hyprland