From 98fbbafef78057c818fb02b15c27e38ad2f5b5bc Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Tue, 28 Apr 2026 15:56:07 +0100 Subject: config/errors: Report and categorize errors properly for actions (#14192) Makes all errors categorized, some not displayed, some displayed. All errors can be obtained after hl.dispatch() --- .../algorithm/tiled/master/MasterAlgorithm.cpp | 54 ++++++++++++---------- .../algorithm/tiled/master/MasterAlgorithm.hpp | 24 +++++----- 2 files changed, 41 insertions(+), 37 deletions(-) (limited to 'src/layout/algorithm/tiled/master') diff --git a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp index 11a59a5f..46506391 100644 --- a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp +++ b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp @@ -428,7 +428,7 @@ void CMasterAlgorithm::recalculate() { calculateWorkspace(); } -std::expected CMasterAlgorithm::layoutMsg(const std::string_view& sv) { +Config::ErrorResult CMasterAlgorithm::layoutMsg(const std::string_view& sv) { auto switchToWindow = [&](SP target) { if (!target || !validMapped(target->window())) return; @@ -441,11 +441,15 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v g_pInputManager->m_forcedFocus.reset(); }; - CVarList2 vars(std::string{sv}, 0, 's'); + CVarList2 vars(std::string{sv}, 0, 's'); + + const auto invalidArg = [](std::string msg) { return Config::configError(std::move(msg), Config::eConfigErrorLevel::ERROR, Config::eConfigErrorCode::INVALID_ARGUMENT); }; + const auto noTarget = [](std::string msg) { return Config::configError(std::move(msg), Config::eConfigErrorLevel::WARNING, Config::eConfigErrorCode::NO_TARGET); }; + const auto stateErr = [](std::string msg) { return Config::configError(std::move(msg), Config::eConfigErrorLevel::WARNING, Config::eConfigErrorCode::INVALID_STATE); }; if (vars.size() < 1 || vars[0].empty()) { Log::logger->log(Log::ERR, "layoutmsg called without params"); - return std::unexpected("layoutmsg without params"); + return invalidArg("layoutmsg without params"); } auto command = vars[0]; @@ -461,15 +465,15 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v if (command == "swapwithmaster") { if (!PWINDOW) - return std::unexpected("No focused window"); + return noTarget("No focused window"); if (!isWindowTiled(PWINDOW)) - return std::unexpected("focused window isn't tiled"); + return stateErr("focused window isn't tiled"); const auto PMASTER = getMasterNode(); if (!PMASTER) - return std::unexpected("no master node"); + return stateErr("no master node"); const auto NEWCHILD = PMASTER->pTarget.lock(); @@ -503,12 +507,12 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v // * auto (default) - swap the focus with the first child, if the current focus was master, otherwise focus master else if (command == "focusmaster") { if (!PWINDOW) - return std::unexpected("no focused window"); + return noTarget("no focused window"); const auto PMASTER = getMasterNode(); if (!PMASTER) - return std::unexpected("no master"); + return stateErr("no master"); const auto& ARG = vars[1]; // returns empty string if out of bounds @@ -541,21 +545,21 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v focusAuto(); } else if (command == "cyclenext") { if (!PWINDOW) - return std::unexpected("no window"); + return noTarget("no window"); const bool NOLOOP = vars.size() >= 2 && vars[1] == "noloop"; const auto PNEXTWINDOW = getNextTarget(PWINDOW->layoutTarget(), true, !NOLOOP); switchToWindow(PNEXTWINDOW); } else if (command == "cycleprev") { if (!PWINDOW) - return std::unexpected("no window"); + return noTarget("no window"); const bool NOLOOP = vars.size() >= 2 && vars[1] == "noloop"; const auto PPREVWINDOW = getNextTarget(PWINDOW->layoutTarget(), false, !NOLOOP); switchToWindow(PPREVWINDOW); } else if (command == "swapnext") { if (!validMapped(PWINDOW)) - return std::unexpected("no window"); + return noTarget("no window"); if (PWINDOW->layoutTarget()->floating()) { Config::Actions::swapNext(true); @@ -572,7 +576,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v } } else if (command == "swapprev") { if (!validMapped(PWINDOW)) - return std::unexpected("no window"); + return noTarget("no window"); if (PWINDOW->layoutTarget()->floating()) { Config::Actions::swapNext(false); @@ -589,10 +593,10 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v } } else if (command == "addmaster") { if (!validMapped(PWINDOW)) - return std::unexpected("no window"); + return noTarget("no window"); if (PWINDOW->layoutTarget()->floating()) - return std::unexpected("window is floating"); + return stateErr("window is floating"); const auto PNODE = getNodeFromTarget(PWINDOW->layoutTarget()); @@ -601,7 +605,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); if (MASTERS + 2 > WINDOWS && *SMALLSPLIT == 0) - return std::unexpected("nothing to do"); + return stateErr("nothing to do"); g_pCompositor->setWindowFullscreenInternal(PWINDOW, FSMODE_NONE); @@ -622,10 +626,10 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v } else if (command == "removemaster") { if (!validMapped(PWINDOW)) - return std::unexpected("no window"); + return noTarget("no window"); if (PWINDOW->layoutTarget()->floating()) - return std::unexpected("window isnt tiled"); + return stateErr("window isnt tiled"); const auto PNODE = getNodeFromTarget(PWINDOW->layoutTarget()); @@ -633,7 +637,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v const auto MASTERS = getMastersNo(); if (WINDOWS < 2 || MASTERS < 2) - return std::unexpected("nothing to do"); + return stateErr("nothing to do"); g_pCompositor->setWindowFullscreenInternal(PWINDOW, FSMODE_NONE); @@ -652,7 +656,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v calculateWorkspace(); } else if (command == "orientationleft" || command == "orientationright" || command == "orientationtop" || command == "orientationbottom" || command == "orientationcenter") { if (!PWINDOW) - return std::unexpected("no window"); + return noTarget("no window"); g_pCompositor->setWindowFullscreenInternal(PWINDOW, FSMODE_NONE); @@ -677,7 +681,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v } else if (command == "mfact") { if (!PWINDOW) - return std::unexpected("no window"); + return noTarget("no window"); const bool exact = vars[1] == "exact"; @@ -685,7 +689,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v try { ratio = std::stof(std::string{exact ? vars[2] : vars[1]}); - } catch (...) { return std::unexpected("bad ratio"); } + } catch (...) { return invalidArg("bad ratio"); } const auto PNODE = getNodeFromWindow(PWINDOW); @@ -699,11 +703,11 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v const auto PNODE = getNodeFromWindow(PWINDOW); if (!PNODE) - return std::unexpected("window couldnt be found"); + return noTarget("window couldnt be found"); const auto OLDMASTER = PNODE->isMaster ? PNODE : getMasterNode(); if (!OLDMASTER) - return std::unexpected("no old master"); + return stateErr("no old master"); auto oldMasterIt = std::ranges::find(m_masterNodesData, OLDMASTER); @@ -735,11 +739,11 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v const auto PNODE = getNodeFromWindow(PWINDOW); if (!PNODE) - return std::unexpected("window couldnt be found"); + return noTarget("window couldnt be found"); const auto OLDMASTER = PNODE->isMaster ? PNODE : getMasterNode(); if (!OLDMASTER) - return std::unexpected("no old master"); + return stateErr("no old master"); auto oldMasterIt = std::ranges::find(m_masterNodesData, OLDMASTER); diff --git a/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp b/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp index 44c61369..00e82784 100644 --- a/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp +++ b/src/layout/algorithm/tiled/master/MasterAlgorithm.hpp @@ -48,22 +48,22 @@ namespace Layout::Tiled { CMasterAlgorithm() = default; virtual ~CMasterAlgorithm() = default; - virtual void newTarget(SP target); - virtual void movedTarget(SP target, std::optional focalPoint = std::nullopt); - virtual void removeTarget(SP target); + virtual void newTarget(SP target); + virtual void movedTarget(SP target, std::optional focalPoint = std::nullopt); + virtual void removeTarget(SP target); - virtual void resizeTarget(const Vector2D& Δ, SP target, eRectCorner corner = CORNER_NONE); - virtual void recalculate(); + virtual void resizeTarget(const Vector2D& Δ, SP target, eRectCorner corner = CORNER_NONE); + virtual void recalculate(); - virtual SP getNextCandidate(SP old); + virtual SP getNextCandidate(SP old); - virtual std::expected layoutMsg(const std::string_view& sv); - virtual std::optional predictSizeForNewTarget(); + virtual Config::ErrorResult layoutMsg(const std::string_view& sv); + virtual std::optional predictSizeForNewTarget(); - virtual void swapTargets(SP a, SP b); - virtual void moveTargetInDirection(SP t, Math::eDirection dir, bool silent); + virtual void swapTargets(SP a, SP b); + virtual void moveTargetInDirection(SP t, Math::eDirection dir, bool silent); - SP getNodeFromTarget(SP) const; + SP getNodeFromTarget(SP) const; private: std::vector> m_masterNodesData; @@ -87,4 +87,4 @@ namespace Layout::Tiled { bool isWindowTiled(PHLWINDOW); eOrientation defaultOrientation(); }; -}; \ No newline at end of file +}; -- cgit v1.2.3