diff options
| author | ItsOhen <TNordfeldt@gmail.com> | 2026-03-15 20:32:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-15 14:32:05 -0500 |
| commit | 94bd4123c6e8fd3162e245b0d568c9d6dfd75780 (patch) | |
| tree | 764d69857d566a44939394960b05731c709ae973 /src | |
| parent | 3fd2a95475d9a954305eeede59fe2b345a4d8098 (diff) | |
desktop/rules: fix static rules and content type. (#13725)
Hopefully for the last time in a while. Also a lot easier to add in new
static types with the recheck done in window map instead of the rule.
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop/rule/windowRule/WindowRuleApplicator.cpp | 41 | ||||
| -rw-r--r-- | src/desktop/rule/windowRule/WindowRuleApplicator.hpp | 6 | ||||
| -rw-r--r-- | src/desktop/view/Window.cpp | 14 | ||||
| -rw-r--r-- | src/protocols/types/ContentType.cpp | 12 |
4 files changed, 45 insertions, 28 deletions
diff --git a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp index 07cb5f64..dd0e7fb8 100644 --- a/src/desktop/rule/windowRule/WindowRuleApplicator.cpp +++ b/src/desktop/rule/windowRule/WindowRuleApplicator.cpp @@ -547,9 +547,10 @@ CWindowRuleApplicator::SRuleResult CWindowRuleApplicator::applyStaticRule(const return SRuleResult{}; } -void CWindowRuleApplicator::readStaticRules(bool preRead) { +// +bool CWindowRuleApplicator::readStaticRules(bool preRead) { if (!m_window) - return; + return false; static_ = {}; @@ -575,35 +576,35 @@ void CWindowRuleApplicator::readStaticRules(bool preRead) { tagsWereChanged = tagsWereChanged || RES.tagsChanged; } - // recheck some props people might wanna use for static rules. - std::underlying_type_t<eRuleProperty> propsToRecheck = RULE_PROP_NONE; + // set a recheck for some props people might wanna use for static rules. if (tagsWereChanged) propsToRecheck |= RULE_PROP_TAG; if (static_.content != NContentType::CONTENT_TYPE_NONE) propsToRecheck |= RULE_PROP_CONTENT; - if (propsToRecheck != RULE_PROP_NONE) { - for (const auto& r : ruleEngine()->rules()) { - if (r->type() != RULE_TYPE_WINDOW) - continue; + for (const auto& wr : execRules) { + applyStaticRule(wr); + applyDynamicRule(wr); + if (!preRead) + ruleEngine()->unregisterRule(wr); + } + return (propsToRecheck != RULE_PROP_NONE); +} - if (!(r->getPropertiesMask() & propsToRecheck)) - continue; +void CWindowRuleApplicator::recheckStaticRules() { + for (const auto& r : ruleEngine()->rules()) { + if (r->type() != RULE_TYPE_WINDOW) + continue; - auto wr = reinterpretPointerCast<CWindowRule>(r); + if (!(r->getPropertiesMask() & propsToRecheck)) + continue; - if (!wr->matches(m_window.lock(), true)) - continue; + auto wr = reinterpretPointerCast<CWindowRule>(r); - applyStaticRule(wr); - } - } + if (!wr->matches(m_window.lock(), true)) + continue; - for (const auto& wr : execRules) { applyStaticRule(wr); - applyDynamicRule(wr); - if (!preRead) - ruleEngine()->unregisterRule(wr); } } diff --git a/src/desktop/rule/windowRule/WindowRuleApplicator.hpp b/src/desktop/rule/windowRule/WindowRuleApplicator.hpp index 5c1d4fd1..8bcf7008 100644 --- a/src/desktop/rule/windowRule/WindowRuleApplicator.hpp +++ b/src/desktop/rule/windowRule/WindowRuleApplicator.hpp @@ -33,7 +33,8 @@ namespace Desktop::Rule { void propertiesChanged(std::underlying_type_t<eRuleProperty> props); std::unordered_set<CWindowRuleEffectContainer::storageType> resetProps(std::underlying_type_t<eRuleProperty> props, Types::eOverridePriority prio = Types::PRIORITY_WINDOW_RULE); - void readStaticRules(bool preRead = false); + bool readStaticRules(bool preRead = false); + void recheckStaticRules(); // static props struct { @@ -138,7 +139,8 @@ namespace Desktop::Rule { #undef DEFINE_PROP private: - PHLWINDOWREF m_window; + PHLWINDOWREF m_window; + std::underlying_type_t<eRuleProperty> propsToRecheck = RULE_PROP_NONE; struct SRuleResult { bool needsRelayout = false; diff --git a/src/desktop/view/Window.cpp b/src/desktop/view/Window.cpp index 4570a901..00d32a47 100644 --- a/src/desktop/view/Window.cpp +++ b/src/desktop/view/Window.cpp @@ -1719,8 +1719,7 @@ void CWindow::mapWindow() { requestedClientFSMode = FSMODE_FULLSCREEN; MONITORID requestedFSMonitor = m_wantsInitialFullscreenMonitor; - m_ruleApplicator->readStaticRules(); - { + auto setStaticProps = [&]() { if (!m_ruleApplicator->static_.monitor.empty()) { const auto& MONITORSTR = m_ruleApplicator->static_.monitor; if (MONITORSTR == "unset") @@ -1771,8 +1770,8 @@ void CWindow::mapWindow() { if (m_ruleApplicator->static_.fullscreenStateClient || m_ruleApplicator->static_.fullscreenStateInternal) { requestedFSState = Desktop::View::SFullscreenState{ - .internal = sc<eFullscreenMode>(m_ruleApplicator->static_.fullscreenStateInternal.value_or(0)), - .client = sc<eFullscreenMode>(m_ruleApplicator->static_.fullscreenStateClient.value_or(0)), + .internal = sc<eFullscreenMode>(m_ruleApplicator->static_.fullscreenStateInternal.value_or(0)), + .client = sc<eFullscreenMode>(m_ruleApplicator->static_.fullscreenStateClient.value_or(0)), }; } @@ -1846,6 +1845,13 @@ void CWindow::mapWindow() { if (m_ruleApplicator->static_.noCloseFor) m_closeableSince = Time::steadyNow() + std::chrono::milliseconds(m_ruleApplicator->static_.noCloseFor.value()); + }; + + const bool recheck = m_ruleApplicator->readStaticRules(); + setStaticProps(); + if (recheck) { + m_ruleApplicator->recheckStaticRules(); + setStaticProps(); } // make it uncloseable if it's a Hyprland dialog diff --git a/src/protocols/types/ContentType.cpp b/src/protocols/types/ContentType.cpp index b5b0041c..e2e58f3e 100644 --- a/src/protocols/types/ContentType.cpp +++ b/src/protocols/types/ContentType.cpp @@ -1,6 +1,7 @@ #include "ContentType.hpp" +#include "debug/log/Logger.hpp" +#include <hyprutils/string/String.hpp> #include <drm_mode.h> -#include <stdexcept> #include <format> namespace NContentType { @@ -8,6 +9,13 @@ namespace NContentType { {"none", CONTENT_TYPE_NONE}, {"photo", CONTENT_TYPE_PHOTO}, {"video", CONTENT_TYPE_VIDEO}, {"game", CONTENT_TYPE_GAME}}; eContentType fromString(const std::string name) { + if (Hyprutils::String::isNumber(name)) { + try { + auto n = std::stoi(name); + if (n >= 0 && n <= 3) + return sc<eContentType>(n); + } catch (std::exception& e) { Log::logger->log(Log::ERR, "NContentType::fromString: invalid number {}, need to be between 0 and 3", name); } + } auto it = table.find(name); if (it != table.end()) return it->second; @@ -42,4 +50,4 @@ namespace NContentType { default: return DRM_MODE_CONTENT_TYPE_NO_DATA; } } -}
\ No newline at end of file +} |
