diff options
| author | M Matthew Hydock <mhydock@yahoo.com> | 2025-04-24 14:48:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-24 20:48:08 +0200 |
| commit | be6268a7ecea2ad50cdb78fb661884811a8a28e8 (patch) | |
| tree | ac5846bc109796f84c1d0abe095286de96a5967d /src | |
| parent | a9549dbca060b65ae6ec50f9bc68cdf1823d6cbe (diff) | |
groupbar: Add options for setting group bar title font weight (and indicator gap) (#9617)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/ConfigDataValues.hpp | 46 | ||||
| -rw-r--r-- | src/config/ConfigDescriptions.hpp | 18 | ||||
| -rw-r--r-- | src/config/ConfigManager.cpp | 25 | ||||
| -rw-r--r-- | src/render/OpenGL.cpp | 6 | ||||
| -rw-r--r-- | src/render/OpenGL.hpp | 42 | ||||
| -rw-r--r-- | src/render/decorations/CHyprGroupBarDecoration.cpp | 36 | ||||
| -rw-r--r-- | src/render/decorations/CHyprGroupBarDecoration.hpp | 4 |
7 files changed, 134 insertions, 43 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}); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index d3ac7962..3e9348d6 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -2714,7 +2714,7 @@ SP<CTexture> CHyprOpenGLImpl::loadAsset(const std::string& filename) { return tex; } -SP<CTexture> CHyprOpenGLImpl::renderText(const std::string& text, CHyprColor col, int pt, bool italic, const std::string& fontFamily, int maxWidth) { +SP<CTexture> CHyprOpenGLImpl::renderText(const std::string& text, CHyprColor col, int pt, bool italic, const std::string& fontFamily, int maxWidth, int weight) { SP<CTexture> tex = makeShared<CTexture>(); static auto FONT = CConfigValue<std::string>("misc:font_family"); @@ -2732,7 +2732,7 @@ SP<CTexture> CHyprOpenGLImpl::renderText(const std::string& text, CHyprColor col pango_font_description_set_family_static(pangoFD, FONTFAMILY.c_str()); pango_font_description_set_absolute_size(pangoFD, FONTSIZE * PANGO_SCALE); pango_font_description_set_style(pangoFD, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); - pango_font_description_set_weight(pangoFD, PANGO_WEIGHT_NORMAL); + pango_font_description_set_weight(pangoFD, static_cast<PangoWeight>(weight)); pango_layout_set_font_description(layoutText, pangoFD); cairo_set_source_rgba(CAIRO, COLOR.r, COLOR.g, COLOR.b, COLOR.a); @@ -2763,7 +2763,7 @@ SP<CTexture> CHyprOpenGLImpl::renderText(const std::string& text, CHyprColor col pango_font_description_set_family_static(pangoFD, FONTFAMILY.c_str()); pango_font_description_set_absolute_size(pangoFD, FONTSIZE * PANGO_SCALE); pango_font_description_set_style(pangoFD, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); - pango_font_description_set_weight(pangoFD, PANGO_WEIGHT_NORMAL); + pango_font_description_set_weight(pangoFD, static_cast<PangoWeight>(weight)); pango_layout_set_font_description(layoutText, pangoFD); pango_layout_set_text(layoutText, text.c_str(), -1); diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 276d5268..414ba103 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -224,35 +224,35 @@ class CHyprOpenGLImpl { void renderOffToMain(CFramebuffer* off); void bindBackOnMain(); - SP<CTexture> loadAsset(const std::string& file); - SP<CTexture> renderText(const std::string& text, CHyprColor col, int pt, bool italic = false, const std::string& fontFamily = "", int maxWidth = 0); + SP<CTexture> loadAsset(const std::string& file); + SP<CTexture> renderText(const std::string& text, CHyprColor col, int pt, bool italic = false, const std::string& fontFamily = "", int maxWidth = 0, int weight = 400); - void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {}); + void setDamage(const CRegion& damage, std::optional<CRegion> finalDamage = {}); - void ensureBackgroundTexturePresence(); + void ensureBackgroundTexturePresence(); - uint32_t getPreferredReadFormat(PHLMONITOR pMonitor); - std::vector<SDRMFormat> getDRMFormats(); - EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); - SP<CEGLSync> createEGLSync(int fence = -1); + uint32_t getPreferredReadFormat(PHLMONITOR pMonitor); + std::vector<SDRMFormat> getDRMFormats(); + EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs); + SP<CEGLSync> createEGLSync(int fence = -1); - bool initShaders(); - bool m_bShadersInitialized = false; - SP<SPreparedShaders> m_shaders; + bool initShaders(); + bool m_bShadersInitialized = false; + SP<SPreparedShaders> m_shaders; - SCurrentRenderData m_RenderData; + SCurrentRenderData m_RenderData; - Hyprutils::OS::CFileDescriptor m_iGBMFD; - gbm_device* m_pGbmDevice = nullptr; - EGLContext m_pEglContext = nullptr; - EGLDisplay m_pEglDisplay = nullptr; - EGLDeviceEXT m_pEglDevice = nullptr; - uint failedAssetsNo = 0; + Hyprutils::OS::CFileDescriptor m_iGBMFD; + gbm_device* m_pGbmDevice = nullptr; + EGLContext m_pEglContext = nullptr; + EGLDisplay m_pEglDisplay = nullptr; + EGLDeviceEXT m_pEglDevice = nullptr; + uint failedAssetsNo = 0; - bool m_bReloadScreenShader = true; // at launch it can be set + bool m_bReloadScreenShader = true; // at launch it can be set - std::map<PHLWINDOWREF, CFramebuffer> m_mWindowFramebuffers; - std::map<PHLLSREF, CFramebuffer> m_mLayerFramebuffers; + std::map<PHLWINDOWREF, CFramebuffer> m_mWindowFramebuffers; + std::map<PHLLSREF, CFramebuffer> m_mLayerFramebuffers; std::map<PHLMONITORREF, SMonitorRenderData> m_mMonitorRenderResources; std::map<PHLMONITORREF, CFramebuffer> m_mMonitorBGFBs; diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 50726514..7eca6d69 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -27,6 +27,7 @@ CHyprGroupBarDecoration::CHyprGroupBarDecoration(PHLWINDOW pWindow) : IHyprWindo SDecorationPositioningInfo CHyprGroupBarDecoration::getPositioningInfo() { static auto PHEIGHT = CConfigValue<Hyprlang::INT>("group:groupbar:height"); + static auto PINDICATORGAP = CConfigValue<Hyprlang::INT>("group:groupbar:indicator_gap"); static auto PINDICATORHEIGHT = CConfigValue<Hyprlang::INT>("group:groupbar:indicator_height"); static auto PENABLED = CConfigValue<Hyprlang::INT>("group:groupbar:enabled"); static auto PRENDERTITLES = CConfigValue<Hyprlang::INT>("group:groupbar:render_titles"); @@ -44,10 +45,10 @@ SDecorationPositioningInfo CHyprGroupBarDecoration::getPositioningInfo() { if (*PENABLED && m_pWindow->m_sWindowData.decorate.valueOrDefault()) { if (*PSTACKED) { - const auto ONEBARHEIGHT = *POUTERGAP + *PINDICATORHEIGHT + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0); + const auto ONEBARHEIGHT = *POUTERGAP + *PINDICATORHEIGHT + *PINDICATORGAP + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0); info.desiredExtents = {{0, (ONEBARHEIGHT * m_dwGroupMembers.size()) + (*PKEEPUPPERGAP * *POUTERGAP)}, {0, 0}}; } else - info.desiredExtents = {{0, *POUTERGAP * (1 + *PKEEPUPPERGAP) + *PINDICATORHEIGHT + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0)}, {0, 0}}; + info.desiredExtents = {{0, *POUTERGAP * (1 + *PKEEPUPPERGAP) + *PINDICATORHEIGHT + *PINDICATORGAP + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0)}, {0, 0}}; } else info.desiredExtents = {{0, 0}, {0, 0}}; return info; @@ -105,6 +106,7 @@ void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float const& a) { static auto PRENDERTITLES = CConfigValue<Hyprlang::INT>("group:groupbar:render_titles"); static auto PTITLEFONTSIZE = CConfigValue<Hyprlang::INT>("group:groupbar:font_size"); static auto PHEIGHT = CConfigValue<Hyprlang::INT>("group:groupbar:height"); + static auto PINDICATORGAP = CConfigValue<Hyprlang::INT>("group:groupbar:indicator_gap"); static auto PINDICATORHEIGHT = CConfigValue<Hyprlang::INT>("group:groupbar:indicator_height"); static auto PGRADIENTS = CConfigValue<Hyprlang::INT>("group:groupbar:gradients"); static auto PSTACKED = CConfigValue<Hyprlang::INT>("group:groupbar:stacked"); @@ -127,7 +129,7 @@ void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float const& a) { const auto ASSIGNEDBOX = assignedBoxGlobal(); - const auto ONEBARHEIGHT = *POUTERGAP + *PINDICATORHEIGHT + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0); + const auto ONEBARHEIGHT = *POUTERGAP + *PINDICATORHEIGHT + *PINDICATORGAP + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0); m_fBarWidth = *PSTACKED ? ASSIGNEDBOX.w : (ASSIGNEDBOX.w - *PINNERGAP * (barsToDraw - 1)) / barsToDraw; m_fBarHeight = *PSTACKED ? ((ASSIGNEDBOX.h - *POUTERGAP * *PKEEPUPPERGAP) - *POUTERGAP * (barsToDraw)) / barsToDraw : ASSIGNEDBOX.h - *POUTERGAP * *PKEEPUPPERGAP; @@ -141,7 +143,7 @@ void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float const& a) { for (int i = 0; i < barsToDraw; ++i) { const auto WINDOWINDEX = *PSTACKED ? m_dwGroupMembers.size() - i - 1 : i; - CBox rect = {ASSIGNEDBOX.x + floor(xoff) - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x, + CBox rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x, ASSIGNEDBOX.y + ASSIGNEDBOX.h - floor(yoff) - *PINDICATORHEIGHT - *POUTERGAP - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y, m_fBarWidth, *PINDICATORHEIGHT}; @@ -185,7 +187,7 @@ void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float const& a) { g_pHyprRenderer->m_sRenderPass.add(makeShared<CRectPassElement>(rectdata)); } - rect = {ASSIGNEDBOX.x + floor(xoff) - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x, + rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x, ASSIGNEDBOX.y + ASSIGNEDBOX.h - floor(yoff) - ONEBARHEIGHT - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y, m_fBarWidth, (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0)}; rect.scale(pMonitor->scale); @@ -235,14 +237,16 @@ void CHyprGroupBarDecoration::draw(PHLMONITOR pMonitor, float const& a) { .emplace_back(makeUnique<CTitleTex>(m_dwGroupMembers[WINDOWINDEX].lock(), Vector2D{m_fBarWidth * pMonitor->scale, (*PTITLEFONTSIZE + 2L * BAR_TEXT_PAD) * pMonitor->scale}, pMonitor->scale)) .get(); - rect.y += std::ceil(((rect.height - pTitleTex->texSize.y) / 2.0) - (*PTEXTOFFSET * pMonitor->scale)); - rect.height = pTitleTex->texSize.y; - rect.width = pTitleTex->texSize.x; - rect.x += std::round(((m_fBarWidth * pMonitor->scale) / 2.0) - (pTitleTex->texSize.x / 2.0)); + + const auto titleTex = m_dwGroupMembers[WINDOWINDEX] == g_pCompositor->m_lastWindow ? pTitleTex->texActive : pTitleTex->texInactive; + rect.y += std::ceil(((rect.height - titleTex->m_vSize.y) / 2.0) - (*PTEXTOFFSET * pMonitor->scale)); + rect.height = titleTex->m_vSize.y; + rect.width = titleTex->m_vSize.x; + rect.x += std::round(((m_fBarWidth * pMonitor->scale) / 2.0) - (titleTex->m_vSize.x / 2.0)); rect.round(); CTexPassElement::SRenderData data; - data.tex = pTitleTex->tex; + data.tex = titleTex; data.box = rect; data.a = a; g_pHyprRenderer->m_sRenderPass.add(makeShared<CTexPassElement>(data)); @@ -278,13 +282,17 @@ CTitleTex::CTitleTex(PHLWINDOW pWindow, const Vector2D& bufferSize, const float static auto PTITLEFONTSIZE = CConfigValue<Hyprlang::INT>("group:groupbar:font_size"); static auto PTEXTCOLOR = CConfigValue<Hyprlang::INT>("group:groupbar:text_color"); + static auto PTITLEFONTWEIGHTACTIVE = CConfigValue<Hyprlang::CUSTOMTYPE>("group:groupbar:font_weight_active"); + static auto PTITLEFONTWEIGHTINACTIVE = CConfigValue<Hyprlang::CUSTOMTYPE>("group:groupbar:font_weight_inactive"); + + const auto FONTWEIGHTACTIVE = (CFontWeightConfigValueData*)(PTITLEFONTWEIGHTACTIVE.ptr())->getData(); + const auto FONTWEIGHTINACTIVE = (CFontWeightConfigValueData*)(PTITLEFONTWEIGHTINACTIVE.ptr())->getData(); + const CHyprColor COLOR = CHyprColor(*PTEXTCOLOR); const auto FONTFAMILY = *PTITLEFONTFAMILY != STRVAL_EMPTY ? *PTITLEFONTFAMILY : *FALLBACKFONT; - tex = g_pHyprOpenGL->renderText(pWindow->m_szTitle, COLOR, *PTITLEFONTSIZE * monitorScale, false, FONTFAMILY, bufferSize.x - 2 /* some padding yk */); - - if (tex) - texSize = tex->m_vSize; + texActive = g_pHyprOpenGL->renderText(pWindow->m_szTitle, COLOR, *PTITLEFONTSIZE * monitorScale, false, FONTFAMILY, bufferSize.x - 2, FONTWEIGHTACTIVE->m_value); + texInactive = g_pHyprOpenGL->renderText(pWindow->m_szTitle, COLOR, *PTITLEFONTSIZE * monitorScale, false, FONTFAMILY, bufferSize.x - 2, FONTWEIGHTINACTIVE->m_value); } static void renderGradientTo(SP<CTexture> tex, CGradientValueData* grad) { diff --git a/src/render/decorations/CHyprGroupBarDecoration.hpp b/src/render/decorations/CHyprGroupBarDecoration.hpp index 0cdf8a6b..de087bce 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.hpp +++ b/src/render/decorations/CHyprGroupBarDecoration.hpp @@ -12,9 +12,9 @@ class CTitleTex { CTitleTex(PHLWINDOW pWindow, const Vector2D& bufferSize, const float monitorScale); ~CTitleTex() = default; - SP<CTexture> tex; + SP<CTexture> texActive; + SP<CTexture> texInactive; std::string szContent; - Vector2D texSize; PHLWINDOWREF pWindowOwner; }; |
