Skip to content

Commit

Permalink
hyprbars: add an option to blur the bar
Browse files Browse the repository at this point in the history
fixes #61
  • Loading branch information
vaxerski committed Dec 22, 2024
1 parent 8a29b42 commit 0b808a5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
14 changes: 13 additions & 1 deletion hyprbars/BarPassElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ void CBarPassElement::draw(const CRegion& damage) {
}

bool CBarPassElement::needsLiveBlur() {
return false;
static auto* const PCOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_color")->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();

CHyprColor color = data.deco->m_bForcedBarColor.value_or(**PCOLOR);
color.a *= data.a;
const bool SHOULDBLUR = **PENABLEBLUR && **PENABLEBLURGLOBAL && color.a < 1.F;

return SHOULDBLUR;
}

std::optional<CBox> CBarPassElement::boundingBox() {
return data.deco->assignedBoxGlobal().translate(-g_pHyprOpenGL->m_RenderData.pMonitor->vecPosition);
}

bool CBarPassElement::needsPrecomputeBlur() {
Expand Down
9 changes: 5 additions & 4 deletions hyprbars/BarPassElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class CBarPassElement : public IPassElement {
CBarPassElement(const SBarData& data_);
virtual ~CBarPassElement() = default;

virtual void draw(const CRegion& damage);
virtual bool needsLiveBlur();
virtual bool needsPrecomputeBlur();
virtual void draw(const CRegion& damage);
virtual bool needsLiveBlur();
virtual bool needsPrecomputeBlur();
virtual std::optional<CBox> boundingBox();

virtual const char* passName() {
virtual const char* passName() {
return "CBarPassElement";
}

Expand Down
2 changes: 2 additions & 0 deletions hyprbars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ plugin {

`bar_height` -> (int) bar's height (default `15`)

`bar_blur` -> (bool) whether to blur the bar. Also requires the global blur to be enabled.

`col.text` -> (col) bar's title text color

`bar_title_enabled` -> (bool) whether to render the title (default `true`)
Expand Down
25 changes: 15 additions & 10 deletions hyprbars/barDeco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,18 @@ void CHyprBar::draw(PHLMONITOR pMonitor, const float& a) {
void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) {
const auto PWINDOW = m_pWindow.lock();

static auto* const PCOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_color")->getDataStaticPtr();
static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr();
static auto* const PPRECEDENCE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_precedence_over_border")->getDataStaticPtr();
static auto* const PALIGNBUTTONS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->getDataStaticPtr();
static auto* const PENABLETITLE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_title_enabled")->getDataStaticPtr();
static auto* const PCOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_color")->getDataStaticPtr();
static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr();
static auto* const PPRECEDENCE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_precedence_over_border")->getDataStaticPtr();
static auto* const PALIGNBUTTONS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_buttons_alignment")->getDataStaticPtr();
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();

const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left";
CHyprColor color = m_bForcedBarColor.value_or(**PCOLOR);
color.a *= a;
const bool BUTTONSRIGHT = std::string{*PALIGNBUTTONS} != "left";
const bool SHOULDBLUR = **PENABLEBLUR && **PENABLEBLURGLOBAL && color.a < 1.F;

if (**PHEIGHT < 1) {
m_iLastHeight = **PHEIGHT;
Expand All @@ -429,9 +434,6 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) {

const auto scaledRounding = ROUNDING > 0 ? ROUNDING * pMonitor->scale - 2 /* idk why but otherwise it looks bad due to the gaps */ : 0;

CHyprColor color = m_bForcedBarColor.value_or(**PCOLOR);
color.a *= a;

m_seExtents = {{0, **PHEIGHT}, {}};

const auto DECOBOX = assignedBoxGlobal();
Expand Down Expand Up @@ -475,7 +477,10 @@ void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) {
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
}

g_pHyprOpenGL->renderRect(&titleBarBox, color, scaledRounding);
if (SHOULDBLUR)
g_pHyprOpenGL->renderRectWithBlur(&titleBarBox, color, scaledRounding);
else
g_pHyprOpenGL->renderRect(&titleBarBox, color, scaledRounding);

// render title
if (**PENABLETITLE && (m_szLastTitle != PWINDOW->m_szTitle || m_bWindowSizeChanged || m_pTextTex->m_iTexID == 0 || m_bTitleColorChanged)) {
Expand Down
1 change: 1 addition & 0 deletions hyprbars/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:col.text", Hyprlang::INT{*configStringToInt("rgba(ffffffff)")});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_size", Hyprlang::INT{10});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_title_enabled", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_blur", Hyprlang::INT{0});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_font", Hyprlang::STRING{"Sans"});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_text_align", Hyprlang::STRING{"center"});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprbars:bar_part_of_window", Hyprlang::INT{1});
Expand Down

0 comments on commit 0b808a5

Please sign in to comment.