diff options
| author | Felix Dick <felix.dick@web.de> | 2022-09-29 01:42:28 +0200 |
|---|---|---|
| committer | Felix Dick <felix.dick@web.de> | 2022-09-29 01:42:28 +0200 |
| commit | a1319e51108997b9335aec4c36db5bbc5b3b5bba (patch) | |
| tree | d3478c865739836c10cc71de1abed649c79ca434 /src/helpers/MiscFunctions.cpp | |
| parent | 5233746ac5d1a9d00462662b7778ebbacdc523dd (diff) | |
| parent | 31cb4c49d9f977d4cb0876cf1124bf9e86a60669 (diff) | |
Merge branch 'main' into fix_bordersize_again
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index e699d75a..17e7a1a1 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) { @@ -192,7 +210,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 +271,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::clamp((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); - else if (isNumber(in)) - result = std::clamp(std::stoi(in), 1, INT_MAX); + 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); } } @@ -269,8 +295,8 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2) { - const float DX = std::max((double)0, std::max(p1.x - vec.x, vec.x - p2.x)); - const float DY = std::max((double)0, std::max(p1.y - vec.y, vec.y - p2.y)); + const float DX = std::max({0.0, p1.x - vec.x, vec.x - p2.x}); + const float DY = std::max({0.0, p1.y - vec.y, vec.y - p2.y}); return DX * DX + DY * DY; } |
