Skip to content

Commit

Permalink
api: add some qol stuff needed by hyprland
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Feb 9, 2024
1 parent ab00791 commit f5056f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions include/hyprlang.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,15 @@ namespace Hyprlang {
CConfigValue(const STRING value);
CConfigValue(const VEC2 value);
CConfigValue(CUSTOMTYPE&& value);
CConfigValue(const CConfigValue&) = delete;
CConfigValue(CConfigValue&&) = delete;
CConfigValue(const CConfigValue&&) = delete;
CConfigValue(CConfigValue&) = delete;

/*!
\since 0.3.0
*/
CConfigValue(const CConfigValue&);

~CConfigValue();

/*!
Expand Down Expand Up @@ -292,10 +297,17 @@ namespace Hyprlang {
void removeSpecialCategory(const char* name);

/*!
\since 0.3.0
Add a config value to a special category.
*/
void addSpecialConfigValue(const char* cat, const char* name, const CConfigValue value);

/*!
Remove a config value from a special category.
*/
void removeSpecialConfigValue(const char* cat, const char* name);

/*!
Parse the config. Refresh the values.
*/
Expand Down Expand Up @@ -323,7 +335,7 @@ namespace Hyprlang {

/*!
Get a special category's config value ptr. These are only static for static (key-less)
categories, unless a new variable is added via addSpecialConfigValue.
categories, unless a new variable is added via addSpecialConfigValue or removed via removeSpecialConfigValue.
key can be nullptr for static categories. Cannot be nullptr for id-based categories.
nullptr on fail.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ CConfigValue::CConfigValue(CConfigCustomValueType&& value) {
m_eType = CONFIGDATATYPE_CUSTOM;
}

CConfigValue::CConfigValue(const CConfigValue& other) {
m_eType = other.m_eType;
setFrom(other.getValue());
}

CConfigValue::CConfigValue() {
;
}
Expand Down
9 changes: 9 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ void CConfig::addSpecialConfigValue(const char* cat, const char* name, const CCo
reinterpret_cast<CConfigCustomValueType*>(value.m_pData)->dtor});
}

void CConfig::removeSpecialConfigValue(const char* cat, const char* name) {
const auto IT = std::find_if(impl->specialCategoryDescriptors.begin(), impl->specialCategoryDescriptors.end(), [&](const auto& other) { return other->name == cat; });

if (IT == impl->specialCategoryDescriptors.end())
throw "No such category";

std::erase_if(IT->get()->defaultValues, [name](const auto& other) { return other.first == name; });
}

void CConfig::addSpecialCategory(const char* name, SSpecialCategoryOptions options) {
const auto PDESC = impl->specialCategoryDescriptors.emplace_back(std::make_unique<SSpecialCategoryDescriptor>()).get();
PDESC->name = name;
Expand Down

0 comments on commit f5056f7

Please sign in to comment.