mirror of
https://github.com/hyprwm/Hyprland
synced 2026-05-07 08:38:05 +02:00
config/actions: fix misuse of ActionResult's error type (#14221)
This commit is contained in:
parent
8884b9e6ce
commit
859bbb11e1
2 changed files with 23 additions and 24 deletions
|
|
@ -29,7 +29,6 @@ namespace Config {
|
|||
SConfigError() = default;
|
||||
SConfigError(std::string msg, eConfigErrorLevel lvl = eConfigErrorLevel::ERROR, eConfigErrorCode c = eConfigErrorCode::UNKNOWN) :
|
||||
message(std::move(msg)), level(lvl), code(c) {}
|
||||
SConfigError(const char* msg) : message(msg ? msg : "") {}
|
||||
|
||||
std::string message;
|
||||
eConfigErrorLevel level = eConfigErrorLevel::ERROR;
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ ActionResult Actions::pinWindow(eTogglableAction action, std::optional<PHLWINDOW
|
|||
|
||||
const auto PMONITOR = window->m_monitor.lock();
|
||||
if (!PMONITOR)
|
||||
return std::unexpected("Window has no monitor");
|
||||
return actionError("Window has no monitor", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
window->layoutTarget()->assignToSpace(PMONITOR->m_activeWorkspace->m_space);
|
||||
window->m_ruleApplicator->propertiesChanged(Desktop::Rule::RULE_PROP_PINNED);
|
||||
|
|
@ -291,7 +291,7 @@ ActionResult Actions::moveToWorkspace(PHLWORKSPACE ws, bool silent, std::optiona
|
|||
return {};
|
||||
|
||||
if (!ws)
|
||||
return std::unexpected("Invalid workspace");
|
||||
return actionError("No workspace to move to", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_ARGUMENT);
|
||||
|
||||
if (ws->m_id == window->workspaceID())
|
||||
return {};
|
||||
|
|
@ -379,7 +379,7 @@ ActionResult Actions::moveFocus(Math::eDirection dir) {
|
|||
|
||||
const auto PMONITOR = PLASTWINDOW->m_monitor.lock();
|
||||
if (!PMONITOR)
|
||||
return std::unexpected("Window has no monitor");
|
||||
return actionError("Window has no monitor", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
if (dir == Math::DIRECTION_LEFT || dir == Math::DIRECTION_RIGHT) {
|
||||
if (STICKS(PLASTWINDOW->m_position.x, PMONITOR->m_position.x) && STICKS(PLASTWINDOW->m_size.x, PMONITOR->m_size.x))
|
||||
|
|
@ -422,7 +422,7 @@ ActionResult Actions::focus(PHLWINDOW window) {
|
|||
|
||||
const auto PWORKSPACE = window->m_workspace;
|
||||
if (!PWORKSPACE)
|
||||
return std::unexpected("Window has no workspace");
|
||||
return actionError("Window has no workspace", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
updateRelativeCursorCoords();
|
||||
|
||||
|
|
@ -540,7 +540,7 @@ ActionResult Actions::moveCursorToCorner(int corner, std::optional<PHLWINDOW> w)
|
|||
return {};
|
||||
|
||||
if (corner < 0 || corner > 3)
|
||||
return std::unexpected("Corner must be 0-3");
|
||||
return actionError("Corner must be 0 - 3", eActionErrorLevel::ERROR, eActionErrorCode::INVALID_ARGUMENT);
|
||||
|
||||
switch (corner) {
|
||||
case 0: g_pCompositor->warpCursorTo({window->m_realPosition->value().x, window->m_realPosition->value().y + window->m_realSize->value().y}, true); break;
|
||||
|
|
@ -565,7 +565,7 @@ ActionResult Actions::resize(const Vector2D& size, bool relative, std::optional<
|
|||
return actionError("Window is fullscreen", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
if (!relative && (size.x < 1 || size.y < 1))
|
||||
return std::unexpected("Invalid size");
|
||||
return actionError("Invalid size", eActionErrorLevel::ERROR, eActionErrorCode::INVALID_ARGUMENT);
|
||||
|
||||
const auto delta = relative ? size : size - window->m_realSize->goal();
|
||||
|
||||
|
|
@ -814,7 +814,7 @@ ActionResult Actions::setProp(const std::string& PROP, const std::string& VAL, s
|
|||
else if (PROP == "animation")
|
||||
parsePropTrivial(PWINDOW->m_ruleApplicator->animationStyle(), VAL);
|
||||
else
|
||||
return std::unexpected("prop not found");
|
||||
return actionError("Invalid prop name", eActionErrorLevel::ERROR, eActionErrorCode::INVALID_ARGUMENT);
|
||||
|
||||
} catch (std::exception& e) { return std::unexpected(std::format("Error parsing prop value: {}", std::string(e.what()))); }
|
||||
|
||||
|
|
@ -886,14 +886,14 @@ ActionResult Actions::setGroupActive(int index, std::optional<PHLWINDOW> w) {
|
|||
|
||||
ActionResult Actions::changeWorkspace(PHLWORKSPACE ws) {
|
||||
if (!ws)
|
||||
return std::unexpected("Invalid workspace");
|
||||
return actionError("Invalid workspace", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
|
||||
static auto PHIDESPECIALONWORKSPACECHANGE = CConfigValue<Config::INTEGER>("binds:hide_special_on_workspace_change");
|
||||
static auto PWORKSPACECENTERON = CConfigValue<Config::INTEGER>("binds:workspace_center_on");
|
||||
|
||||
const auto PMONITOR = Desktop::focusState()->monitor();
|
||||
if (!PMONITOR)
|
||||
return std::unexpected("No monitor");
|
||||
return actionError("No focused monitor", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
if (ws->m_isSpecialWorkspace) {
|
||||
PMONITOR->setSpecialWorkspace(ws);
|
||||
|
|
@ -907,7 +907,7 @@ ActionResult Actions::changeWorkspace(PHLWORKSPACE ws) {
|
|||
|
||||
const auto PMONITORWORKSPACEOWNER = PMONITOR == ws->m_monitor ? PMONITOR : ws->m_monitor.lock();
|
||||
if (!PMONITORWORKSPACEOWNER)
|
||||
return std::unexpected("Workspace has no monitor");
|
||||
return actionError("Workspace has no monitor", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
updateRelativeCursorCoords();
|
||||
|
||||
|
|
@ -997,13 +997,13 @@ static PHLWORKSPACE resolveWorkspaceForChange(const std::string& args) {
|
|||
ActionResult Actions::changeWorkspace(const std::string& ws) {
|
||||
auto p = resolveWorkspaceForChange(ws);
|
||||
if (!p)
|
||||
return std::unexpected("invalid workspace");
|
||||
return actionError("Bad workspace", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
return Actions::changeWorkspace(p);
|
||||
}
|
||||
|
||||
ActionResult Actions::renameWorkspace(PHLWORKSPACE ws, const std::string& s) {
|
||||
if (!ws)
|
||||
return std::unexpected("Invalid workspace");
|
||||
return actionError("Bad workspace", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
|
||||
ws->rename(s);
|
||||
|
||||
|
|
@ -1012,9 +1012,9 @@ ActionResult Actions::renameWorkspace(PHLWORKSPACE ws, const std::string& s) {
|
|||
|
||||
ActionResult Actions::moveToMonitor(PHLWORKSPACE ws, PHLMONITOR mon) {
|
||||
if (!ws)
|
||||
return std::unexpected("Invalid workspace");
|
||||
return actionError("Bad workspace", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
if (!mon)
|
||||
return std::unexpected("Invalid monitor");
|
||||
return actionError("Bad monitor", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
|
||||
g_pCompositor->moveWorkspaceToMonitor(ws, mon);
|
||||
|
||||
|
|
@ -1023,16 +1023,16 @@ ActionResult Actions::moveToMonitor(PHLWORKSPACE ws, PHLMONITOR mon) {
|
|||
|
||||
ActionResult Actions::changeWorkspaceOnCurrentMonitor(PHLWORKSPACE ws) {
|
||||
if (!ws)
|
||||
return std::unexpected("Invalid workspace");
|
||||
return actionError("Bad workspace", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
|
||||
const auto PCURRMONITOR = Desktop::focusState()->monitor();
|
||||
if (!PCURRMONITOR)
|
||||
return std::unexpected("No current monitor");
|
||||
return actionError("No focused monitor", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
if (ws->m_monitor != PCURRMONITOR) {
|
||||
const auto POLDMONITOR = ws->m_monitor.lock();
|
||||
if (!POLDMONITOR)
|
||||
return std::unexpected("Workspace has no monitor");
|
||||
return actionError("Workspace has no monitor", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
if (POLDMONITOR->activeWorkspaceID() == ws->m_id) {
|
||||
g_pCompositor->swapActiveWorkspaces(POLDMONITOR, PCURRMONITOR);
|
||||
|
|
@ -1047,11 +1047,11 @@ ActionResult Actions::changeWorkspaceOnCurrentMonitor(PHLWORKSPACE ws) {
|
|||
|
||||
ActionResult Actions::toggleSpecial(PHLWORKSPACE special) {
|
||||
if (!special || !special->m_isSpecialWorkspace)
|
||||
return std::unexpected("Invalid special workspace");
|
||||
return actionError("Bad special workspace", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
|
||||
const auto PMONITOR = Desktop::focusState()->monitor();
|
||||
if (!PMONITOR)
|
||||
return std::unexpected("No monitor");
|
||||
return actionError("No focused monitor", eActionErrorLevel::WARNING, eActionErrorCode::INVALID_STATE);
|
||||
|
||||
bool requestedWorkspaceIsAlreadyOpen = false;
|
||||
auto specialOpenOnMonitor = PMONITOR->activeSpecialWorkspaceID();
|
||||
|
|
@ -1090,7 +1090,7 @@ ActionResult Actions::toggleSpecial(PHLWORKSPACE special) {
|
|||
|
||||
ActionResult Actions::focusMonitor(PHLMONITOR mon) {
|
||||
if (!mon)
|
||||
return std::unexpected("Invalid monitor");
|
||||
return actionError("Bad monitor", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
|
||||
tryMoveFocusToMonitor(mon);
|
||||
|
||||
|
|
@ -1099,7 +1099,7 @@ ActionResult Actions::focusMonitor(PHLMONITOR mon) {
|
|||
|
||||
ActionResult Actions::swapActiveWorkspaces(PHLMONITOR mon1, PHLMONITOR mon2) {
|
||||
if (!mon1 || !mon2)
|
||||
return std::unexpected("Invalid monitor");
|
||||
return actionError("Bad monitor", eActionErrorLevel::WARNING, eActionErrorCode::NO_TARGET);
|
||||
|
||||
if (mon1 == mon2)
|
||||
return {};
|
||||
|
|
@ -1408,7 +1408,7 @@ ActionResult Actions::pass(std::optional<PHLWINDOW> w) {
|
|||
return {};
|
||||
|
||||
if (!g_pSeatManager->m_keyboard)
|
||||
return std::unexpected("No keyboard");
|
||||
return actionError("No keyboard connected", eActionErrorLevel::INFO, eActionErrorCode::NO_TARGET);
|
||||
|
||||
const auto& S = *Config::Actions::state();
|
||||
const auto XWTOXW = window->m_isX11 && Desktop::focusState()->window() && Desktop::focusState()->window()->m_isX11;
|
||||
|
|
@ -1476,7 +1476,7 @@ ActionResult Actions::pass(uint32_t modMask, uint32_t key, std::optional<PHLWIND
|
|||
|
||||
if (window) {
|
||||
if (!g_pSeatManager->m_keyboard)
|
||||
return std::unexpected("No keyboard");
|
||||
return actionError("No keyboard connected", eActionErrorLevel::INFO, eActionErrorCode::NO_TARGET);
|
||||
|
||||
if (!isMouse)
|
||||
g_pSeatManager->setKeyboardFocus(window->wlSurface()->resource());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue