mirror of
				https://github.com/hyprwm/Hyprland.git
				synced 2025-10-26 12:27:09 +00:00 
			
		
		
		
	pluginAPI: add register dispatcher v2
This commit is contained in:
		| @@ -3,6 +3,7 @@ | |||||||
| #include "helpers/math/Math.hpp" | #include "helpers/math/Math.hpp" | ||||||
| #include <functional> | #include <functional> | ||||||
| #include <any> | #include <any> | ||||||
|  | #include <string> | ||||||
| #include <hyprutils/math/Box.hpp> | #include <hyprutils/math/Box.hpp> | ||||||
|  |  | ||||||
| enum eIcons : uint8_t { | enum eIcons : uint8_t { | ||||||
| @@ -50,6 +51,12 @@ struct SHyprCtlCommand { | |||||||
|     std::function<std::string(eHyprCtlOutputFormat, std::string)> fn; |     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                                              WINDOWID; | ||||||
| typedef int64_t                                              MONITORID; | typedef int64_t                                              MONITORID; | ||||||
| typedef int64_t                                              WORKSPACEID; | typedef int64_t                                              WORKSPACEID; | ||||||
|   | |||||||
| @@ -74,12 +74,6 @@ enum eMultiKeyCase : uint8_t { | |||||||
|     MK_FULL_MATCH |     MK_FULL_MATCH | ||||||
| }; | }; | ||||||
|  |  | ||||||
| struct SDispatchResult { |  | ||||||
|     bool        passEvent = false; |  | ||||||
|     bool        success   = true; |  | ||||||
|     std::string error; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| class CKeybindManager { | class CKeybindManager { | ||||||
|   public: |   public: | ||||||
|     CKeybindManager(); |     CKeybindManager(); | ||||||
|   | |||||||
| @@ -202,6 +202,19 @@ APICALL bool HyprlandAPI::addDispatcher(HANDLE handle, const std::string& name, | |||||||
|     return true; |     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) { | APICALL bool HyprlandAPI::removeDispatcher(HANDLE handle, const std::string& name) { | ||||||
|     auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); |     auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -236,8 +236,17 @@ namespace HyprlandAPI { | |||||||
|         Adds a keybind dispatcher. |         Adds a keybind dispatcher. | ||||||
|  |  | ||||||
|         returns: true on success. False otherwise. |         returns: true on success. False otherwise. | ||||||
|  |  | ||||||
|  |         DEPRECATED: use addDispatcherV2 | ||||||
|     */ |     */ | ||||||
|     APICALL bool addDispatcher(HANDLE handle, const std::string& name, std::function<void(std::string)> handler); |     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 addDispatcherV2(HANDLE handle, const std::string& name, std::function<SDispatchResult(std::string)> handler); | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|         Removes a keybind dispatcher. |         Removes a keybind dispatcher. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Vaxry
					Vaxry