hyprbars: add inactive_button_color option (#383)

This commit is contained in:
Khalid 2025-06-17 21:18:59 +03:00 committed by GitHub
parent 4783860953
commit c0e675dd87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 1 deletions

View File

@ -55,6 +55,8 @@ plugin {
`icon_on_hover` -> (bool) whether the icons show on mouse hovering over the buttons (default `false`)
`inactive_button_color` -> (col) buttons bg color when window isn't focused
`on_double_click` -> (str) command to run on double click of the bar (not on a button)
## Buttons Config

View File

@ -428,6 +428,7 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
static auto* const PBARBUTTONPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->getDataStaticPtr();
static auto* const PBARPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->getDataStaticPtr();
static auto* const PALIGNBUTTONS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->getDataStaticPtr();
static auto* const PINACTIVECOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:inactive_button_color")->getDataStaticPtr();
const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left";
const auto visibleCount = getVisibleButtonCount(PBARBUTTONPADDING, PBARPADDING, bufferSize, scale);
@ -449,8 +450,15 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
const auto scaledButtonsPad = **PBARBUTTONPADDING * scale;
const auto pos = Vector2D{BUTTONSRIGHT ? bufferSize.x - offset - scaledButtonSize / 2.0 : offset + scaledButtonSize / 2.0, bufferSize.y / 2.0}.floor();
auto color = button.bgcol;
cairo_set_source_rgba(CAIRO, button.bgcol.r, button.bgcol.g, button.bgcol.b, button.bgcol.a);
if (**PINACTIVECOLOR > 0) {
color = m_bWindowHasFocus ? color : CHyprColor(**PINACTIVECOLOR);
if (button.userfg && button.iconTex->m_texID != 0)
button.iconTex->destroyTexture();
}
cairo_set_source_rgba(CAIRO, color.r, color.g, color.b, color.a);
cairo_arc(CAIRO, pos.x, pos.y, scaledButtonSize / 2, 0, 2 * M_PI);
cairo_fill(CAIRO);
@ -558,6 +566,15 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) {
static auto* const PENABLETITLE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_title_enabled")->getDataStaticPtr();
static auto* const PENABLEBLUR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_blur")->getDataStaticPtr();
static auto* const PENABLEBLURGLOBAL = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "decoration:blur:enabled")->getDataStaticPtr();
static auto* const PINACTIVECOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:inactive_button_color")->getDataStaticPtr();
if (**PINACTIVECOLOR > 0) {
bool currentWindowFocus = PWINDOW == g_pCompositor->m_lastWindow.lock();
if (currentWindowFocus != m_bWindowHasFocus) {
m_bWindowHasFocus = currentWindowFocus;
m_bButtonsDirty = true;
}
}
const CHyprColor DEST_COLOR = m_bForcedBarColor.value_or(**PCOLOR);
if (DEST_COLOR != m_cRealBarColor->goal())

View File

@ -62,6 +62,7 @@ class CHyprBar : public IHyprWindowDecoration {
bool m_bTitleColorChanged = false;
bool m_bButtonHovered = false;
bool m_bLastEnabledState = false;
bool m_bWindowHasFocus = false;
std::optional<CHyprColor> m_bForcedBarColor;
std::optional<CHyprColor> m_bForcedTitleColor;

View File

@ -142,6 +142,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding", Hyprlang::INT{5});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:enabled", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:icon_on_hover", Hyprlang::INT{0});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:inactive_button_color", Hyprlang::INT{0}); // unset
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:on_double_click", Hyprlang::STRING{""});
HyprlandAPI::addConfigKeyword(PHANDLE, "hyprbars-button", onNewButton, Hyprlang::SHandlerOptions{});