groupbar: Add options for setting group bar title font weight (and indicator gap) (#9617)

This commit is contained in:
M Matthew Hydock 2025-04-24 14:48:08 -04:00 committed by GitHub
parent a9549dbca0
commit be6268a7ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 134 additions and 43 deletions

View file

@ -2,11 +2,13 @@
#include "../defines.hpp"
#include "../helpers/varlist/VarList.hpp"
#include <vector>
#include <map>
enum eConfigValueDataTypes : int8_t {
CVD_TYPE_INVALID = -1,
CVD_TYPE_GRADIENT = 0,
CVD_TYPE_CSS_VALUE = 1
CVD_TYPE_INVALID = -1,
CVD_TYPE_GRADIENT = 0,
CVD_TYPE_CSS_VALUE = 1,
CVD_TYPE_FONT_WEIGHT = 2,
};
class ICustomConfigValueData {
@ -136,3 +138,41 @@ class CCssGapData : public ICustomConfigValueData {
return std::format("{} {} {} {}", m_top, m_right, m_bottom, m_left);
}
};
class CFontWeightConfigValueData : public ICustomConfigValueData {
public:
CFontWeightConfigValueData() = default;
CFontWeightConfigValueData(const char* weight) {
parseWeight(weight);
}
int64_t m_value = 400; // default to normal weight
virtual eConfigValueDataTypes getDataType() {
return CVD_TYPE_FONT_WEIGHT;
}
virtual std::string toString() {
return std::format("{}", m_value);
}
void parseWeight(const std::string& strWeight) {
auto lcWeight{strWeight};
transform(strWeight.begin(), strWeight.end(), lcWeight.begin(), ::tolower);
// values taken from Pango weight enums
const auto WEIGHTS = std::map<std::string, int>{
{"thin", 100}, {"ultralight", 200}, {"light", 300}, {"semilight", 350}, {"book", 380}, {"normal", 400},
{"medium", 500}, {"semibold", 600}, {"bold", 700}, {"ultrabold", 800}, {"heavy", 900}, {"ultraheavy", 1000},
};
auto weight = WEIGHTS.find(lcWeight);
if (weight != WEIGHTS.end())
m_value = weight->second;
else {
int w_i = std::stoi(strWeight);
if (w_i < 100 || w_i > 1000)
m_value = 400;
}
}
};

View file

@ -897,6 +897,18 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_STRING_SHORT,
.data = SConfigOptionDescription::SStringData{STRVAL_EMPTY}, //##TODO UNSET?
},
SConfigOptionDescription{
.value = "group:groupbar:font_weight_active",
.description = "weight of the font used to display active groupbar titles",
.type = CONFIG_OPTION_STRING_SHORT,
.data = SConfigOptionDescription::SStringData{"normal"},
},
SConfigOptionDescription{
.value = "group:groupbar:font_weight_inactive",
.description = "weight of the font used to display inactive groupbar titles",
.type = CONFIG_OPTION_STRING_SHORT,
.data = SConfigOptionDescription::SStringData{"normal"},
},
SConfigOptionDescription{
.value = "group:groupbar:font_size",
.description = "font size of groupbar title",
@ -915,6 +927,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_INT,
.data = SConfigOptionDescription::SRangeData{14, 1, 64},
},
SConfigOptionDescription{
.value = "group:groupbar:indicator_gap",
.description = "height of the gap between the groupbar indicator and title",
.type = CONFIG_OPTION_INT,
.data = SConfigOptionDescription::SRangeData{0, 0, 64},
},
SConfigOptionDescription{
.value = "group:groupbar:indicator_height",
.description = "height of the groupbar indicator",

View file

@ -147,6 +147,28 @@ static void configHandleGapDestroy(void** data) {
delete reinterpret_cast<CCssGapData*>(*data);
}
static Hyprlang::CParseResult configHandleFontWeightSet(const char* VALUE, void** data) {
if (!*data)
*data = new CFontWeightConfigValueData();
const auto DATA = reinterpret_cast<CFontWeightConfigValueData*>(*data);
Hyprlang::CParseResult result;
try {
DATA->parseWeight(VALUE);
} catch (...) {
std::string parseError = std::format("{} is not a valid font weight", VALUE);
result.setError(parseError.c_str());
}
return result;
}
static void configHandleFontWeightDestroy(void** data) {
if (*data)
delete reinterpret_cast<CFontWeightConfigValueData*>(*data);
}
static Hyprlang::CParseResult handleExec(const char* c, const char* v) {
const std::string VALUE = v;
const std::string COMMAND = c;
@ -485,9 +507,12 @@ CConfigManager::CConfigManager() {
registerConfigVar("group:group_on_movetoworkspace", Hyprlang::INT{0});
registerConfigVar("group:groupbar:enabled", Hyprlang::INT{1});
registerConfigVar("group:groupbar:font_family", {STRVAL_EMPTY});
registerConfigVar("group:groupbar:font_weight_active", Hyprlang::CConfigCustomValueType{&configHandleFontWeightSet, configHandleFontWeightDestroy, "normal"});
registerConfigVar("group:groupbar:font_weight_inactive", Hyprlang::CConfigCustomValueType{&configHandleFontWeightSet, configHandleFontWeightDestroy, "normal"});
registerConfigVar("group:groupbar:font_size", Hyprlang::INT{8});
registerConfigVar("group:groupbar:gradients", Hyprlang::INT{0});
registerConfigVar("group:groupbar:height", Hyprlang::INT{14});
registerConfigVar("group:groupbar:indicator_gap", Hyprlang::INT{0});
registerConfigVar("group:groupbar:indicator_height", Hyprlang::INT{3});
registerConfigVar("group:groupbar:priority", Hyprlang::INT{3});
registerConfigVar("group:groupbar:render_titles", Hyprlang::INT{1});