2023-12-28 20:38:01 +01:00
|
|
|
#include "public.hpp"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-12-28 23:25:43 +01:00
|
|
|
struct SHandler {
|
|
|
|
std::string name = "";
|
|
|
|
Hyprlang::SHandlerOptions options;
|
|
|
|
Hyprlang::PCONFIGHANDLERFUNC func = nullptr;
|
|
|
|
};
|
|
|
|
|
2023-12-29 11:40:08 +01:00
|
|
|
struct SVariable {
|
2023-12-29 11:48:55 +01:00
|
|
|
std::string name = "";
|
|
|
|
std::string value = "";
|
|
|
|
std::vector<std::string> linesContainingVar; // for dynamic updates
|
2023-12-29 11:40:08 +01:00
|
|
|
};
|
|
|
|
|
2023-12-29 19:35:23 +01:00
|
|
|
// remember to also edit CConfigValue if editing
|
|
|
|
enum eDataType {
|
|
|
|
CONFIGDATATYPE_EMPTY,
|
|
|
|
CONFIGDATATYPE_INT,
|
|
|
|
CONFIGDATATYPE_FLOAT,
|
|
|
|
CONFIGDATATYPE_STR,
|
|
|
|
CONFIGDATATYPE_VEC2,
|
|
|
|
CONFIGDATATYPE_CUSTOM,
|
|
|
|
};
|
|
|
|
|
|
|
|
// CUSTOM is stored as STR!!
|
|
|
|
struct SConfigDefaultValue {
|
|
|
|
std::any data;
|
|
|
|
eDataType type = CONFIGDATATYPE_EMPTY;
|
|
|
|
|
|
|
|
// this sucks but I have no better idea
|
|
|
|
Hyprlang::PCONFIGCUSTOMVALUEHANDLERFUNC handler = nullptr;
|
|
|
|
Hyprlang::PCONFIGCUSTOMVALUEDESTRUCTOR dtor = nullptr;
|
|
|
|
};
|
|
|
|
|
2023-12-29 13:26:21 +01:00
|
|
|
struct SSpecialCategoryDescriptor {
|
2023-12-29 19:35:23 +01:00
|
|
|
std::string name = "";
|
|
|
|
std::string key = "";
|
|
|
|
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
|
|
|
|
bool dontErrorOnMissing = false;
|
2023-12-29 13:26:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SSpecialCategory {
|
|
|
|
SSpecialCategoryDescriptor* descriptor = nullptr;
|
|
|
|
std::string name = "";
|
|
|
|
std::string key = ""; // empty means no key
|
|
|
|
std::unordered_map<std::string, Hyprlang::CConfigValue> values;
|
|
|
|
bool isStatic = false;
|
|
|
|
|
|
|
|
void applyDefaults();
|
|
|
|
};
|
|
|
|
|
2023-12-28 20:38:01 +01:00
|
|
|
class CConfigImpl {
|
|
|
|
public:
|
2023-12-29 13:26:21 +01:00
|
|
|
std::string path = "";
|
2023-12-28 20:38:01 +01:00
|
|
|
|
2023-12-29 13:26:21 +01:00
|
|
|
std::unordered_map<std::string, Hyprlang::CConfigValue> values;
|
2023-12-29 19:35:23 +01:00
|
|
|
std::unordered_map<std::string, SConfigDefaultValue> defaultValues;
|
2023-12-29 13:26:21 +01:00
|
|
|
std::vector<SHandler> handlers;
|
|
|
|
std::vector<SVariable> variables;
|
|
|
|
std::vector<SVariable> envVariables;
|
|
|
|
std::vector<std::unique_ptr<SSpecialCategory>> specialCategories;
|
|
|
|
std::vector<std::unique_ptr<SSpecialCategoryDescriptor>> specialCategoryDescriptors;
|
2023-12-28 20:38:01 +01:00
|
|
|
|
2023-12-29 13:26:21 +01:00
|
|
|
std::vector<std::string> categories;
|
|
|
|
std::string currentSpecialKey = "";
|
2023-12-28 20:38:01 +01:00
|
|
|
|
2023-12-29 13:26:21 +01:00
|
|
|
std::string parseError = "";
|
2023-12-28 20:38:01 +01:00
|
|
|
};
|