hyprctl: move to a class and unify commands

This commit is contained in:
Vaxry 2024-02-05 01:43:45 +00:00
parent cbadf3e3f3
commit 939696f97e
6 changed files with 165 additions and 155 deletions

View file

@ -3,24 +3,34 @@
#include "../Compositor.hpp"
#include <fstream>
#include "../helpers/MiscFunctions.hpp"
#include <functional>
namespace HyprCtl {
void startHyprCtlSocket();
std::string makeDynamicCall(const std::string& input);
// very simple thread-safe request method
inline bool requestMade = false;
inline bool requestReady = false;
inline std::string request = "";
inline std::ifstream requestStream;
inline wl_event_source* hyprCtlTickSource = nullptr;
inline int iSocketFD = -1;
class CHyprCtl {
public:
CHyprCtl();
enum eHyprCtlOutputFormat {
FORMAT_NORMAL = 0,
FORMAT_JSON
};
};
struct SCommand {
std::string name = "";
bool exact = true;
std::function<std::string(eHyprCtlOutputFormat, std::string)> fn;
};
std::string makeDynamicCall(const std::string& input);
std::shared_ptr<SCommand> registerCommand(SCommand cmd);
void unregisterCommand(const std::shared_ptr<SCommand>& cmd);
std::string getReply(std::string);
int m_iSocketFD = -1;
private:
void startHyprCtlSocket();
std::vector<std::shared_ptr<SCommand>> m_vCommands;
};
inline std::unique_ptr<CHyprCtl> g_pHyprCtl;