diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index f9bb5b46..4855553a 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -282,10 +282,18 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } outName = WORKSPACENAME; } else if (in.starts_with("empty")) { - int id = 0; + const bool same_mon = in.substr(5).contains("m"); + const bool next = in.substr(5).contains("n"); + if (same_mon || next) { + if (!g_pCompositor->m_pLastMonitor) { + Debug::log(ERR, "Empty monitor workspace on monitor null!"); + return WORKSPACE_INVALID; + } + } + int id = next ? g_pCompositor->m_pLastMonitor->activeWorkspaceID() : 0; while (++id < INT_MAX) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id); - if (!PWORKSPACE || (g_pCompositor->getWindowsOnWorkspace(id) == 0)) + if (!PWORKSPACE || (g_pCompositor->getWindowsOnWorkspace(id) == 0 && (!same_mon || PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID))) return id; } } else if (in.starts_with("prev")) {