From 458ba3237b402c72b78e890de228e561b3b4de8b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:12:15 +0100 Subject: [PATCH 1/3] use goalv in movetoworkspace --- src/managers/KeybindManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 99f6bab5..9aebe7c4 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -819,8 +819,8 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { return; } - auto PSAVEDSIZE = PWINDOW->m_vRealSize.vec(); - auto PSAVEDPOS = PWINDOW->m_vRealPosition.vec(); + auto PSAVEDSIZE = PWINDOW->m_vRealSize.goalv(); + auto PSAVEDPOS = PWINDOW->m_vRealPosition.goalv(); g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); From e3b1d3c3c53c2ffad07f2ef91d5a0cf3fa452879 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:26:41 +0100 Subject: [PATCH 2/3] allow for pure workspace names in dispatchers --- src/helpers/MiscFunctions.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index d7df7bd7..67debf32 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -192,7 +192,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } outName = WORKSPACENAME; } else { - if (in[0] == 'm' || in[0] == 'e') { + if ((in[0] == 'm' || in[0] == 'e') && (in[1] == '-' || in[1] == '+') && isNumber(in.substr(2))) { bool onAllMonitors = in[0] == 'e'; if (!g_pCompositor->m_pLastMonitor) { @@ -253,14 +253,22 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { outName = g_pCompositor->getWorkspaceByID(currentID)->m_szName; } else { - if (g_pCompositor->m_pLastMonitor) - result = std::max((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1); - else if (isNumber(in)) + if (in[0] == '+' || in[0] == '-') { + if (g_pCompositor->m_pLastMonitor) + result = std::max((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1); + else { + Debug::log(ERR, "Relative workspace on no mon!"); + result = INT_MAX; + } + } else if (isNumber(in)) result = std::max(std::stoi(in), 1); else { - Debug::log(ERR, "Relative workspace on no mon!"); - result = INT_MAX; + // maybe name + const auto PWORKSPACE = g_pCompositor->getWorkspaceByName(in); + if (PWORKSPACE) + result = PWORKSPACE->m_iID; } + outName = std::to_string(result); } } From ec5ffe8839c9c993fed4c23d72077969615dd298 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 28 Sep 2022 15:32:53 +0100 Subject: [PATCH 3/3] rewrite isNumber --- src/helpers/MiscFunctions.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 67debf32..b2f3a086 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -170,7 +170,25 @@ float getPlusMinusKeywordResult(std::string source, float relative) { } bool isNumber(const std::string& str, bool allowfloat) { - return std::ranges::all_of(str.begin(), str.end(), [&](char c) { return isdigit(c) != 0 || c == '-' || (allowfloat && c == '.'); }); + + std::string copy = str; + if (*copy.begin() == '-') + copy = copy.substr(1); + + bool point = !allowfloat; + for (auto& c : copy) { + if (c == '.') { + if (point) + return false; + point = true; + break; + } + + if (!std::isdigit(c)) + return false; + } + + return true; } bool isDirection(const std::string& arg) {