Skip to content

Commit

Permalink
pluginAPI: add register dispatcher v2
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Dec 19, 2024
1 parent fd67ee9 commit 71dc9f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/SharedDefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "helpers/math/Math.hpp"
#include <functional>
#include <any>
#include <string>
#include <hyprutils/math/Box.hpp>

enum eIcons : uint8_t {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/PluginAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 10 additions & 1 deletion src/plugins/PluginAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,21 @@ namespace HyprlandAPI {
*/
APICALL bool removeWindowDecoration(HANDLE handle, IHyprWindowDecoration* pDecoration);

/*
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.
Expand Down

0 comments on commit 71dc9f6

Please sign in to comment.