Skip to content

Commit c0e675d

Browse files
authored
hyprbars: add inactive_button_color option (#383)
1 parent 4783860 commit c0e675d

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

hyprbars/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ plugin {
5555

5656
`icon_on_hover` -> (bool) whether the icons show on mouse hovering over the buttons (default `false`)
5757

58+
`inactive_button_color` -> (col) buttons bg color when window isn't focused
59+
5860
`on_double_click` -> (str) command to run on double click of the bar (not on a button)
5961

6062
## Buttons Config

hyprbars/barDeco.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
428428
static auto* const PBARBUTTONPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->getDataStaticPtr();
429429
static auto* const PBARPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->getDataStaticPtr();
430430
static auto* const PALIGNBUTTONS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->getDataStaticPtr();
431+
static auto* const PINACTIVECOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:inactive_button_color")->getDataStaticPtr();
431432

432433
const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left";
433434
const auto visibleCount = getVisibleButtonCount(PBARBUTTONPADDING, PBARPADDING, bufferSize, scale);
@@ -449,8 +450,15 @@ void CHyprBar::renderBarButtons(const Vector2D& bufferSize, const float scale) {
449450
const auto scaledButtonsPad = **PBARBUTTONPADDING * scale;
450451

451452
const auto pos = Vector2D{BUTTONSRIGHT ? bufferSize.x - offset - scaledButtonSize / 2.0 : offset + scaledButtonSize / 2.0, bufferSize.y / 2.0}.floor();
453+
auto color = button.bgcol;
452454

453-
cairo_set_source_rgba(CAIRO, button.bgcol.r, button.bgcol.g, button.bgcol.b, button.bgcol.a);
455+
if (**PINACTIVECOLOR > 0) {
456+
color = m_bWindowHasFocus ? color : CHyprColor(**PINACTIVECOLOR);
457+
if (button.userfg && button.iconTex->m_texID != 0)
458+
button.iconTex->destroyTexture();
459+
}
460+
461+
cairo_set_source_rgba(CAIRO, color.r, color.g, color.b, color.a);
454462
cairo_arc(CAIRO, pos.x, pos.y, scaledButtonSize / 2, 0, 2 * M_PI);
455463
cairo_fill(CAIRO);
456464

@@ -558,6 +566,15 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) {
558566
static auto* const PENABLETITLE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_title_enabled")->getDataStaticPtr();
559567
static auto* const PENABLEBLUR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_blur")->getDataStaticPtr();
560568
static auto* const PENABLEBLURGLOBAL = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "decoration:blur:enabled")->getDataStaticPtr();
569+
static auto* const PINACTIVECOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:inactive_button_color")->getDataStaticPtr();
570+
571+
if (**PINACTIVECOLOR > 0) {
572+
bool currentWindowFocus = PWINDOW == g_pCompositor->m_lastWindow.lock();
573+
if (currentWindowFocus != m_bWindowHasFocus) {
574+
m_bWindowHasFocus = currentWindowFocus;
575+
m_bButtonsDirty = true;
576+
}
577+
}
561578

562579
const CHyprColor DEST_COLOR = m_bForcedBarColor.value_or(**PCOLOR);
563580
if (DEST_COLOR != m_cRealBarColor->goal())

hyprbars/barDeco.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class CHyprBar : public IHyprWindowDecoration {
6262
bool m_bTitleColorChanged = false;
6363
bool m_bButtonHovered = false;
6464
bool m_bLastEnabledState = false;
65+
bool m_bWindowHasFocus = false;
6566
std::optional<CHyprColor> m_bForcedBarColor;
6667
std::optional<CHyprColor> m_bForcedTitleColor;
6768

hyprbars/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
142142
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding", Hyprlang::INT{5});
143143
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:enabled", Hyprlang::INT{1});
144144
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:icon_on_hover", Hyprlang::INT{0});
145+
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:inactive_button_color", Hyprlang::INT{0}); // unset
145146
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:on_double_click", Hyprlang::STRING{""});
146147

147148
HyprlandAPI::addConfigKeyword(PHANDLE, "hyprbars-button", onNewButton, Hyprlang::SHandlerOptions{});

0 commit comments

Comments
 (0)