summaryrefslogtreecommitdiff
path: root/src/debug/HyprCtl.hpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-02-05 01:43:45 +0000
committerVaxry <vaxry@vaxry.net>2024-02-05 01:56:49 +0000
commit939696f97e2dcfa9ed6b91aa7ddf608c454d49e5 (patch)
treeed86a0d62b2773640a8dbaa1637593c36ab061d7 /src/debug/HyprCtl.hpp
parentcbadf3e3f31ab5ad5d192daac5f2ca930d08b8fb (diff)
hyprctl: move to a class and unify commands
Diffstat (limited to 'src/debug/HyprCtl.hpp')
-rw-r--r--src/debug/HyprCtl.hpp40
1 files changed, 25 insertions, 15 deletions
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 <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
};
-}; \ No newline at end of file
+
+ 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; \ No newline at end of file