mirror of
https://github.com/hyprwm/hyprland-plugins.git
synced 2026-08-18 11:14:01 +00:00
hyprbars: fix windowrules
This commit is contained in:
@ -573,7 +573,7 @@ void CHyprBar::draw(PHLMONITOR pMonitor, const float& a) {
|
||||
|
||||
const auto PWINDOW = m_pWindow.lock();
|
||||
|
||||
if (!PWINDOW->m_windowData.decorate.valueOrDefault())
|
||||
if (!PWINDOW->m_ruleApplicator->decorate().valueOrDefault())
|
||||
return;
|
||||
|
||||
auto data = CBarPassElement::SBarData{this, a};
|
||||
@ -754,7 +754,6 @@ PHLWINDOW CHyprBar::getOwner() {
|
||||
|
||||
void CHyprBar::updateRules() {
|
||||
const auto PWINDOW = m_pWindow.lock();
|
||||
auto rules = PWINDOW->m_matchedRules;
|
||||
auto prevHidden = m_hidden;
|
||||
auto prevForcedTitleColor = m_bForcedTitleColor;
|
||||
|
||||
@ -762,9 +761,12 @@ void CHyprBar::updateRules() {
|
||||
m_bForcedTitleColor = std::nullopt;
|
||||
m_hidden = false;
|
||||
|
||||
for (auto& r : rules) {
|
||||
applyRule(r);
|
||||
}
|
||||
if (PWINDOW->m_ruleApplicator->m_otherProps.props.contains(g_pGlobalState->nobarRuleIdx))
|
||||
m_hidden = truthy(PWINDOW->m_ruleApplicator->m_otherProps.props.at(g_pGlobalState->nobarRuleIdx)->effect);
|
||||
if (PWINDOW->m_ruleApplicator->m_otherProps.props.contains(g_pGlobalState->barColorRuleIdx))
|
||||
m_bForcedBarColor = CHyprColor(configStringToInt(PWINDOW->m_ruleApplicator->m_otherProps.props.at(g_pGlobalState->nobarRuleIdx)->effect).value_or(0));
|
||||
if (PWINDOW->m_ruleApplicator->m_otherProps.props.contains(g_pGlobalState->titleColorRuleIdx))
|
||||
m_bForcedTitleColor = CHyprColor(configStringToInt(PWINDOW->m_ruleApplicator->m_otherProps.props.at(g_pGlobalState->nobarRuleIdx)->effect).value_or(0));
|
||||
|
||||
if (prevHidden != m_hidden)
|
||||
g_pDecorationPositioner->repositionDeco(this);
|
||||
@ -772,17 +774,6 @@ void CHyprBar::updateRules() {
|
||||
m_bTitleColorChanged = true;
|
||||
}
|
||||
|
||||
void CHyprBar::applyRule(const SP<CWindowRule>& r) {
|
||||
auto arg = r->m_rule.substr(r->m_rule.find_first_of(' ') + 1);
|
||||
|
||||
if (r->m_rule == "plugin:hyprbars:nobar")
|
||||
m_hidden = true;
|
||||
else if (r->m_rule.starts_with("plugin:hyprbars:bar_color"))
|
||||
m_bForcedBarColor = CHyprColor(configStringToInt(arg).value_or(0));
|
||||
else if (r->m_rule.starts_with("plugin:hyprbars:title_color"))
|
||||
m_bForcedTitleColor = CHyprColor(configStringToInt(arg).value_or(0));
|
||||
}
|
||||
|
||||
void CHyprBar::damageOnButtonHover() {
|
||||
static auto* const PBARPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_padding")->getDataStaticPtr();
|
||||
static auto* const PBARBUTTONPADDING = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_button_padding")->getDataStaticPtr();
|
||||
|
||||
@ -43,7 +43,6 @@ class CHyprBar : public IHyprWindowDecoration {
|
||||
PHLWINDOW getOwner();
|
||||
|
||||
void updateRules();
|
||||
void applyRule(const SP<CWindowRule>&);
|
||||
|
||||
WP<CHyprBar> m_self;
|
||||
|
||||
|
||||
@ -20,6 +20,9 @@ class CHyprBar;
|
||||
struct SGlobalState {
|
||||
std::vector<SHyprButton> buttons;
|
||||
std::vector<WP<CHyprBar>> bars;
|
||||
uint32_t nobarRuleIdx = 0;
|
||||
uint32_t barColorRuleIdx = 0;
|
||||
uint32_t titleColorRuleIdx = 0;
|
||||
};
|
||||
|
||||
inline UP<SGlobalState> g_pGlobalState;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <hyprland/src/desktop/Window.hpp>
|
||||
#include <hyprland/src/config/ConfigManager.hpp>
|
||||
#include <hyprland/src/render/Renderer.hpp>
|
||||
#include <hyprland/src/desktop/rule/windowRule/WindowRuleEffectContainer.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -121,7 +122,10 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
||||
throw std::runtime_error("[hb] Version mismatch");
|
||||
}
|
||||
|
||||
g_pGlobalState = makeUnique<SGlobalState>();
|
||||
g_pGlobalState = makeUnique<SGlobalState>();
|
||||
g_pGlobalState->nobarRuleIdx = Desktop::Rule::windowEffects()->registerEffect("hyprbars:no_bar");
|
||||
g_pGlobalState->barColorRuleIdx = Desktop::Rule::windowEffects()->registerEffect("hyprbars:bar_color");
|
||||
g_pGlobalState->titleColorRuleIdx = Desktop::Rule::windowEffects()->registerEffect("hyprbars:title_color");
|
||||
|
||||
static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "openWindow", [&](void* self, SCallbackInfo& info, std::any data) { onNewWindow(self, data); });
|
||||
// static auto P2 = HyprlandAPI::registerCallbackDynamic(PHANDLE, "closeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onCloseWindow(self, data); });
|
||||
@ -167,4 +171,8 @@ APICALL EXPORT void PLUGIN_EXIT() {
|
||||
m->m_scheduledRecalc = true;
|
||||
|
||||
g_pHyprRenderer->m_renderPass.removeAllOfType("CBarPassElement");
|
||||
|
||||
Desktop::Rule::windowEffects()->unregisterEffect(g_pGlobalState->barColorRuleIdx);
|
||||
Desktop::Rule::windowEffects()->unregisterEffect(g_pGlobalState->titleColorRuleIdx);
|
||||
Desktop::Rule::windowEffects()->unregisterEffect(g_pGlobalState->nobarRuleIdx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user