hyprbars: add align left

This commit is contained in:
Vaxry 2023-12-13 00:46:12 +00:00
parent 9099c480d8
commit ed16998aad
3 changed files with 8 additions and 4 deletions

View file

@ -24,13 +24,15 @@ plugin {
`bar_color` -> (col) bar's background color `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 `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) `bar_part_of_window` -> (bool) whether the bar is a part of the main window (if it is, stuff like shadows render around it)

View file

@ -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 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 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 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(); const auto BORDERSIZE = m_pWindow->getRealBorderSize();
@ -229,7 +230,7 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) {
int layoutWidth, layoutHeight; int layoutWidth, layoutHeight;
pango_layout_get_size(layout, &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)); const int yOffset = std::round((bufferSize.y / 2.0 - layoutHeight / PANGO_SCALE / 2.0));
cairo_move_to(CAIRO, xOffset, yOffset); cairo_move_to(CAIRO, xOffset, yOffset);

View file

@ -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: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_size", SConfigValue{.intValue = 10});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font", SConfigValue{.strValue = "Sans"}); 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::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); }); HyprlandAPI::addConfigKeyword(PHANDLE, "hyprbars-button", [&](const std::string& k, const std::string& v) { onNewButton(k, v); });