windowrules: add initialTitle and initialClass (#4259)

This commit is contained in:
Tuur Vanhoutte 2023-12-26 23:47:46 +01:00 committed by GitHub
parent 9fb50252d3
commit 191fa587f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 10 deletions

View file

@ -151,6 +151,8 @@ struct SWindowRule {
bool v2 = false; bool v2 = false;
std::string szTitle; std::string szTitle;
std::string szClass; std::string szClass;
std::string szInitialTitle;
std::string szInitialClass;
int bX11 = -1; // -1 means "ANY" int bX11 = -1; // -1 means "ANY"
int bFloating = -1; int bFloating = -1;
int bFullscreen = -1; int bFullscreen = -1;

View file

@ -1028,14 +1028,16 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
rule.szRule = RULE; rule.szRule = RULE;
rule.szValue = VALUE; rule.szValue = VALUE;
const auto TITLEPOS = VALUE.find("title:"); const auto TITLEPOS = VALUE.find("title:");
const auto CLASSPOS = VALUE.find("class:"); const auto CLASSPOS = VALUE.find("class:");
const auto X11POS = VALUE.find("xwayland:"); const auto INITIALTITLEPOS = VALUE.find("initialTitle:");
const auto FLOATPOS = VALUE.find("floating:"); const auto INITIALCLASSPOS = VALUE.find("initialClass:");
const auto FULLSCREENPOS = VALUE.find("fullscreen:"); const auto X11POS = VALUE.find("xwayland:");
const auto PINNEDPOS = VALUE.find("pinned:"); const auto FLOATPOS = VALUE.find("floating:");
const auto FOCUSPOS = VALUE.find("focus:"); const auto FULLSCREENPOS = VALUE.find("fullscreen:");
const auto ONWORKSPACEPOS = VALUE.find("onworkspace:"); const auto PINNEDPOS = VALUE.find("pinned:");
const auto FOCUSPOS = VALUE.find("focus:");
const auto ONWORKSPACEPOS = VALUE.find("onworkspace:");
// find workspacepos that isn't onworkspacepos // find workspacepos that isn't onworkspacepos
size_t WORKSPACEPOS = std::string::npos; size_t WORKSPACEPOS = std::string::npos;
@ -1048,8 +1050,9 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
currentPos = VALUE.find("workspace:", currentPos + 1); currentPos = VALUE.find("workspace:", currentPos + 1);
} }
if (TITLEPOS == std::string::npos && CLASSPOS == std::string::npos && X11POS == std::string::npos && FLOATPOS == std::string::npos && FULLSCREENPOS == std::string::npos && if (TITLEPOS == std::string::npos && CLASSPOS == std::string::npos && INITIALTITLEPOS == std::string::npos && INITIALCLASSPOS == std::string::npos &&
PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos && FOCUSPOS == std::string::npos && ONWORKSPACEPOS == std::string::npos) { X11POS == std::string::npos && FLOATPOS == std::string::npos && FULLSCREENPOS == std::string::npos && PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos &&
FOCUSPOS == std::string::npos && ONWORKSPACEPOS == std::string::npos) {
Debug::log(ERR, "Invalid rulev2 syntax: {}", VALUE); Debug::log(ERR, "Invalid rulev2 syntax: {}", VALUE);
parseError = "Invalid rulev2 syntax: " + VALUE; parseError = "Invalid rulev2 syntax: " + VALUE;
return; return;
@ -1064,6 +1067,10 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
min = TITLEPOS; min = TITLEPOS;
if (CLASSPOS > pos && CLASSPOS < min) if (CLASSPOS > pos && CLASSPOS < min)
min = CLASSPOS; min = CLASSPOS;
if (INITIALTITLEPOS > pos && INITIALTITLEPOS < min)
min = INITIALTITLEPOS;
if (INITIALCLASSPOS > pos && INITIALCLASSPOS < min)
min = INITIALCLASSPOS;
if (X11POS > pos && X11POS < min) if (X11POS > pos && X11POS < min)
min = X11POS; min = X11POS;
if (FLOATPOS > pos && FLOATPOS < min) if (FLOATPOS > pos && FLOATPOS < min)
@ -1095,6 +1102,12 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
if (TITLEPOS != std::string::npos) if (TITLEPOS != std::string::npos)
rule.szTitle = extract(TITLEPOS + 6); rule.szTitle = extract(TITLEPOS + 6);
if (INITIALCLASSPOS != std::string::npos)
rule.szInitialClass = extract(INITIALCLASSPOS + 13);
if (INITIALTITLEPOS != std::string::npos)
rule.szInitialTitle = extract(INITIALTITLEPOS + 13);
if (X11POS != std::string::npos) if (X11POS != std::string::npos)
rule.bX11 = extract(X11POS + 9) == "1" ? 1 : 0; rule.bX11 = extract(X11POS + 9) == "1" ? 1 : 0;
@ -1127,6 +1140,12 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
if (!rule.szTitle.empty() && rule.szTitle != other.szTitle) if (!rule.szTitle.empty() && rule.szTitle != other.szTitle)
return false; return false;
if (!rule.szInitialClass.empty() && rule.szInitialClass != other.szInitialClass)
return false;
if (!rule.szInitialTitle.empty() && rule.szInitialTitle != other.szInitialTitle)
return false;
if (rule.bX11 != -1 && rule.bX11 != other.bX11) if (rule.bX11 != -1 && rule.bX11 != other.bX11)
return false; return false;
@ -2008,6 +2027,20 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
continue; continue;
} }
if (rule.szInitialTitle != "") {
std::regex RULECHECK(rule.szInitialTitle);
if (!std::regex_search(pWindow->m_szInitialTitle, RULECHECK))
continue;
}
if (rule.szInitialClass != "") {
std::regex RULECHECK(rule.szInitialClass);
if (!std::regex_search(pWindow->m_szInitialClass, RULECHECK))
continue;
}
if (rule.bX11 != -1) { if (rule.bX11 != -1) {
if (pWindow->m_bIsX11 != rule.bX11) if (pWindow->m_bIsX11 != rule.bX11)
continue; continue;