add infra for plugin stuff

This commit is contained in:
Vaxry 2024-02-09 15:38:59 +00:00
parent 0deac3df77
commit fdf8da1012
4 changed files with 36 additions and 10 deletions

View file

@ -1169,11 +1169,23 @@ std::unordered_map<std::string, SAnimationPropertyConfig> CConfigManager::getAni
return animationConfig;
}
void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) {}
void onPluginLoadUnload(const std::string& name, bool load) {
//
}
void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string&, const std::string&)> fn) {
void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) {
if (!name.starts_with("plugin:"))
return;
std::string field = name.substr(7);
m_pConfig->addSpecialConfigValue("plugin:", field.c_str(), value);
pluginVariables.push_back({handle, field});
}
void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) {
pluginKeywords.emplace_back(SPluginKeyword{handle, name, fn});
// HYPRLANG_TODO:
m_pConfig->registerHandler(fn, name.c_str(), opts);
}
void CConfigManager::removePluginConfig(HANDLE handle) {
@ -1185,6 +1197,13 @@ void CConfigManager::removePluginConfig(HANDLE handle) {
}
std::erase_if(pluginKeywords, [&](const auto& other) { return other.handle == handle; });
for (auto& [h, n] : pluginVariables) {
if (h != handle)
continue;
m_pConfig->removeSpecialConfigValue("plugin:", n.c_str());
}
std::erase_if(pluginVariables, [handle](const auto& other) { return other.handle == handle; });
}
std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) {

View file

@ -66,9 +66,14 @@ struct SAnimationPropertyConfig {
};
struct SPluginKeyword {
HANDLE handle = 0;
std::string name = "";
std::function<void(const std::string&, const std::string&)> fn;
HANDLE handle = 0;
std::string name = "";
Hyprlang::PCONFIGHANDLERFUNC fn = nullptr;
};
struct SPluginVariable {
HANDLE handle = 0;
std::string name = "";
};
struct SExecRequestedRule {
@ -93,6 +98,7 @@ class CConfigManager {
void* const* getConfigValuePtr(const std::string&);
Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string&);
void onPluginLoadUnload(const std::string& name, bool load);
static std::string getConfigDir();
static std::string getMainConfigPath();
@ -112,7 +118,7 @@ class CConfigManager {
std::unordered_map<std::string, SAnimationPropertyConfig> getAnimationConfig();
void addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value);
void addPluginKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& cmd, const std::string& val)> fun);
void addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fun, Hyprlang::SHandlerOptions opts = {});
void removePluginConfig(HANDLE handle);
// no-op when done.
@ -171,6 +177,7 @@ class CConfigManager {
std::vector<std::string> m_vDeclaredPlugins;
std::vector<SPluginKeyword> pluginKeywords;
std::vector<SPluginVariable> pluginVariables;
bool isFirstLaunch = true; // For exec-once

View file

@ -163,7 +163,7 @@ APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name,
return true;
}
APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& key, const std::string& val)> fn) {
APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) {
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
if (!g_pPluginSystem->m_bAllowConfigVars)
@ -172,7 +172,7 @@ APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& nam
if (!PLUGIN)
return false;
g_pConfigManager->addPluginKeyword(handle, name, fn);
g_pConfigManager->addPluginKeyword(handle, name, fn, opts);
return true;
}

View file

@ -120,7 +120,7 @@ namespace HyprlandAPI {
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);
APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts);
/*
Get a config value.