mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-09 15:45:57 +01:00
pluginapi: add a config keyword adding method
This commit is contained in:
parent
7f4b0aaadc
commit
af9440152e
4 changed files with 47 additions and 3 deletions
|
@ -1389,8 +1389,15 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::
|
||||||
else if (COMMAND.starts_with("plugin"))
|
else if (COMMAND.starts_with("plugin"))
|
||||||
handlePlugin(COMMAND, VALUE);
|
handlePlugin(COMMAND, VALUE);
|
||||||
else {
|
else {
|
||||||
configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE);
|
// try config
|
||||||
needsLayoutRecalc = 2;
|
const auto IT = std::find_if(pluginKeywords.begin(), pluginKeywords.end(), [&](const auto& other) { return other.name == COMMAND; });
|
||||||
|
|
||||||
|
if (IT != pluginKeywords.end()) {
|
||||||
|
IT->fn(COMMAND, VALUE);
|
||||||
|
} else {
|
||||||
|
configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE);
|
||||||
|
needsLayoutRecalc = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
|
@ -1524,6 +1531,8 @@ void CConfigManager::parseLine(std::string& line) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfigManager::loadConfigLoadVars() {
|
void CConfigManager::loadConfigLoadVars() {
|
||||||
|
EMIT_HOOK_EVENT("preConfigReload", nullptr);
|
||||||
|
|
||||||
Debug::log(LOG, "Reloading the config!");
|
Debug::log(LOG, "Reloading the config!");
|
||||||
parseError = ""; // reset the error
|
parseError = ""; // reset the error
|
||||||
currentCategory = ""; // reset the category
|
currentCategory = ""; // reset the category
|
||||||
|
@ -2312,8 +2321,13 @@ void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string&, const std::string&)> fn) {
|
||||||
|
pluginKeywords.emplace_back(SPluginKeyword{handle, name, fn});
|
||||||
|
}
|
||||||
|
|
||||||
void CConfigManager::removePluginConfig(HANDLE handle) {
|
void CConfigManager::removePluginConfig(HANDLE handle) {
|
||||||
std::erase_if(pluginConfigs, [&](const auto& other) { return other.first == handle; });
|
std::erase_if(pluginConfigs, [&](const auto& other) { return other.first == handle; });
|
||||||
|
std::erase_if(pluginKeywords, [&](const auto& other) { return other.handle == handle; });
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) {
|
std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <functional>
|
||||||
#include <xf86drmMode.h>
|
#include <xf86drmMode.h>
|
||||||
#include "../Window.hpp"
|
#include "../Window.hpp"
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../helpers/WLClasses.hpp"
|
||||||
|
@ -71,6 +72,12 @@ struct SAnimationPropertyConfig {
|
||||||
SAnimationPropertyConfig* pParentAnimation = nullptr;
|
SAnimationPropertyConfig* pParentAnimation = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SPluginKeyword {
|
||||||
|
HANDLE handle = 0;
|
||||||
|
std::string name = "";
|
||||||
|
std::function<void(const std::string&, const std::string&)> fn;
|
||||||
|
};
|
||||||
|
|
||||||
struct SExecRequestedRule {
|
struct SExecRequestedRule {
|
||||||
std::string szRule = "";
|
std::string szRule = "";
|
||||||
uint64_t iPid = 0;
|
uint64_t iPid = 0;
|
||||||
|
@ -120,7 +127,8 @@ class CConfigManager {
|
||||||
std::unordered_map<std::string, SAnimationPropertyConfig> getAnimationConfig();
|
std::unordered_map<std::string, SAnimationPropertyConfig> getAnimationConfig();
|
||||||
|
|
||||||
void addPluginConfigVar(HANDLE handle, const std::string& name, const SConfigValue& value);
|
void addPluginConfigVar(HANDLE handle, const std::string& name, const SConfigValue& value);
|
||||||
void removePluginConfig(HANDLE handle);
|
void addPluginKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& cmd, const std::string& val)> fun);
|
||||||
|
void removePluginConfig(HANDLE handle);
|
||||||
|
|
||||||
// no-op when done.
|
// no-op when done.
|
||||||
void dispatchExecOnce();
|
void dispatchExecOnce();
|
||||||
|
@ -163,6 +171,7 @@ class CConfigManager {
|
||||||
|
|
||||||
std::vector<std::string> m_vDeclaredPlugins;
|
std::vector<std::string> m_vDeclaredPlugins;
|
||||||
std::unordered_map<HANDLE, std::unique_ptr<std::unordered_map<std::string, SConfigValue>>> pluginConfigs; // stores plugin configs
|
std::unordered_map<HANDLE, std::unique_ptr<std::unordered_map<std::string, SConfigValue>>> pluginConfigs; // stores plugin configs
|
||||||
|
std::vector<SPluginKeyword> pluginKeywords;
|
||||||
|
|
||||||
bool isFirstLaunch = true; // For exec-once
|
bool isFirstLaunch = true; // For exec-once
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,19 @@ APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& key, const std::string& val)> fn) {
|
||||||
|
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
|
||||||
|
|
||||||
|
if (!g_pPluginSystem->m_bAllowConfigVars)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!PLUGIN)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
g_pConfigManager->addPluginKeyword(handle, name, fn);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
APICALL SConfigValue* HyprlandAPI::getConfigValue(HANDLE handle, const std::string& name) {
|
APICALL SConfigValue* HyprlandAPI::getConfigValue(HANDLE handle, const std::string& name) {
|
||||||
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
|
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,14 @@ namespace HyprlandAPI {
|
||||||
*/
|
*/
|
||||||
APICALL bool addConfigValue(HANDLE handle, const std::string& name, const SConfigValue& value);
|
APICALL bool addConfigValue(HANDLE handle, const std::string& name, const SConfigValue& value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Add a config keyword.
|
||||||
|
This method may only be called in "pluginInit"
|
||||||
|
|
||||||
|
returns: true on success, false on fail
|
||||||
|
*/
|
||||||
|
APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& key, const std::string& val)> fn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get a config value.
|
Get a config value.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue