summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-12-19 20:23:32 +0000
committerVaxry <vaxry@vaxry.net>2024-12-19 20:23:32 +0000
commit71dc9f6128b8d2e382b2a574d2d5f15e2d907f3a (patch)
tree0b677e89a5bd3ffe2942078bd91bb0933ceb8ee7 /src
parentfd67ee9ecdc7207939fe1dcea9b81050ec7d58c4 (diff)
pluginAPI: add register dispatcher v2
Diffstat (limited to 'src')
-rw-r--r--src/SharedDefs.hpp7
-rw-r--r--src/managers/KeybindManager.hpp6
-rw-r--r--src/plugins/PluginAPI.cpp13
-rw-r--r--src/plugins/PluginAPI.hpp11
4 files changed, 30 insertions, 7 deletions
diff --git a/src/SharedDefs.hpp b/src/SharedDefs.hpp
index 711cf562..a6271556 100644
--- a/src/SharedDefs.hpp
+++ b/src/SharedDefs.hpp
@@ -3,6 +3,7 @@
#include "helpers/math/Math.hpp"
#include <functional>
#include <any>
+#include <string>
#include <hyprutils/math/Box.hpp>
enum eIcons : uint8_t {
@@ -50,6 +51,12 @@ struct SHyprCtlCommand {
std::function<std::string(eHyprCtlOutputFormat, std::string)> fn;
};
+struct SDispatchResult {
+ bool passEvent = false;
+ bool success = true;
+ std::string error;
+};
+
typedef int64_t WINDOWID;
typedef int64_t MONITORID;
typedef int64_t WORKSPACEID;
diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp
index 6486ac3b..c8c6266c 100644
--- a/src/managers/KeybindManager.hpp
+++ b/src/managers/KeybindManager.hpp
@@ -74,12 +74,6 @@ enum eMultiKeyCase : uint8_t {
MK_FULL_MATCH
};
-struct SDispatchResult {
- bool passEvent = false;
- bool success = true;
- std::string error;
-};
-
class CKeybindManager {
public:
CKeybindManager();
diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp
index 4172a856..5e1d9e58 100644
--- a/src/plugins/PluginAPI.cpp
+++ b/src/plugins/PluginAPI.cpp
@@ -202,6 +202,19 @@ APICALL bool HyprlandAPI::addDispatcher(HANDLE handle, const std::string& name,
return true;
}
+APICALL bool HyprlandAPI::addDispatcherV2(HANDLE handle, const std::string& name, std::function<SDispatchResult(std::string)> handler) {
+ auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
+
+ if (!PLUGIN)
+ return false;
+
+ PLUGIN->registeredDispatchers.push_back(name);
+
+ g_pKeybindManager->m_mDispatchers[name] = handler;
+
+ return true;
+}
+
APICALL bool HyprlandAPI::removeDispatcher(HANDLE handle, const std::string& name) {
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp
index 6b8c35f0..96c32bf1 100644
--- a/src/plugins/PluginAPI.hpp
+++ b/src/plugins/PluginAPI.hpp
@@ -236,8 +236,17 @@ namespace HyprlandAPI {
Adds a keybind dispatcher.
returns: true on success. False otherwise.
+
+ DEPRECATED: use addDispatcherV2
+ */
+ APICALL [[deprecated]] bool addDispatcher(HANDLE handle, const std::string& name, std::function<void(std::string)> handler);
+
+ /*
+ Adds a keybind dispatcher.
+
+ returns: true on success. False otherwise.
*/
- APICALL bool addDispatcher(HANDLE handle, const std::string& name, std::function<void(std::string)> handler);
+ APICALL bool addDispatcherV2(HANDLE handle, const std::string& name, std::function<SDispatchResult(std::string)> handler);
/*
Removes a keybind dispatcher.