windowrules: add focus param

This commit is contained in:
Vaxry 2023-12-08 16:02:16 +00:00
parent 288f1863f0
commit 11d1c50420
3 changed files with 21 additions and 2 deletions

View file

@ -943,6 +943,8 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
// we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window // we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window
if (windowValidMapped(PLASTWINDOW)) { if (windowValidMapped(PLASTWINDOW)) {
PLASTWINDOW->updateDynamicRules();
updateWindowAnimatedDecorationValues(PLASTWINDOW); updateWindowAnimatedDecorationValues(PLASTWINDOW);
if (!pWindow->m_bIsX11 || pWindow->m_iX11Type == 1) if (!pWindow->m_bIsX11 || pWindow->m_iX11Type == 1)
@ -960,6 +962,8 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
g_pXWaylandManager->activateWindow(pWindow, true); // sets the m_pLastWindow g_pXWaylandManager->activateWindow(pWindow, true); // sets the m_pLastWindow
pWindow->updateDynamicRules();
updateWindowAnimatedDecorationValues(pWindow); updateWindowAnimatedDecorationValues(pWindow);
if (pWindow->m_bIsUrgent) if (pWindow->m_bIsUrgent)

View file

@ -155,6 +155,7 @@ struct SWindowRule {
int bFloating = -1; int bFloating = -1;
int bFullscreen = -1; int bFullscreen = -1;
int bPinned = -1; int bPinned = -1;
int bFocus = -1;
std::string szWorkspace = ""; // empty means any std::string szWorkspace = ""; // empty means any
}; };

View file

@ -1028,9 +1028,10 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
const auto FULLSCREENPOS = VALUE.find("fullscreen:"); const auto FULLSCREENPOS = VALUE.find("fullscreen:");
const auto PINNEDPOS = VALUE.find("pinned:"); const auto PINNEDPOS = VALUE.find("pinned:");
const auto WORKSPACEPOS = VALUE.find("workspace:"); const auto WORKSPACEPOS = VALUE.find("workspace:");
const auto FOCUSPOS = VALUE.find("focus:");
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 && X11POS == std::string::npos && FLOATPOS == std::string::npos && FULLSCREENPOS == std::string::npos &&
PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos) { PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos && FOCUSPOS == 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;
@ -1054,7 +1055,9 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
if (PINNEDPOS > pos && PINNEDPOS < min) if (PINNEDPOS > pos && PINNEDPOS < min)
min = PINNEDPOS; min = PINNEDPOS;
if (WORKSPACEPOS > pos && WORKSPACEPOS < min) if (WORKSPACEPOS > pos && WORKSPACEPOS < min)
min = PINNEDPOS; min = WORKSPACEPOS;
if (FOCUSPOS > pos && FOCUSPOS < min)
min = FOCUSPOS;
result = result.substr(0, min - pos); result = result.substr(0, min - pos);
@ -1087,6 +1090,9 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
if (WORKSPACEPOS != std::string::npos) if (WORKSPACEPOS != std::string::npos)
rule.szWorkspace = extract(WORKSPACEPOS + 10); rule.szWorkspace = extract(WORKSPACEPOS + 10);
if (FOCUSPOS != std::string::npos)
rule.bFocus = extract(FOCUSPOS + 6) == "1" ? 1 : 0;
if (RULE == "unset") { if (RULE == "unset") {
std::erase_if(m_dWindowRules, [&](const SWindowRule& other) { std::erase_if(m_dWindowRules, [&](const SWindowRule& other) {
if (!other.v2) { if (!other.v2) {
@ -1113,6 +1119,9 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
if (!rule.szWorkspace.empty() && rule.szWorkspace != other.szWorkspace) if (!rule.szWorkspace.empty() && rule.szWorkspace != other.szWorkspace)
return false; return false;
if (rule.bFocus != -1 && rule.bFocus != other.bFocus)
return false;
return true; return true;
} }
}); });
@ -1965,6 +1974,11 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
continue; continue;
} }
if (rule.bFocus != -1) {
if (rule.bFocus != (g_pCompositor->m_pLastWindow == pWindow))
continue;
}
if (!rule.szWorkspace.empty()) { if (!rule.szWorkspace.empty()) {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);