summaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
authorM Matthew Hydock <mhydock@yahoo.com>2025-04-24 14:48:08 -0400
committerGitHub <noreply@github.com>2025-04-24 20:48:08 +0200
commitbe6268a7ecea2ad50cdb78fb661884811a8a28e8 (patch)
treeac5846bc109796f84c1d0abe095286de96a5967d /src/config
parenta9549dbca060b65ae6ec50f9bc68cdf1823d6cbe (diff)
groupbar: Add options for setting group bar title font weight (and indicator gap) (#9617)
Diffstat (limited to 'src/config')
-rw-r--r--src/config/ConfigDataValues.hpp46
-rw-r--r--src/config/ConfigDescriptions.hpp18
-rw-r--r--src/config/ConfigManager.cpp25
3 files changed, 86 insertions, 3 deletions
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 <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;
+ }
+ }
+};
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
@@ -898,6 +898,18 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.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",
.type = CONFIG_OPTION_INT,
@@ -916,6 +928,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.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",
.type = CONFIG_OPTION_INT,
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<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});