keybinds: fix empty on monitor for new workspaces (#6089)

This commit is contained in:
JManch 2024-05-15 21:03:51 +01:00 committed by GitHub
parent b9c58b6e75
commit a8522db683
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -284,16 +284,24 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
} else if (in.starts_with("empty")) { } else if (in.starts_with("empty")) {
const bool same_mon = in.substr(5).contains("m"); const bool same_mon = in.substr(5).contains("m");
const bool next = in.substr(5).contains("n"); const bool next = in.substr(5).contains("n");
if (same_mon || next) { if ((same_mon || next) && !g_pCompositor->m_pLastMonitor) {
if (!g_pCompositor->m_pLastMonitor) { Debug::log(ERR, "Empty monitor workspace on monitor null!");
Debug::log(ERR, "Empty monitor workspace on monitor null!"); return WORKSPACE_INVALID;
return WORKSPACE_INVALID; }
std::set<int> invalidWSes;
if (same_mon) {
for (auto& rule : g_pConfigManager->getAllWorkspaceRules()) {
const auto PMONITOR = g_pCompositor->getMonitorFromName(rule.monitor);
if (PMONITOR && (PMONITOR->ID != g_pCompositor->m_pLastMonitor->ID))
invalidWSes.insert(rule.workspaceId);
} }
} }
int id = next ? g_pCompositor->m_pLastMonitor->activeWorkspaceID() : 0; int id = next ? g_pCompositor->m_pLastMonitor->activeWorkspaceID() : 0;
while (++id < INT_MAX) { while (++id < INT_MAX) {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id);
if (!PWORKSPACE || (g_pCompositor->getWindowsOnWorkspace(id) == 0 && (!same_mon || PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID))) if (!invalidWSes.contains(id) && (!PWORKSPACE || g_pCompositor->getWindowsOnWorkspace(id) == 0))
return id; return id;
} }
} else if (in.starts_with("prev")) { } else if (in.starts_with("prev")) {