From 939696f97e2dcfa9ed6b91aa7ddf608c454d49e5 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 5 Feb 2024 01:43:45 +0000 Subject: hyprctl: move to a class and unify commands --- src/debug/HyprCtl.hpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'src/debug/HyprCtl.hpp') diff --git a/src/debug/HyprCtl.hpp b/src/debug/HyprCtl.hpp index 00cf7c5b..1bef65a0 100644 --- a/src/debug/HyprCtl.hpp +++ b/src/debug/HyprCtl.hpp @@ -3,24 +3,34 @@ #include "../Compositor.hpp" #include #include "../helpers/MiscFunctions.hpp" +#include -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 }; -}; \ No newline at end of file + + struct SCommand { + std::string name = ""; + bool exact = true; + std::function fn; + }; + + std::string makeDynamicCall(const std::string& input); + std::shared_ptr registerCommand(SCommand cmd); + void unregisterCommand(const std::shared_ptr& cmd); + std::string getReply(std::string); + + int m_iSocketFD = -1; + + private: + void startHyprCtlSocket(); + + std::vector> m_vCommands; +}; + +inline std::unique_ptr g_pHyprCtl; \ No newline at end of file -- cgit v1.2.3