windowrules: add onworkspace

cool
This commit is contained in:
Vaxry 2023-12-20 23:52:18 +01:00
parent 48ecb13b14
commit 4eb42fab7b
5 changed files with 57 additions and 15 deletions

View file

@ -1814,6 +1814,15 @@ void CCompositor::updateAllWindowsAnimatedDecorationValues() {
} }
} }
void CCompositor::updateWorkspaceWindows(const int64_t& id) {
for (auto& w : m_vWindows) {
if (!w->m_bIsMapped || w->m_iWorkspaceID != id)
continue;
w->updateDynamicRules();
}
}
void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) {
// optimization // optimization
static auto* const ACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("general:col.active_border")->data.get(); static auto* const ACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("general:col.active_border")->data.get();
@ -2643,6 +2652,9 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks
if (FULLSCREEN) if (FULLSCREEN)
setWindowFullscreen(pWindow, true, FULLSCREENMODE); setWindowFullscreen(pWindow, true, FULLSCREENMODE);
g_pCompositor->updateWorkspaceWindows(pWorkspace->m_iID);
g_pCompositor->updateWorkspaceWindows(pWindow->m_iWorkspaceID);
} }
CWindow* CCompositor::getForceFocus() { CWindow* CCompositor::getForceFocus() {

View file

@ -172,6 +172,7 @@ class CCompositor {
CWindow* getConstraintWindow(SMouse*); CWindow* getConstraintWindow(SMouse*);
CMonitor* getMonitorInDirection(const char&); CMonitor* getMonitorInDirection(const char&);
void updateAllWindowsAnimatedDecorationValues(); void updateAllWindowsAnimatedDecorationValues();
void updateWorkspaceWindows(const int64_t& id);
void updateWindowAnimatedDecorationValues(CWindow*); void updateWindowAnimatedDecorationValues(CWindow*);
int getNextAvailableMonitorID(std::string const& name); int getNextAvailableMonitorID(std::string const& name);
void moveWorkspaceToMonitor(CWorkspace*, CMonitor*); void moveWorkspaceToMonitor(CWorkspace*, CMonitor*);

View file

@ -448,6 +448,8 @@ void CWindow::onUnmap() {
if (PMONITOR && PMONITOR->solitaryClient == this) if (PMONITOR && PMONITOR->solitaryClient == this)
PMONITOR->solitaryClient = nullptr; PMONITOR->solitaryClient = nullptr;
g_pCompositor->updateWorkspaceWindows(m_iWorkspaceID);
} }
void CWindow::onMap() { void CWindow::onMap() {
@ -485,6 +487,8 @@ void CWindow::onMap() {
"CWindow"); "CWindow");
m_vReportedSize = m_vPendingReportedSize; m_vReportedSize = m_vPendingReportedSize;
g_pCompositor->updateWorkspaceWindows(m_iWorkspaceID);
} }
void CWindow::onBorderAngleAnimEnd(void* ptr) { void CWindow::onBorderAngleAnimEnd(void* ptr) {

View file

@ -151,12 +151,13 @@ struct SWindowRule {
bool v2 = false; bool v2 = false;
std::string szTitle; std::string szTitle;
std::string szClass; std::string szClass;
int bX11 = -1; // -1 means "ANY" int bX11 = -1; // -1 means "ANY"
int bFloating = -1; int bFloating = -1;
int bFullscreen = -1; int bFullscreen = -1;
int bPinned = -1; int bPinned = -1;
int bFocus = -1; int bFocus = -1;
std::string szWorkspace = ""; // empty means any int iOnWorkspace = -1;
std::string szWorkspace = ""; // empty means any
}; };
class CWindow { class CWindow {

View file

@ -1026,17 +1026,28 @@ 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 X11POS = VALUE.find("xwayland:");
const auto FLOATPOS = VALUE.find("floating:"); const auto FLOATPOS = VALUE.find("floating:");
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 FOCUSPOS = VALUE.find("focus:");
const auto FOCUSPOS = VALUE.find("focus:"); const auto ONWORKSPACEPOS = VALUE.find("onworkspace:");
// find workspacepos that isn't onworkspacepos
size_t WORKSPACEPOS = std::string::npos;
size_t currentPos = 0;
while (currentPos != std::string::npos) {
if (currentPos > 0 && VALUE[currentPos - 1] != 'n') {
WORKSPACEPOS = currentPos;
break;
}
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 && X11POS == std::string::npos && FLOATPOS == std::string::npos && FULLSCREENPOS == std::string::npos &&
PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos && FOCUSPOS == 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;
@ -1059,6 +1070,8 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
min = FULLSCREENPOS; min = FULLSCREENPOS;
if (PINNEDPOS > pos && PINNEDPOS < min) if (PINNEDPOS > pos && PINNEDPOS < min)
min = PINNEDPOS; min = PINNEDPOS;
if (ONWORKSPACEPOS > pos && ONWORKSPACEPOS < min)
min = ONWORKSPACEPOS;
if (WORKSPACEPOS > pos && WORKSPACEPOS < min) if (WORKSPACEPOS > pos && WORKSPACEPOS < min)
min = WORKSPACEPOS; min = WORKSPACEPOS;
if (FOCUSPOS > pos && FOCUSPOS < min) if (FOCUSPOS > pos && FOCUSPOS < min)
@ -1098,6 +1111,9 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
if (FOCUSPOS != std::string::npos) if (FOCUSPOS != std::string::npos)
rule.bFocus = extract(FOCUSPOS + 6) == "1" ? 1 : 0; rule.bFocus = extract(FOCUSPOS + 6) == "1" ? 1 : 0;
if (ONWORKSPACEPOS != std::string::npos)
rule.iOnWorkspace = configStringToInt(extract(ONWORKSPACEPOS + 12));
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) {
@ -1127,6 +1143,9 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
if (rule.bFocus != -1 && rule.bFocus != other.bFocus) if (rule.bFocus != -1 && rule.bFocus != other.bFocus)
return false; return false;
if (rule.iOnWorkspace != -1 && rule.iOnWorkspace != other.iOnWorkspace)
return false;
return true; return true;
} }
}); });
@ -2012,6 +2031,11 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
continue; continue;
} }
if (rule.iOnWorkspace != -1) {
if (rule.iOnWorkspace != g_pCompositor->getWindowsOnWorkspace(pWindow->m_iWorkspaceID))
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);