From ed16998aad7167d807571aaba95befaf7068a8bc Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 13 Dec 2023 00:46:12 +0000 Subject: [PATCH] hyprbars: add align left --- hyprbars/README.md | 8 +++++--- hyprbars/barDeco.cpp | 3 ++- hyprbars/main.cpp | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hyprbars/README.md b/hyprbars/README.md index 30c7fde..547eae0 100644 --- a/hyprbars/README.md +++ b/hyprbars/README.md @@ -24,13 +24,15 @@ plugin { `bar_color` -> (col) bar's background color -`bar_height` -> (int) bar's height (default 15) +`bar_height` -> (int) bar's height (default `15`) `col.text` -> (col) bar's title text color -`bar_text_size` -> (int) bar's title text font size (default 10) +`bar_text_size` -> (int) bar's title text font size (default `10`) -`bar_text_font` -> (str) bar's title text font (default "Sans") +`bar_text_font` -> (str) bar's title text font (default `Sans`) + +`bar_text_align` -> (str) bar's title text alignment (default `center`, can also be `left`) `bar_part_of_window` -> (bool) whether the bar is a part of the main window (if it is, stuff like shadows render around it) diff --git a/hyprbars/barDeco.cpp b/hyprbars/barDeco.cpp index 74ae468..f7634e4 100644 --- a/hyprbars/barDeco.cpp +++ b/hyprbars/barDeco.cpp @@ -184,6 +184,7 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) { static auto* const PCOLOR = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:col.text")->intValue; static auto* const PSIZE = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_size")->intValue; static auto* const PFONT = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font")->strValue; + static auto* const PALIGN = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_text_align")->strValue; const auto BORDERSIZE = m_pWindow->getRealBorderSize(); @@ -229,7 +230,7 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) { int layoutWidth, layoutHeight; pango_layout_get_size(layout, &layoutWidth, &layoutHeight); - const int xOffset = std::round(((bufferSize.x - scaledBorderSize) / 2.0 - layoutWidth / PANGO_SCALE / 2.0)); + const int xOffset = *PALIGN == "left" ? std::round(scaledBarPadding) : std::round(((bufferSize.x - scaledBorderSize) / 2.0 - layoutWidth / PANGO_SCALE / 2.0)); const int yOffset = std::round((bufferSize.y / 2.0 - layoutHeight / PANGO_SCALE / 2.0)); cairo_move_to(CAIRO, xOffset, yOffset); diff --git a/hyprbars/main.cpp b/hyprbars/main.cpp index 6a68c11..81c1b9c 100644 --- a/hyprbars/main.cpp +++ b/hyprbars/main.cpp @@ -70,6 +70,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) { HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:col.text", SConfigValue{.intValue = configStringToInt("rgba(ffffffff)")}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_size", SConfigValue{.intValue = 10}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font", SConfigValue{.strValue = "Sans"}); + HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_align", SConfigValue{.strValue = "center"}); HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_part_of_window", SConfigValue{.intValue = 1}); HyprlandAPI::addConfigKeyword(PHANDLE, "hyprbars-button", [&](const std::string& k, const std::string& v) { onNewButton(k, v); });