From be6268a7ecea2ad50cdb78fb661884811a8a28e8 Mon Sep 17 00:00:00 2001 From: M Matthew Hydock Date: Thu, 24 Apr 2025 14:48:08 -0400 Subject: groupbar: Add options for setting group bar title font weight (and indicator gap) (#9617) --- src/config/ConfigDataValues.hpp | 46 ++++++++++++++++++++++++++++++++++++--- src/config/ConfigDescriptions.hpp | 18 +++++++++++++++ src/config/ConfigManager.cpp | 25 +++++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) (limited to 'src/config') diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp index 270f6880..2fad9277 100644 --- a/src/config/ConfigDataValues.hpp +++ b/src/config/ConfigDataValues.hpp @@ -2,11 +2,13 @@ #include "../defines.hpp" #include "../helpers/varlist/VarList.hpp" #include +#include 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{ + {"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; + } + } +}; diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 78b9f559..236f4d6e 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -897,6 +897,18 @@ inline static const std::vector 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 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", diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4bd00c99..f609eeb4 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -147,6 +147,28 @@ static void configHandleGapDestroy(void** data) { delete reinterpret_cast(*data); } +static Hyprlang::CParseResult configHandleFontWeightSet(const char* VALUE, void** data) { + if (!*data) + *data = new CFontWeightConfigValueData(); + + const auto DATA = reinterpret_cast(*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(*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}); -- cgit v1.2.3