mirror of
https://github.com/virtcode/hypr-dynamic-cursors
synced 2025-09-19 16:13:21 +02:00
feat: implemented shaperules
This commit is contained in:
parent
f2793f3bd3
commit
9fd1b6a1c2
13 changed files with 448 additions and 95 deletions
65
src/config/config.cpp
Normal file
65
src/config/config.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include "../globals.hpp"
|
||||
#include "config.hpp"
|
||||
#include <hyprland/src/plugins/PluginAPI.hpp>
|
||||
#include <hyprlang.hpp>
|
||||
#include <stdexcept>
|
||||
#include <variant>
|
||||
|
||||
Hyprlang::CConfigValue toHyprlang(std::variant<std::string, float, int> value) {
|
||||
|
||||
if (std::holds_alternative<std::string>(value))
|
||||
return Hyprlang::STRING { std::get<std::string>(value).c_str() };
|
||||
|
||||
if (std::holds_alternative<float>(value))
|
||||
return Hyprlang::FLOAT { std::get<float>(value) };
|
||||
|
||||
if (std::holds_alternative<int>(value))
|
||||
return Hyprlang::INT { std::get<int>(value) };
|
||||
|
||||
throw new std::logic_error("invalid type in variant?!");
|
||||
}
|
||||
|
||||
EShapeRuleType toShapeRule(std::variant<std::string, float, int> value) {
|
||||
|
||||
if (std::holds_alternative<std::string>(value))
|
||||
return EShapeRuleType::STRING;
|
||||
|
||||
if (std::holds_alternative<float>(value))
|
||||
return EShapeRuleType::FLOAT;
|
||||
|
||||
if (std::holds_alternative<int>(value))
|
||||
return EShapeRuleType::INT;
|
||||
|
||||
throw new std::logic_error("invalid type in variant?!");
|
||||
}
|
||||
|
||||
void startConfig() {
|
||||
g_pShapeRuleHandler = std::make_unique<CShapeRuleHandler>();
|
||||
}
|
||||
|
||||
void addConfig(std::string name, std::variant<std::string, float, int> value) {
|
||||
HyprlandAPI::addConfigValue(PHANDLE, NAMESPACE + name, toHyprlang(value));
|
||||
}
|
||||
|
||||
void addShapeConfig(std::string name, std::variant<std::string, float, int> value) {
|
||||
addConfig(name, value);
|
||||
|
||||
g_pShapeRuleHandler->addProperty(name, toShapeRule(value));
|
||||
}
|
||||
|
||||
void* const* getConfig(std::string name) {
|
||||
return HyprlandAPI::getConfigValue(PHANDLE, NAMESPACE + name)->getDataStaticPtr();
|
||||
}
|
||||
|
||||
void addRulesConfig() {
|
||||
HyprlandAPI::addConfigKeyword(PHANDLE, CONFIG_SHAPERULE, onShapeRuleKeyword, Hyprlang::SHandlerOptions {});
|
||||
|
||||
// clear on reload
|
||||
static const auto PCALLBACK = HyprlandAPI::registerCallbackDynamic( PHANDLE, "preConfigReload", [&](void* self, SCallbackInfo&, std::any data) {
|
||||
g_pShapeRuleHandler->clear();
|
||||
});
|
||||
}
|
||||
|
||||
void finishConfig() {
|
||||
HyprlandAPI::reloadConfig();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue