mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-25 20:29:48 +01:00
add infra for plugin stuff
This commit is contained in:
parent
0deac3df77
commit
fdf8da1012
4 changed files with 36 additions and 10 deletions
|
@ -1169,11 +1169,23 @@ std::unordered_map<std::string, SAnimationPropertyConfig> CConfigManager::getAni
|
||||||
return animationConfig;
|
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});
|
pluginKeywords.emplace_back(SPluginKeyword{handle, name, fn});
|
||||||
// HYPRLANG_TODO:
|
m_pConfig->registerHandler(fn, name.c_str(), opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfigManager::removePluginConfig(HANDLE handle) {
|
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; });
|
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) {
|
std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) {
|
||||||
|
|
|
@ -66,9 +66,14 @@ struct SAnimationPropertyConfig {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SPluginKeyword {
|
struct SPluginKeyword {
|
||||||
HANDLE handle = 0;
|
HANDLE handle = 0;
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
std::function<void(const std::string&, const std::string&)> fn;
|
Hyprlang::PCONFIGHANDLERFUNC fn = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SPluginVariable {
|
||||||
|
HANDLE handle = 0;
|
||||||
|
std::string name = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SExecRequestedRule {
|
struct SExecRequestedRule {
|
||||||
|
@ -93,6 +98,7 @@ class CConfigManager {
|
||||||
|
|
||||||
void* const* getConfigValuePtr(const std::string&);
|
void* const* getConfigValuePtr(const std::string&);
|
||||||
Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string&);
|
Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string&);
|
||||||
|
void onPluginLoadUnload(const std::string& name, bool load);
|
||||||
static std::string getConfigDir();
|
static std::string getConfigDir();
|
||||||
static std::string getMainConfigPath();
|
static std::string getMainConfigPath();
|
||||||
|
|
||||||
|
@ -112,7 +118,7 @@ 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 Hyprlang::CConfigValue& value);
|
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);
|
void removePluginConfig(HANDLE handle);
|
||||||
|
|
||||||
// no-op when done.
|
// no-op when done.
|
||||||
|
@ -171,6 +177,7 @@ class CConfigManager {
|
||||||
|
|
||||||
std::vector<std::string> m_vDeclaredPlugins;
|
std::vector<std::string> m_vDeclaredPlugins;
|
||||||
std::vector<SPluginKeyword> pluginKeywords;
|
std::vector<SPluginKeyword> pluginKeywords;
|
||||||
|
std::vector<SPluginVariable> pluginVariables;
|
||||||
|
|
||||||
bool isFirstLaunch = true; // For exec-once
|
bool isFirstLaunch = true; // For exec-once
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ 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) {
|
APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) {
|
||||||
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
|
auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle);
|
||||||
|
|
||||||
if (!g_pPluginSystem->m_bAllowConfigVars)
|
if (!g_pPluginSystem->m_bAllowConfigVars)
|
||||||
|
@ -172,7 +172,7 @@ APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& nam
|
||||||
if (!PLUGIN)
|
if (!PLUGIN)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
g_pConfigManager->addPluginKeyword(handle, name, fn);
|
g_pConfigManager->addPluginKeyword(handle, name, fn, opts);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace HyprlandAPI {
|
||||||
|
|
||||||
returns: true on success, false on fail
|
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.
|
Get a config value.
|
||||||
|
|
Loading…
Reference in a new issue