From 69e314207d193eb67be0ae153d50c6c6bcee4b60 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 12 Nov 2023 13:34:42 +0000 Subject: [PATCH] internal: replace INT_MAX with WORKSPACE_INVALID --- src/config/ConfigManager.cpp | 4 ++-- src/events/Windows.cpp | 2 +- src/helpers/MiscFunctions.cpp | 16 +++++++--------- src/helpers/Monitor.cpp | 2 +- src/macros.hpp | 2 ++ src/managers/KeybindManager.cpp | 12 ++++++------ src/managers/input/Swipe.cpp | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index d07e6a6a..424b67a4 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1164,13 +1164,13 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: auto rules = value.substr(FIRST_DELIM + 1); SWorkspaceRule wsRule; wsRule.workspaceString = first_ident; - if (id == INT_MAX) { + if (id == WORKSPACE_INVALID) { // it could be the monitor. If so, second value MUST be // the workspace. const auto WORKSPACE_DELIM = value.find_first_of(',', FIRST_DELIM + 1); auto wsIdent = removeBeginEndSpacesTabs(value.substr(FIRST_DELIM + 1, (WORKSPACE_DELIM - FIRST_DELIM - 1))); id = getWorkspaceIDFromString(wsIdent, name); - if (id == INT_MAX) { + if (id == WORKSPACE_INVALID) { Debug::log(ERR, "Invalid workspace identifier found: {}", wsIdent); parseError = "Invalid workspace identifier found: " + wsIdent; return; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 00d78f4c..1d5384b7 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -279,7 +279,7 @@ void Events::listener_mapWindow(void* owner, void* data) { std::string requestedWorkspaceName; const int REQUESTEDWORKSPACEID = getWorkspaceIDFromString(WORKSPACEARGS.join(" ", 0, workspaceSilent ? WORKSPACEARGS.size() - 1 : 0), requestedWorkspaceName); - if (REQUESTEDWORKSPACEID != INT_MAX) { + if (REQUESTEDWORKSPACEID != WORKSPACE_INVALID) { auto pWorkspace = g_pCompositor->getWorkspaceByID(REQUESTEDWORKSPACEID); if (!pWorkspace) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 376ac032..7a9c5e5e 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -247,7 +247,7 @@ bool isDirection(const char& arg) { } int getWorkspaceIDFromString(const std::string& in, std::string& outName) { - int result = INT_MAX; + int result = WORKSPACE_INVALID; if (in.starts_with("special")) { outName = "special"; @@ -280,17 +280,17 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } } else if (in.starts_with("prev")) { if (!g_pCompositor->m_pLastMonitor) - return INT_MAX; + return WORKSPACE_INVALID; const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); if (!PWORKSPACE) - return INT_MAX; + return WORKSPACE_INVALID; const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.iID); if (!PLASTWORKSPACE) - return INT_MAX; + return WORKSPACE_INVALID; outName = PLASTWORKSPACE->m_szName; return PLASTWORKSPACE->m_iID; @@ -298,8 +298,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { if (in[0] == 'r' && (in[1] == '-' || in[1] == '+') && isNumber(in.substr(2))) { if (!g_pCompositor->m_pLastMonitor) { Debug::log(ERR, "Relative monitor workspace on monitor null!"); - result = INT_MAX; - return result; + return WORKSPACE_INVALID; } result = (int)getPlusMinusKeywordResult(in.substr(1), 0); @@ -433,8 +432,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { if (!g_pCompositor->m_pLastMonitor) { Debug::log(ERR, "Relative monitor workspace on monitor null!"); - result = INT_MAX; - return result; + return WORKSPACE_INVALID; } // monitor relative @@ -483,7 +481,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { result = std::max((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1); else { Debug::log(ERR, "Relative workspace on no mon!"); - result = INT_MAX; + return WORKSPACE_INVALID; } } else if (isNumber(in)) result = std::max(std::stoi(in), 1); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 743c938e..20880d8d 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -353,7 +353,7 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) { findAvailableDefaultWS() : getWorkspaceIDFromString(g_pConfigManager->getDefaultWorkspaceFor(szName), newDefaultWorkspaceName); - if (WORKSPACEID == INT_MAX || (WORKSPACEID >= SPECIAL_WORKSPACE_START && WORKSPACEID <= -2)) { + if (WORKSPACEID == WORKSPACE_INVALID || (WORKSPACEID >= SPECIAL_WORKSPACE_START && WORKSPACEID <= -2)) { WORKSPACEID = g_pCompositor->m_vWorkspaces.size() + 1; newDefaultWorkspaceName = std::to_string(WORKSPACEID); diff --git a/src/macros.hpp b/src/macros.hpp index eada3a9f..c2eb98db 100644 --- a/src/macros.hpp +++ b/src/macros.hpp @@ -22,6 +22,8 @@ #define STRVAL_EMPTY "[[EMPTY]]" +#define WORKSPACE_INVALID -1L + #define LISTENER(name) \ void listener_##name(wl_listener*, void*); \ inline wl_listener listen_##name = {.notify = listener_##name} diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index e4cac5f4..d8307de2 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -831,7 +831,7 @@ void CKeybindManager::changeworkspace(std::string args) { workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName); } - if (workspaceToChangeTo == INT_MAX) { + if (workspaceToChangeTo == WORKSPACE_INVALID) { Debug::log(ERR, "Error in changeworkspace, invalid value"); return; } @@ -920,7 +920,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { std::string workspaceName; const auto WORKSPACEID = getWorkspaceIDFromString(args, workspaceName); - if (WORKSPACEID == INT_MAX) { + if (WORKSPACEID == WORKSPACE_INVALID) { Debug::log(LOG, "Invalid workspace in moveActiveToWorkspace"); return; } @@ -977,7 +977,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { const int WORKSPACEID = getWorkspaceIDFromString(args, workspaceName); - if (WORKSPACEID == INT_MAX) { + if (WORKSPACEID == WORKSPACE_INVALID) { Debug::log(ERR, "Error in moveActiveToWorkspaceSilent, invalid value"); return; } @@ -1233,7 +1233,7 @@ void CKeybindManager::alterSplitRatio(std::string args) { } } - if (splitratio == INT_MAX) { + if (splitratio == WORKSPACE_INVALID) { Debug::log(ERR, "Splitratio invalid in alterSplitRatio!"); return; } @@ -1425,7 +1425,7 @@ void CKeybindManager::moveWorkspaceToMonitor(std::string args) { std::string workspaceName; const int WORKSPACEID = getWorkspaceIDFromString(workspace, workspaceName); - if (WORKSPACEID == INT_MAX) { + if (WORKSPACEID == WORKSPACE_INVALID) { Debug::log(ERR, "moveWorkspaceToMonitor invalid workspace!"); return; } @@ -1447,7 +1447,7 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { std::string workspaceName = ""; int workspaceID = getWorkspaceIDFromString("special:" + args, workspaceName); - if (workspaceID == INT_MAX || !g_pCompositor->isWorkspaceSpecial(workspaceID)) { + if (workspaceID == WORKSPACE_INVALID || !g_pCompositor->isWorkspaceSpecial(workspaceID)) { Debug::log(ERR, "Invalid workspace passed to special"); return; } diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 360397eb..dba3d735 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -211,7 +211,7 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { auto workspaceIDLeft = getWorkspaceIDFromString(*PSWIPENUMBER ? "-1" : (*PSWIPEUSER ? "r-1" : "m-1"), wsname); auto workspaceIDRight = getWorkspaceIDFromString(*PSWIPENUMBER ? "+1" : (*PSWIPEUSER ? "r+1" : "m+1"), wsname); - if ((workspaceIDLeft == INT_MAX || workspaceIDRight == INT_MAX || workspaceIDLeft == m_sActiveSwipe.pWorkspaceBegin->m_iID) && !*PSWIPENEW) { + if ((workspaceIDLeft == WORKSPACE_INVALID || workspaceIDRight == WORKSPACE_INVALID || workspaceIDLeft == m_sActiveSwipe.pWorkspaceBegin->m_iID) && !*PSWIPENEW) { m_sActiveSwipe.pWorkspaceBegin = nullptr; // invalidate the swipe return; }