Add custom wrapper overriding togglegroup dispatcher

This commit is contained in:
ItsDrike 2023-03-31 17:56:09 +02:00
parent 1ae38874f2
commit 2788905750
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -2,8 +2,23 @@
#include "globals.hpp"
#include <src/layout/DwindleLayout.hpp>
#include <src/managers/KeybindManager.hpp>
#include <src/managers/LayoutManager.hpp>
const CColor s_pluginColor = {0x61 / 255.0f, 0xAF / 255.0f, 0xEF / 255.0f, 1.0f};
inline std::function<void(std::string)> originalToggleGroup = nullptr;
void toggleGroup(std::string args)
{
// Run the original function, creating the group
originalToggleGroup(args);
HyprlandAPI::addNotification(PHANDLE, "[dwindle-autogroup] Group toggeld!", s_pluginColor, 5000);
}
// Do NOT change this function.
APICALL EXPORT std::string PLUGIN_API_VERSION()
{
@ -14,14 +29,22 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle)
{
PHANDLE = handle;
HyprlandAPI::addNotification(PHANDLE, "[dwindle-autogroup] Initialized successfully!", s_pluginColor, 5000);
originalToggleGroup = g_pKeybindManager->m_mDispatchers["togglegroup"];
HyprlandAPI::addDispatcher(PHANDLE, "togglegroup", toggleGroup);
HyprlandAPI::reloadConfig();
HyprlandAPI::addNotification(PHANDLE, "[dwindle-autogroup] Initialized successfully!", s_pluginColor, 5000);
return {"dwindle-autogroup", "Dwindle Autogroup", "ItsDrike", "1.0"};
}
APICALL EXPORT void PLUGIN_EXIT()
{
// Since we added the "togglegroup" dispatcher ourselves, by default, the cleanup would just remove it
// but we want to restore it back to the original function instead
HyprlandAPI::removeDispatcher(PHANDLE, "togglegroup");
g_pKeybindManager->m_mDispatchers["togglegroup"] = originalToggleGroup;
HyprlandAPI::addNotification(PHANDLE, "[dwindle-autogroup] Unloaded successfully!", s_pluginColor, 5000);
}