mirror of
https://github.com/hyprwm/hyprland-plugins.git
synced 2024-11-22 02:35:57 +01:00
hyprbars: add bar_color & title_color windowrules (#192)
* hyprbars: add bar_color & title_color windowrules * hyprbars: fix if formatting * hyprbars: format
This commit is contained in:
parent
7a28245e5a
commit
b73d7b901d
4 changed files with 63 additions and 35 deletions
|
@ -59,3 +59,5 @@ hyprbars-button = color, size, icon, on-click
|
||||||
Hyprbars supports the following _dynamic_ window rules:
|
Hyprbars supports the following _dynamic_ window rules:
|
||||||
|
|
||||||
`plugin:hyprbars:nobar` -> disables the bar on matching windows.
|
`plugin:hyprbars:nobar` -> disables the bar on matching windows.
|
||||||
|
`plugin:hyprbars:bar_color` -> sets the bar background color on matching windows.
|
||||||
|
`plugin:hyprbars:title_color` -> sets the bar title color on matching windows.
|
||||||
|
|
|
@ -220,7 +220,7 @@ void CHyprBar::renderBarTitle(const Vector2D& bufferSize, const float scale) {
|
||||||
const auto scaledButtonsPad = **PBARBUTTONPADDING * scale;
|
const auto scaledButtonsPad = **PBARBUTTONPADDING * scale;
|
||||||
const auto scaledBarPadding = **PBARPADDING * scale;
|
const auto scaledBarPadding = **PBARPADDING * scale;
|
||||||
|
|
||||||
const CColor COLOR = **PCOLOR;
|
const CColor COLOR = m_bForcedTitleColor.value_or(**PCOLOR);
|
||||||
|
|
||||||
const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y);
|
const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y);
|
||||||
const auto CAIRO = cairo_create(CAIROSURFACE);
|
const auto CAIRO = cairo_create(CAIROSURFACE);
|
||||||
|
@ -412,7 +412,7 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
|
||||||
|
|
||||||
const auto scaledRounding = ROUNDING > 0 ? ROUNDING * pMonitor->scale - 2 /* idk why but otherwise it looks bad due to the gaps */ : 0;
|
const auto scaledRounding = ROUNDING > 0 ? ROUNDING * pMonitor->scale - 2 /* idk why but otherwise it looks bad due to the gaps */ : 0;
|
||||||
|
|
||||||
CColor color = **PCOLOR;
|
CColor color = m_bForcedBarColor.value_or(**PCOLOR);
|
||||||
color.a *= a;
|
color.a *= a;
|
||||||
|
|
||||||
m_seExtents = {{0, **PHEIGHT}, {}};
|
m_seExtents = {{0, **PHEIGHT}, {}};
|
||||||
|
@ -461,7 +461,7 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
|
||||||
g_pHyprOpenGL->renderRect(&titleBarBox, color, scaledRounding);
|
g_pHyprOpenGL->renderRect(&titleBarBox, color, scaledRounding);
|
||||||
|
|
||||||
// render title
|
// render title
|
||||||
if (**PENABLETITLE && (m_szLastTitle != PWINDOW->m_szTitle || m_bWindowSizeChanged || m_pTextTex->m_iTexID == 0)) {
|
if (**PENABLETITLE && (m_szLastTitle != PWINDOW->m_szTitle || m_bWindowSizeChanged || m_pTextTex->m_iTexID == 0 || m_bTitleColorChanged)) {
|
||||||
m_szLastTitle = PWINDOW->m_szTitle;
|
m_szLastTitle = PWINDOW->m_szTitle;
|
||||||
renderBarTitle(BARBUF, pMonitor->scale);
|
renderBarTitle(BARBUF, pMonitor->scale);
|
||||||
}
|
}
|
||||||
|
@ -491,6 +491,7 @@ void CHyprBar::draw(CMonitor* pMonitor, float a) {
|
||||||
renderBarButtonsText(&textBox, pMonitor->scale, a);
|
renderBarButtonsText(&textBox, pMonitor->scale, a);
|
||||||
|
|
||||||
m_bWindowSizeChanged = false;
|
m_bWindowSizeChanged = false;
|
||||||
|
m_bTitleColorChanged = false;
|
||||||
|
|
||||||
// dynamic updates change the extents
|
// dynamic updates change the extents
|
||||||
if (m_iLastHeight != **PHEIGHT) {
|
if (m_iLastHeight != **PHEIGHT) {
|
||||||
|
@ -540,11 +541,33 @@ PHLWINDOW CHyprBar::getOwner() {
|
||||||
return m_pWindow.lock();
|
return m_pWindow.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHyprBar::setHidden(bool hidden) {
|
void CHyprBar::updateRules() {
|
||||||
if (m_bHidden == hidden)
|
const auto PWINDOW = m_pWindow.lock();
|
||||||
return;
|
auto rules = PWINDOW->m_vMatchedRules;
|
||||||
|
auto prev_m_bHidden = m_bHidden;
|
||||||
|
auto prev_m_bForcedTitleColor = m_bForcedTitleColor;
|
||||||
|
|
||||||
m_bHidden = hidden;
|
m_bForcedBarColor = std::nullopt;
|
||||||
|
m_bForcedTitleColor = std::nullopt;
|
||||||
|
m_bHidden = false;
|
||||||
|
|
||||||
|
for (auto& r : rules) {
|
||||||
|
applyRule(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev_m_bHidden != m_bHidden)
|
||||||
g_pDecorationPositioner->repositionDeco(this);
|
g_pDecorationPositioner->repositionDeco(this);
|
||||||
|
if (prev_m_bForcedTitleColor != m_bForcedTitleColor)
|
||||||
|
m_bTitleColorChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHyprBar::applyRule(const SWindowRule& r) {
|
||||||
|
auto arg = r.szRule.substr(r.szRule.find_first_of(' ') + 1);
|
||||||
|
|
||||||
|
if (r.szRule == "plugin:hyprbars:nobar")
|
||||||
|
m_bHidden = true;
|
||||||
|
else if (r.szRule.starts_with("plugin:hyprbars:bar_color"))
|
||||||
|
m_bForcedBarColor = CColor(configStringToInt(arg));
|
||||||
|
else if (r.szRule.starts_with("plugin:hyprbars:title_color"))
|
||||||
|
m_bForcedTitleColor = CColor(configStringToInt(arg));
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ class CHyprBar : public IHyprWindowDecoration {
|
||||||
|
|
||||||
PHLWINDOW getOwner();
|
PHLWINDOW getOwner();
|
||||||
|
|
||||||
void setHidden(bool hidden);
|
void updateRules();
|
||||||
|
void applyRule(const SWindowRule&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SBoxExtents m_seExtents;
|
SBoxExtents m_seExtents;
|
||||||
|
@ -48,6 +49,9 @@ class CHyprBar : public IHyprWindowDecoration {
|
||||||
|
|
||||||
bool m_bWindowSizeChanged = false;
|
bool m_bWindowSizeChanged = false;
|
||||||
bool m_bHidden = false;
|
bool m_bHidden = false;
|
||||||
|
bool m_bTitleColorChanged = false;
|
||||||
|
std::optional<CColor> m_bForcedBarColor;
|
||||||
|
std::optional<CColor> m_bForcedTitleColor;
|
||||||
|
|
||||||
Vector2D cursorRelativeToBar();
|
Vector2D cursorRelativeToBar();
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,8 @@ static void onUpdateWindowRules(PHLWINDOW window) {
|
||||||
if (BARIT == g_pGlobalState->bars.end())
|
if (BARIT == g_pGlobalState->bars.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto HASNOBAR = std::find_if(window->m_vMatchedRules.begin(), window->m_vMatchedRules.end(), [](const auto& rule) { return rule.szRule == "plugin:hyprbars:nobar"; }) != window->m_vMatchedRules.end();
|
(*BARIT)->updateRules();
|
||||||
|
window->updateWindowDecos();
|
||||||
(*BARIT)->setHidden(HASNOBAR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Hyprlang::CParseResult onNewButton(const char* K, const char* V) {
|
Hyprlang::CParseResult onNewButton(const char* K, const char* V) {
|
||||||
|
|
Loading…
Reference in a new issue