diff options
author | Ikalco <[email protected]> | 2024-08-24 11:45:53 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2024-08-24 18:45:53 +0200 |
commit | 66586c38f53f16bcf762f019359a3c9042546a72 (patch) | |
tree | 9a1f3b8b7796bd06765d32ec0f12d7298df59bf1 | |
parent | 82c67e61a96b23c7b962ab8e3ed9079f671942e1 (diff) | |
download | Hyprland-66586c38f53f16bcf762f019359a3c9042546a72.tar.gz Hyprland-66586c38f53f16bcf762f019359a3c9042546a72.zip |
keybinds: refactor dispatchers to be better (#7331)
-rw-r--r-- | src/debug/HyprCtl.cpp | 6 | ||||
-rw-r--r-- | src/managers/KeybindManager.cpp | 578 | ||||
-rw-r--r-- | src/managers/KeybindManager.hpp | 171 | ||||
-rw-r--r-- | src/plugins/PluginAPI.cpp | 7 |
4 files changed, 457 insertions, 305 deletions
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 78c8504a..a92c3a53 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -962,11 +962,11 @@ std::string dispatchRequest(eHyprCtlOutputFormat format, std::string in) { if (DISPATCHER == g_pKeybindManager->m_mDispatchers.end()) return "Invalid dispatcher"; - DISPATCHER->second(DISPATCHARG); + SDispatchResult res = DISPATCHER->second(DISPATCHARG); - Debug::log(LOG, "Hyprctl: dispatcher {} : {}", DISPATCHSTR, DISPATCHARG); + Debug::log(LOG, "Hyprctl: dispatcher {} : {}{}", DISPATCHSTR, DISPATCHARG, res.success ? "" : " -> " + res.error); - return "ok"; + return res.success ? "ok" : res.error; } std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 38593497..8bf7152e 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -405,7 +405,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP<IKeyboard> pKeyboard) { m_dPressedKeys.push_back(KEY); - suppressEvent = handleKeybinds(MODS, KEY, true); + suppressEvent = !handleKeybinds(MODS, KEY, true).passEvent; if (suppressEvent) shadowKeybinds(keysym, KEYCODE); @@ -427,7 +427,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP<IKeyboard> pKeyboard) { if (!foundInPressedKeys) { Debug::log(ERR, "BUG THIS: key not found in m_dPressedKeys"); // fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy - suppressEvent = handleKeybinds(MODS, KEY, false); + suppressEvent = !handleKeybinds(MODS, KEY, false).passEvent; } shadowKeybinds(); @@ -457,14 +457,14 @@ bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e) { bool found = false; if (e.source == WL_POINTER_AXIS_SOURCE_WHEEL && e.axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { if (e.delta < 0) - found = handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_down"}, true); + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_down"}, true).passEvent; else - found = handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_up"}, true); + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_up"}, true).passEvent; } else if (e.source == WL_POINTER_AXIS_SOURCE_WHEEL && e.axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { if (e.delta < 0) - found = handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_left"}, true); + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_left"}, true).passEvent; else - found = handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_right"}, true); + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_right"}, true).passEvent; } if (found) @@ -500,7 +500,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { if (e.state == WL_POINTER_BUTTON_STATE_PRESSED) { m_dPressedKeys.push_back(KEY); - suppressEvent = handleKeybinds(MODS, KEY, true); + suppressEvent = !handleKeybinds(MODS, KEY, true).passEvent; if (suppressEvent) shadowKeybinds(); @@ -510,7 +510,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { bool foundInPressedKeys = false; for (auto it = m_dPressedKeys.begin(); it != m_dPressedKeys.end();) { if (it->keyName == KEY_NAME) { - suppressEvent = handleKeybinds(MODS, *it, false); + suppressEvent = !handleKeybinds(MODS, *it, false).passEvent; foundInPressedKeys = true; suppressEvent = !it->sent; it = m_dPressedKeys.erase(it); @@ -521,7 +521,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { if (!foundInPressedKeys) { Debug::log(ERR, "BUG THIS: key not found in m_dPressedKeys (2)"); // fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy - suppressEvent = handleKeybinds(MODS, KEY, false); + suppressEvent = !handleKeybinds(MODS, KEY, false).passEvent; } shadowKeybinds(); @@ -590,8 +590,10 @@ eMultiKeyCase CKeybindManager::mkBindMatches(const SKeybind keybind) { return mkKeysymSetMatches(keybind.sMkKeys, m_sMkKeys); } -bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWithMods& key, bool pressed) { - bool found = false; +SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWithMods& key, bool pressed) { + static auto PDISABLEINHIBIT = CConfigValue<Hyprlang::INT>("binds:disable_keybind_grabbing"); + bool found = false; + SDispatchResult res; if (pressed) { if (keycodeToModifier(key.keycode)) @@ -605,11 +607,6 @@ bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWi m_sMkKeys.erase(key.keysym); } - static auto PDISABLEINHIBIT = CConfigValue<Hyprlang::INT>("binds:disable_keybind_grabbing"); - - if (!*PDISABLEINHIBIT && PROTO::shortcutsInhibit->isInhibited()) - Debug::log(LOG, "Keybind handling is disabled due to an inhibitor"); - for (auto& k : m_lKeybinds) { const bool SPECIALDISPATCHER = k.handler == "global" || k.handler == "pass" || k.handler == "sendshortcut" || k.handler == "mouse"; const bool SPECIALTRIGGERED = @@ -711,10 +708,11 @@ bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWi m_iPassPressed = (int)pressed; + // if the dispatchers says to pass event then we will if (k.handler == "mouse") - DISPATCHER->second((pressed ? "1" : "0") + k.arg); + res = DISPATCHER->second((pressed ? "1" : "0") + k.arg); else - DISPATCHER->second(k.arg); + res = DISPATCHER->second(k.arg); m_iPassPressed = -1; @@ -737,7 +735,18 @@ bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWi found = true; } - return found; + // if keybind wasn't found (or dispatcher said to) then pass event + res.passEvent |= !found; + + if (!found && !*PDISABLEINHIBIT && PROTO::shortcutsInhibit->isInhibited()) { + Debug::log(LOG, "Keybind handling is disabled due to an inhibitor"); + + res.success = false; + if (res.error.empty()) + res.error = "Keybind handling is disabled due to an inhibitor"; + } + + return res; } void CKeybindManager::shadowKeybinds(const xkb_keysym_t& doesntHave, const uint32_t doesntHaveCode) { @@ -838,7 +847,7 @@ bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) { // Dispatchers -void CKeybindManager::spawn(std::string args) { +SDispatchResult CKeybindManager::spawn(std::string args) { args = trim(args); @@ -850,7 +859,7 @@ void CKeybindManager::spawn(std::string args) { args = args.substr(args.find_first_of(']') + 1); } - const uint64_t PROC = spawnRaw(args); + const uint64_t PROC = spawnRawProc(args); if (!RULES.empty()) { const auto RULESLIST = CVarList(RULES, 0, ';'); @@ -861,9 +870,16 @@ void CKeybindManager::spawn(std::string args) { Debug::log(LOG, "Applied {} rule arguments for exec.", RULESLIST.size()); } + + return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)}; +} + +SDispatchResult CKeybindManager::spawnRaw(std::string args) { + const uint64_t PROC = spawnRawProc(args); + return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)}; } -uint64_t CKeybindManager::spawnRaw(std::string args) { +uint64_t CKeybindManager::spawnRawProc(std::string args) { Debug::log(LOG, "Executing {}", args); const auto HLENV = getHyprlandLaunchEnv(); @@ -924,26 +940,30 @@ uint64_t CKeybindManager::spawnRaw(std::string args) { return grandchild; } -void CKeybindManager::killActive(std::string args) { +SDispatchResult CKeybindManager::killActive(std::string args) { g_pCompositor->closeWindow(g_pCompositor->m_pLastWindow.lock()); + + return {}; } -void CKeybindManager::kill(std::string args) { +SDispatchResult CKeybindManager::kill(std::string args) { const auto PWINDOW = g_pCompositor->getWindowByRegex(args); if (!PWINDOW) { Debug::log(ERR, "kill: no window found"); - return; + return {.success = false, .error = "kill: no window found"}; } g_pCompositor->closeWindow(PWINDOW); + + return {}; } void CKeybindManager::clearKeybinds() { m_lKeybinds.clear(); } -static void toggleActiveFloatingCore(std::string args, std::optional<bool> floatState) { +static SDispatchResult toggleActiveFloatingCore(std::string args, std::optional<bool> floatState) { PHLWINDOW PWINDOW = nullptr; if (args != "active" && args.length() > 1) @@ -952,10 +972,10 @@ static void toggleActiveFloatingCore(std::string args, std::optional<bool> float PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; if (floatState.has_value() && floatState == PWINDOW->m_bIsFloating) - return; + return {}; // remove drag status if (!g_pInputManager->currentlyDraggedWindow.expired()) @@ -981,25 +1001,27 @@ static void toggleActiveFloatingCore(std::string args, std::optional<bool> float g_pCompositor->updateWorkspaceWindowData(PWINDOW->workspaceID()); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PWINDOW->m_iMonitorID); g_pCompositor->updateAllWindowsAnimatedDecorationValues(); + + return {}; } -void CKeybindManager::toggleActiveFloating(std::string args) { +SDispatchResult CKeybindManager::toggleActiveFloating(std::string args) { return toggleActiveFloatingCore(args, std::nullopt); } -void CKeybindManager::setActiveFloating(std::string args) { +SDispatchResult CKeybindManager::setActiveFloating(std::string args) { return toggleActiveFloatingCore(args, true); } -void CKeybindManager::setActiveTiled(std::string args) { +SDispatchResult CKeybindManager::setActiveTiled(std::string args) { return toggleActiveFloatingCore(args, false); } -void CKeybindManager::centerWindow(std::string args) { +SDispatchResult CKeybindManager::centerWindow(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || !PWINDOW->m_bIsFloating || PWINDOW->isFullscreen()) - return; + return {.success = false, .error = "No floating window found"}; const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); @@ -1009,9 +1031,11 @@ void CKeybindManager::centerWindow(std::string args) { PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.goal() / 2.f + RESERVEDOFFSET; PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goal(); + + return {}; } -void CKeybindManager::toggleActivePseudo(std::string args) { +SDispatchResult CKeybindManager::toggleActivePseudo(std::string args) { PHLWINDOW PWINDOW = nullptr; if (args != "active" && args.length() > 1) @@ -1020,12 +1044,14 @@ void CKeybindManager::toggleActivePseudo(std::string args) { PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; PWINDOW->m_bIsPseudotiled = !PWINDOW->m_bIsPseudotiled; if (!PWINDOW->isFullscreen()) g_pLayoutManager->getCurrentLayout()->recalculateWindow(PWINDOW); + + return {}; } SWorkspaceIDName getWorkspaceToChangeFromArgs(std::string args, PHLWORKSPACE PCURRENTWORKSPACE) { @@ -1051,7 +1077,7 @@ SWorkspaceIDName getWorkspaceToChangeFromArgs(std::string args, PHLWORKSPACE PCU return {ID, PPREVWS.name.empty() ? std::to_string(PPREVWS.id) : PPREVWS.name}; } -void CKeybindManager::changeworkspace(std::string args) { +SDispatchResult CKeybindManager::changeworkspace(std::string args) { // Workspace_back_and_forth being enabled means that an attempt to switch to // the current workspace will instead switch to the previous. static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth"); @@ -1061,7 +1087,7 @@ void CKeybindManager::changeworkspace(std::string args) { const auto PMONITOR = g_pCompositor->m_pLastMonitor.get(); if (!PMONITOR) - return; + return {.success = false, .error = "Last monitor not found"}; const auto PCURRENTWORKSPACE = PMONITOR->activeWorkspace; const bool EXPLICITPREVIOUS = args.contains("previous"); @@ -1069,18 +1095,17 @@ void CKeybindManager::changeworkspace(std::string args) { const auto& [workspaceToChangeTo, workspaceName] = getWorkspaceToChangeFromArgs(args, PCURRENTWORKSPACE); if (workspaceToChangeTo == WORKSPACE_INVALID) { Debug::log(ERR, "Error in changeworkspace, invalid value"); - return; + return {.success = false, .error = "Error in changeworkspace, invalid value"}; } - if (workspaceToChangeTo == WORKSPACE_NOT_CHANGED) { - return; - } + if (workspaceToChangeTo == WORKSPACE_NOT_CHANGED) + return {}; const auto PREVWS = PCURRENTWORKSPACE->getPrevWorkspaceIDName(args.contains("_per_monitor")); const bool BISWORKSPACECURRENT = workspaceToChangeTo == PCURRENTWORKSPACE->m_iID; if (BISWORKSPACECURRENT && (!(*PBACKANDFORTH || EXPLICITPREVIOUS) || PREVWS.id == -1)) - return; + return {.success = false, .error = "Previous workspace doesn't exist"}; g_pInputManager->unconstrainMouse(); g_pInputManager->m_bEmptyFocusCursorSet = false; @@ -1093,7 +1118,7 @@ void CKeybindManager::changeworkspace(std::string args) { if (!BISWORKSPACECURRENT && pWorkspaceToChangeTo->m_bIsSpecialWorkspace) { PMONITOR->setSpecialWorkspace(pWorkspaceToChangeTo); g_pInputManager->simulateMouseMovement(); - return; + return {}; } g_pInputManager->releaseAllMouseButtons(); @@ -1101,7 +1126,7 @@ void CKeybindManager::changeworkspace(std::string args) { const auto PMONITORWORKSPACEOWNER = PMONITOR->ID == pWorkspaceToChangeTo->m_iMonitorID ? PMONITOR : g_pCompositor->getMonitorFromID(pWorkspaceToChangeTo->m_iMonitorID); if (!PMONITORWORKSPACEOWNER) - return; + return {.success = false, .error = "Workspace to switch to has no monitor"}; updateRelativeCursorCoords(); @@ -1143,13 +1168,15 @@ void CKeybindManager::changeworkspace(std::string args) { if (PLAST && (!HLSurface || HLSurface->getWindow())) PLAST->warpCursor(); } + + return {}; } -void CKeybindManager::fullscreenActive(std::string args) { +SDispatchResult CKeybindManager::fullscreenActive(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; const eFullscreenMode MODE = args == "1" ? FSMODE_MAXIMIZED : FSMODE_FULLSCREEN; @@ -1157,14 +1184,16 @@ void CKeybindManager::fullscreenActive(std::string args) { g_pCompositor->setWindowFullscreenInternal(PWINDOW, FSMODE_NONE); else g_pCompositor->setWindowFullscreenInternal(PWINDOW, MODE); + + return {}; } -void CKeybindManager::fullscreenStateActive(std::string args) { +SDispatchResult CKeybindManager::fullscreenStateActive(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); const auto ARGS = CVarList(args, 2, ' '); if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; PWINDOW->m_sWindowData.syncFullscreen = CWindowOverridableVar(false, PRIORITY_SET_PROP); @@ -1189,9 +1218,11 @@ void CKeybindManager::fullscreenStateActive(std::string args) { g_pCompositor->setWindowFullscreenState(PWINDOW, STATE); PWINDOW->m_sWindowData.syncFullscreen = CWindowOverridableVar(PWINDOW->m_sFullscreenState.internal == PWINDOW->m_sFullscreenState.client, PRIORITY_SET_PROP); + + return {}; } -void CKeybindManager::moveActiveToWorkspace(std::string args) { +SDispatchResult CKeybindManager::moveActiveToWorkspace(std::string args) { PHLWINDOW PWINDOW = nullptr; @@ -1203,17 +1234,17 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { } if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; const auto& [WORKSPACEID, workspaceName] = getWorkspaceIDNameFromString(args); if (WORKSPACEID == WORKSPACE_INVALID) { Debug::log(LOG, "Invalid workspace in moveActiveToWorkspace"); - return; + return {.success = false, .error = "Invalid workspace in moveActiveToWorkspace"}; } if (WORKSPACEID == PWINDOW->workspaceID()) { Debug::log(LOG, "Not moving to workspace because it didn't change."); - return; + return {.success = false, .error = "Not moving to workspace because it didn't change."}; } auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID); @@ -1249,9 +1280,11 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { g_pCompositor->focusWindow(PWINDOW); PWINDOW->warpCursor(); + + return {}; } -void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { +SDispatchResult CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { PHLWINDOW PWINDOW = nullptr; const auto ORIGINALARGS = args; @@ -1264,16 +1297,16 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { } if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; const auto& [WORKSPACEID, workspaceName] = getWorkspaceIDNameFromString(args); if (WORKSPACEID == WORKSPACE_INVALID) { Debug::log(ERR, "Error in moveActiveToWorkspaceSilent, invalid value"); - return; + return {.success = false, .error = "Error in moveActiveToWorkspaceSilent, invalid value"}; } if (WORKSPACEID == PWINDOW->workspaceID()) - return; + return {}; g_pHyprRenderer->damageWindow(PWINDOW); @@ -1293,16 +1326,18 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { else g_pInputManager->refocus(); } + + return {}; } -void CKeybindManager::moveFocusTo(std::string args) { +SDispatchResult CKeybindManager::moveFocusTo(std::string args) { static auto PFULLCYCLE = CConfigValue<Hyprlang::INT>("binds:movefocus_cycles_fullscreen"); static auto PMONITORFALLBACK = CConfigValue<Hyprlang::INT>("binds:window_direction_monitor_fallback"); char arg = args[0]; if (!isDirection(args)) { Debug::log(ERR, "Cannot move focus in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); - return; + return {.success = false, .error = std::format("Cannot move focus in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg)}; } const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); @@ -1310,7 +1345,7 @@ void CKeybindManager::moveFocusTo(std::string args) { if (*PMONITORFALLBACK) tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg)); - return; + return {}; } const auto PWINDOWTOCHANGETO = *PFULLCYCLE && PLASTWINDOW->isFullscreen() ? @@ -1320,69 +1355,81 @@ void CKeybindManager::moveFocusTo(std::string args) { // Found window in direction, switch to it if (PWINDOWTOCHANGETO) { switchToWindow(PWINDOWTOCHANGETO); - return; + return {}; } Debug::log(LOG, "No window found in direction {}, looking for a monitor", arg); if (*PMONITORFALLBACK && tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg))) - return; + return {}; static auto PNOFALLBACK = CConfigValue<Hyprlang::INT>("general:no_focus_fallback"); if (*PNOFALLBACK) - return; + return {.success = false, .error = std::format("Nothing to focus to in direction {}", arg)}; Debug::log(LOG, "No monitor found in direction {}, falling back to next window on current workspace", arg); const auto PWINDOWNEXT = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true); if (PWINDOWNEXT) switchToWindow(PWINDOWNEXT); + + return {}; } -void CKeybindManager::focusUrgentOrLast(std::string args) { +SDispatchResult CKeybindManager::focusUrgentOrLast(std::string args) { const auto PWINDOWURGENT = g_pCompositor->getUrgentWindow(); const auto PWINDOWPREV = g_pCompositor->m_pLastWindow.lock() ? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1].lock()) : (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0].lock()); if (!PWINDOWURGENT && !PWINDOWPREV) - return; + return {.success = false, .error = "Window not found"}; switchToWindow(PWINDOWURGENT ? PWINDOWURGENT : PWINDOWPREV); + + return {}; } -void CKeybindManager::focusCurrentOrLast(std::string args) { +SDispatchResult CKeybindManager::focusCurrentOrLast(std::string args) { const auto PWINDOWPREV = g_pCompositor->m_pLastWindow.lock() ? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1].lock()) : (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0].lock()); if (!PWINDOWPREV) - return; + return {.success = false, .error = "Window not found"}; switchToWindow(PWINDOWPREV); + + return {}; } -void CKeybindManager::swapActive(std::string args) { +SDispatchResult CKeybindManager::swapActive(std::string args) { char arg = args[0]; if (!isDirection(args)) { Debug::log(ERR, "Cannot move window in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); - return; + return {.success = false, .error = std::format("Cannot move window in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg)}; } Debug::log(LOG, "Swapping active window in direction {}", arg); const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); - if (!PLASTWINDOW || PLASTWINDOW->isFullscreen()) - return; + + if (!PLASTWINDOW) + return {.success = false, .error = "Window to swap with not found"}; + + if (PLASTWINDOW->isFullscreen()) + return {.success = false, .error = "Can't swap fullscreen window"}; const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); if (!PWINDOWTOCHANGETO) - return; + return {.success = false, .error = "Window to swap with not found"}; updateRelativeCursorCoords(); g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO); PLASTWINDOW->warpCursor(); + + return {}; } -void CKeybindManager::moveActiveTo(std::string args) { +SDispatchResult CKeybindManager::moveActiveTo(std::string args) { char arg = args[0]; bool silent = args.ends_with(" silent"); if (silent) @@ -1391,25 +1438,28 @@ void CKeybindManager::moveActiveTo(std::string args) { if (args.starts_with("mon:")) { const auto PNEWMONITOR = g_pCompositor->getMonitorFromString(args.substr(4)); if (!PNEWMONITOR) - return; + return {.success = false, .error = std::format("Monitor {} not found", args.substr(4))}; if (silent) moveActiveToWorkspaceSilent(PNEWMONITOR->activeWorkspace->getConfigName()); else moveActiveToWorkspace(PNEWMONITOR->activeWorkspace->getConfigName()); - return; + return {}; } if (!isDirection(args)) { Debug::log(ERR, "Cannot move window in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); - return; + return {.success = false, .error = std::format("Cannot move window in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg)}; } const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); - if (!PLASTWINDOW || PLASTWINDOW->isFullscreen()) - return; + if (!PLASTWINDOW) + return {.success = false, .error = "Window to move not found"}; + + if (PLASTWINDOW->isFullscreen()) + return {.success = false, .error = "Can't move fullscreen window"}; if (PLASTWINDOW->m_bIsFloating) { std::optional<float> vPosx, vPosy; @@ -1427,7 +1477,7 @@ void CKeybindManager::moveActiveTo(std::string args) { PLASTWINDOW->m_vRealPosition = Vector2D(vPosx.value_or(PLASTWINDOW->m_vRealPosition.goal().x), vPosy.value_or(PLASTWINDOW->m_vRealPosition.goal().y)); - return; + return {}; } // If the window to change to is on the same workspace, switch them @@ -1438,30 +1488,32 @@ void CKeybindManager::moveActiveTo(std::string args) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PLASTWINDOW, args, silent); if (!silent) PLASTWINDOW->warpCursor(); - return; + return {}; } static auto PMONITORFALLBACK = CConfigValue<Hyprlang::INT>("binds:window_direction_monitor_fallback"); if (!*PMONITORFALLBACK) - return; + return {}; // Otherwise, we always want to move to the next monitor in that direction const auto PMONITORTOCHANGETO = g_pCompositor->getMonitorInDirection(arg); if (!PMONITORTOCHANGETO) - return; + return {.success = false, .error = "Nowhere to move active window to"}; const auto PWORKSPACE = PMONITORTOCHANGETO->activeWorkspace; if (silent) moveActiveToWorkspaceSilent(PWORKSPACE->getConfigName()); else moveActiveToWorkspace(PWORKSPACE->getConfigName()); + + return {}; } -void CKeybindManager::toggleGroup(std::string args) { +SDispatchResult CKeybindManager::toggleGroup(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; if (PWINDOW->isFullscreen()) g_pCompositor->setWindowFullscreenInternal(PWINDOW, FSMODE_NONE); @@ -1470,30 +1522,32 @@ void CKeybindManager::toggleGroup(std::string args) { PWINDOW->createGroup(); else PWINDOW->destroyGroup(); + + return {}; } -void CKeybindManager::changeGroupActive(std::string args) { +SDispatchResult CKeybindManager::changeGroupActive(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; if (PWINDOW->m_sGroupData.pNextWindow.expired()) - return; + return {.success = false, .error = "No next window in group"}; if (PWINDOW->m_sGroupData.pNextWindow.lock() == PWINDOW) - return; + return {.success = false, .error = "Only one window in group"}; if (isNumber(args, false)) { // index starts from '1'; '0' means last window const int INDEX = std::stoi(args); if (INDEX > PWINDOW->getGroupSize()) - return; + return {}; if (INDEX == 0) PWINDOW->setGroupCurrent(PWINDOW->getGroupTail()); else PWINDOW->setGroupCurrent(PWINDOW->getGroupWindowByIndex(INDEX - 1)); - return; + return {}; } if (args != "b" && args != "prev") { @@ -1501,39 +1555,45 @@ void CKeybindManager::changeGroupActive(std::string args) { } else { PWINDOW->setGroupCurrent(PWINDOW->getGroupPrevious()); } + + return {}; } -void CKeybindManager::toggleSplit(std::string args) { +SDispatchResult CKeybindManager::toggleSplit(std::string args) { SLayoutMessageHeader header; header.pWindow = g_pCompositor->m_pLastWindow.lock(); if (!header.pWindow) - return; + return {.success = false, .error = "Window not found"}; const auto PWORKSPACE = header.pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow) - return; + return {.success = false, .error = "Can't split windows that already split"}; g_pLayoutManager->getCurrentLayout()->layoutMessage(header, "togglesplit"); + + return {}; } -void CKeybindManager::swapSplit(std::string args) { +SDispatchResult CKeybindManager::swapSplit(std::string args) { SLayoutMessageHeader header; header.pWindow = g_pCompositor->m_pLastWindow.lock(); if (!header.pWindow) - return; + return {.success = false, .error = "Window not found"}; const auto PWORKSPACE = header.pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow) - return; + return {.success = false, .error = "Can't split windows that already split"}; g_pLayoutManager->getCurrentLayout()->layoutMessage(header, "swapsplit"); + + return {}; } -void CKeybindManager::alterSplitRatio(std::string args) { +SDispatchResult CKeybindManager::alterSplitRatio(std::string args) { std::optional<float> splitResult; bool exact = false; @@ -1545,39 +1605,43 @@ void CKeybindManager::alterSplitRatio(std::string args) { if (!splitResult.has_value()) { Debug::log(ERR, "Splitratio invalid in alterSplitRatio!"); - return; + return {.success = false, .error = "Splitratio invalid in alterSplitRatio!"}; } const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW) - return; + return {.success = false, .error = "Window not found"}; g_pLayoutManager->getCurrentLayout()->alterSplitRatio(PLASTWINDOW, splitResult.value(), exact); + + return {}; } -void CKeybindManager::focusMonitor(std::string arg) { +SDispatchResult CKeybindManager::focusMonitor(std::string arg) { const auto PMONITOR = g_pCompositor->getMonitorFromString(arg); tryMoveFocusToMonitor(PMONITOR); + + return {}; } -void CKeybindManager::moveCursorToCorner(std::string arg) { +SDispatchResult CKeybindManager::moveCursorToCorner(std::string arg) { if (!isNumber(arg)) { Debug::log(ERR, "moveCursorToCorner, arg has to be a number."); - return; + return {.success = false, .error = "moveCursorToCorner, arg has to be a number."}; } const auto CORNER = std::stoi(arg); if (CORNER < 0 || CORNER > 3) { Debug::log(ERR, "moveCursorToCorner, corner not 0 - 3."); - return; + return {.success = false, .error = "moveCursorToCorner, corner not 0 - 3."}; } const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW) - return; + return {.success = false, .error = "Window not found"}; switch (CORNER) { case 0: @@ -1598,16 +1662,18 @@ void CKeybindManager::moveCursorToCorner(std::string arg) { g_pCompositor->warpCursorTo({PWINDOW->m_vRealPosition.value().x, PWINDOW->m_vRealPosition.value().y}, true); break; } + + return {}; } -void CKeybindManager::moveCursor(std::string args) { +SDispatchResult CKeybindManager::moveCursor(std::string args) { std::string x_str, y_str; int x, y; size_t i = args.find_first_of(' '); if (i == std::string::npos) { Debug::log(ERR, "moveCursor, takes 2 arguments."); - return; + return {.success = false, .error = "moveCursor, takes 2 arguments"}; } x_str = args.substr(0, i); @@ -1615,26 +1681,28 @@ void CKeybindManager::moveCursor(std::string args) { if (!isNumber(x_str)) { Debug::log(ERR, "moveCursor, x argument has to be a number."); - return; + return {.success = false, .error = "moveCursor, x argument has to be a number."}; } if (!isNumber(y_str)) { Debug::log(ERR, "moveCursor, y argument has to be a number."); - return; + return {.success = false, .error = "moveCursor, y argument has to be a number."}; } x = std::stoi(x_str); y = std::stoi(y_str); g_pCompositor->warpCursorTo({x, y}, true); + + return {}; } -void CKeybindManager::workspaceOpt(std::string args) { +SDispatchResult CKeybindManager::workspaceOpt(std::string args) { // current workspace const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; if (!PWORKSPACE) - return; // ???? + return {.success = false, .error = "Workspace not found"}; // ???? if (args == "allpseudo") { PWORKSPACE->m_bDefaultPseudo = !PWORKSPACE->m_bDefaultPseudo; @@ -1677,14 +1745,16 @@ void CKeybindManager::workspaceOpt(std::string args) { } } else { Debug::log(ERR, "Invalid arg in workspaceOpt, opt \"{}\" doesn't exist.", args); - return; + return {.success = false, .error = std::format("Invalid arg in workspaceOpt, opt \"{}\" doesn't exist.", args)}; } // recalc mon g_pLayoutManager->getCurrentLayout()->recalculateMonitor(g_pCompositor->m_pLastMonitor->ID); + + return {}; } -void CKeybindManager::renameWorkspace(std::string args) { +SDispatchResult CKeybindManager::renameWorkspace(std::string args) { try { const auto FIRSTSPACEPOS = args.find_first_of(' '); if (FIRSTSPACEPOS != std::string::npos) { @@ -1694,34 +1764,42 @@ void CKeybindManager::renameWorkspace(std::string args) { } else { g_pCompositor->renameWorkspace(std::stoi(args), ""); } - } catch (std::exception& e) { Debug::log(ERR, "Invalid arg in renameWorkspace, expected numeric id only or a numeric id and string name. \"{}\": \"{}\"", args, e.what()); } + } catch (std::exception& e) { + Debug::log(ERR, "Invalid arg in renameWorkspace, expected numeric id only or a numeric id and string name. \"{}\": \"{}\"", args, e.what()); + return {.success = false, .error = std::format("Invalid arg in renameWorkspace, expected numeric id only or a numeric id and string name. \"{}\": \"{}\"", args, e.what())}; + } + + return {}; } -void CKeybindManager::exitHyprland(std::string argz) { +SDispatchResult CKeybindManager::exitHyprland(std::string argz) { g_pCompositor->stopCompositor(); + return {}; } -void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) { +SDispatchResult CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) { CMonitor* PMONITOR = g_pCompositor->getMonitorFromString(args); if (!PMONITOR) { Debug::log(ERR, "Ignoring moveCurrentWorkspaceToMonitor: monitor doesnt exist"); - return; + return {.success = false, .error = "Ignoring moveCurrentWorkspaceToMonitor: monitor doesnt exist"}; } // get the current workspace const auto PCURRENTWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; if (!PCURRENTWORKSPACE) { Debug::log(ERR, "moveCurrentWorkspaceToMonitor invalid workspace!"); - return; + return {.success = false, .error = "moveCurrentWorkspaceToMonitor invalid workspace!"}; } g_pCompositor->moveWorkspaceToMonitor(PCURRENTWORKSPACE, PMONITOR); + + return {}; } -void CKeybindManager::moveWorkspaceToMonitor(std::string args) { +SDispatchResult CKeybindManager::moveWorkspaceToMonitor(std::string args) { if (!args.contains(' ')) - return; + return {}; std::string workspace = args.substr(0, args.find_first_of(' ')); std::string monitor = args.substr(args.find_first_of(' ') + 1); @@ -1730,38 +1808,40 @@ void CKeybindManager::moveWorkspaceToMonitor(std::string args) { if (!PMONITOR) { Debug::log(ERR, "Ignoring moveWorkspaceToMonitor: monitor doesnt exist"); - return; + return {.success = false, .error = "Ignoring moveWorkspaceToMonitor: monitor doesnt exist"}; } const auto WORKSPACEID = getWorkspaceIDNameFromString(workspace).id; if (WORKSPACEID == WORKSPACE_INVALID) { Debug::log(ERR, "moveWorkspaceToMonitor invalid workspace!"); - return; + return {.success = false, .error = "moveWorkspaceToMonitor invalid workspace!"}; } const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID); if (!PWORKSPACE) { Debug::log(ERR, "moveWorkspaceToMonitor workspace doesn't exist!"); - return; + return {.success = false, .error = "moveWorkspaceToMonitor workspace doesn't exist!"}; } g_pCompositor->moveWorkspaceToMonitor(PWORKSPACE, PMONITOR); + + return {}; } -void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { +SDispatchResult CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { auto workspaceID = getWorkspaceIDNameFromString(args).id; if (workspaceID == WORKSPACE_INVALID) { Debug::log(ERR, "focusWorkspaceOnCurrentMonitor invalid workspace!"); - return; + return {.success = false, .error = "focusWorkspaceOnCurrentMonitor invalid workspace!"}; } const auto PCURRMONITOR = g_pCompositor->m_pLastMonitor.get(); if (!PCURRMONITOR) { Debug::log(ERR, "focusWorkspaceOnCurrentMonitor monitor doesn't exist!"); - return; + return {.success = false, .error = "focusWorkspaceOnCurrentMonitor monitor doesn't exist!"}; } auto pWorkspace = g_pCompositor->getWorkspaceByID(workspaceID); @@ -1770,7 +1850,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { pWorkspace = g_pCompositor->createNewWorkspace(workspaceID, PCURRMONITOR->ID); // we can skip the moving, since it's already on the current monitor changeworkspace(pWorkspace->getConfigName()); - return; + return {}; } static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth"); @@ -1789,24 +1869,26 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { const auto POLDMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); if (!POLDMONITOR) { // wat Debug::log(ERR, "focusWorkspaceOnCurrentMonitor old monitor doesn't exist!"); - return; + return {.success = false, .error = "focusWorkspaceOnCurrentMonitor old monitor doesn't exist!"}; } if (POLDMONITOR->activeWorkspaceID() == workspaceID) { g_pCompositor->swapActiveWorkspaces(POLDMONITOR, PCURRMONITOR); - return; + return {}; } else { g_pCompositor->moveWorkspaceToMonitor(pWorkspace, PCURRMONITOR, true); } } changeworkspace(pWorkspace->getConfigName()); + + return {}; } -void CKeybindManager::toggleSpecialWorkspace(std::string args) { +SDispatchResult CKeybindManager::toggleSpecialWorkspace(std::string args) { const auto& [workspaceID, workspaceName] = getWorkspaceIDNameFromString("special:" + args); if (workspaceID == WORKSPACE_INVALID || !g_pCompositor->isWorkspaceSpecial(workspaceID)) { Debug::log(ERR, "Invalid workspace passed to special"); - return; + return {.success = false, .error = "Invalid workspace passed to special"}; } bool requestedWorkspaceIsAlreadyOpen = false; @@ -1833,9 +1915,11 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { PMONITOR->setSpecialWorkspace(PSPECIALWORKSPACE); } + + return {}; } -void CKeybindManager::forceRendererReload(std::string args) { +SDispatchResult CKeybindManager::forceRendererReload(std::string args) { bool overAgain = false; for (auto& m : g_pCompositor->m_vMonitors) { @@ -1851,37 +1935,43 @@ void CKeybindManager::forceRendererReload(std::string args) { if (overAgain) forceRendererReload(args); + + return {}; } -void CKeybindManager::resizeActive(std::string args) { +SDispatchResult CKeybindManager::resizeActive(std::string args) { const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW || PLASTWINDOW->isFullscreen()) - return; + return {}; const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, PLASTWINDOW->m_vRealSize.goal()); if (SIZ.x < 1 || SIZ.y < 1) - return; + return {}; g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PLASTWINDOW->m_vRealSize.goal()); if (PLASTWINDOW->m_vRealSize.goal().x > 1 && PLASTWINDOW->m_vRealSize.goal().y > 1) PLASTWINDOW->setHidden(false); + + return {}; } -void CKeybindManager::moveActive(std::string args) { +SDispatchResult CKeybindManager::moveActive(std::string args) { const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW || PLASTWINDOW->isFullscreen()) - return; + return {}; const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, PLASTWINDOW->m_vRealPosition.goal()); g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - PLASTWINDOW->m_vRealPosition.goal()); + + return {}; } -void CKeybindManager::moveWindow(std::string args) { +SDispatchResult CKeybindManager::moveWindow(std::string args) { const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1); const auto MOVECMD = args.substr(0, args.find_first_of(',')); @@ -1890,18 +1980,20 @@ void CKeybindManager::moveWindow(std::string args) { if (!PWINDOW) { Debug::log(ERR, "moveWindow: no window"); - return; + return {.success = false, .error = "moveWindow: no window"}; } if (PWINDOW->isFullscreen()) - return; + return {}; const auto POS = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealPosition.goal()); g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - PWINDOW->m_vRealPosition.goal(), PWINDOW); + + return {}; } -void CKeybindManager::resizeWindow(std::string args) { +SDispatchResult CKeybindManager::resizeWindow(std::string args) { const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1); const auto MOVECMD = args.substr(0, args.find_first_of(',')); @@ -1910,24 +2002,26 @@ void CKeybindManager::resizeWindow(std::string args) { if (!PWINDOW) { Debug::log(ERR, "resizeWindow: no window"); - return; + return {.success = false, .error = "resizeWindow: no window"}; } if (PWINDOW->isFullscreen()) - return; + return {}; const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealSize.goal()); if (SIZ.x < 1 || SIZ.y < 1) - return; + return {}; g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PWINDOW->m_vRealSize.goal(), CORNER_NONE, PWINDOW); if (PWINDOW->m_vRealSize.goal().x > 1 && PWINDOW->m_vRealSize.goal().y > 1) PWINDOW->setHidden(false); + + return {}; } -void CKeybindManager::circleNext(std::string arg) { +SDispatchResult CKeybindManager::circleNext(std::string arg) { if (g_pCompositor->m_pLastWindow.expired()) { // if we have a clear focus, find the first window and get the next focusable. @@ -1937,7 +2031,7 @@ void CKeybindManager::circleNext(std::string arg) { switchToWindow(PWINDOW); } - return; + return {}; } CVarList args{arg, 0, 's', true}; @@ -1952,20 +2046,22 @@ void CKeybindManager::circleNext(std::string arg) { switchToWindow(g_pCompositor->getPrevWindowOnWorkspace(g_pCompositor->m_pLastWindow.lock(), true, floatStatus)); else switchToWindow(g_pCompositor->getNextWindowOnWorkspace(g_pCompositor->m_pLastWindow.lock(), true, floatStatus)); + + return {}; } -void CKeybindManager::focusWindow(std::string regexp) { +SDispatchResult CKeybindManager::focusWindow(std::string regexp) { const auto PWINDOW = g_pCompositor->getWindowByRegex(regexp); if (!PWINDOW) - return; + return {}; Debug::log(LOG, "Focusing to window name: {}", PWINDOW->m_szTitle); const auto PWORKSPACE = PWINDOW->m_pWorkspace; if (!PWORKSPACE) { Debug::log(ERR, "BUG THIS: null workspace in focusWindow"); - return; + return {.success = false, .error = "BUG THIS: null workspace in focusWindow"}; } updateRelativeCursorCoords(); @@ -2001,9 +2097,11 @@ void CKeybindManager::focusWindow(std::string regexp) { g_pCompositor->focusWindow(PWINDOW); PWINDOW->warpCursor(); + + return {}; } -void CKeybindManager::tagWindow(std::string args) { +SDispatchResult CKeybindManager::tagWindow(std::string args) { PHLWINDOW PWINDOW = nullptr; CVarList vars{args, 0, 's', true}; @@ -2012,21 +2110,23 @@ void CKeybindManager::tagWindow(std::string args) { else if (vars.size() == 2) PWINDOW = g_pCompositor->getWindowByRegex(vars[1]); else - return; + return {}; if (PWINDOW && PWINDOW->m_tags.applyTag(vars[0])) { PWINDOW->updateDynamicRules(); g_pCompositor->updateWindowAnimatedDecorationValues(PWINDOW->m_pSelf.lock()); } + + return {}; } -void CKeybindManager::setSubmap(std::string submap) { +SDispatchResult CKeybindManager::setSubmap(std::string submap) { if (submap == "reset" || submap == "") { m_szCurrentSelectedSubmap = ""; Debug::log(LOG, "Reset active submap to the default one."); g_pEventManager->postEvent(SHyprIPCEvent{"submap", ""}); EMIT_HOOK_EVENT("submap", m_szCurrentSelectedSubmap); - return; + return {}; } for (auto& k : g_pKeybindManager->m_lKeybinds) { @@ -2035,26 +2135,27 @@ void CKeybindManager::setSubmap(std::string submap) { Debug::log(LOG, "Changed keybind submap to {}", submap); g_pEventManager->postEvent(SHyprIPCEvent{"submap", submap}); EMIT_HOOK_EVENT("submap", m_szCurrentSelectedSubmap); - return; + return {}; } } Debug::log(ERR, "Cannot set submap {}, submap doesn't exist (wasn't registered!)", submap); + return {.success = false, .error = std::format("Cannot set submap {}, submap doesn't exist (wasn't registered!)", submap)}; } -void CKeybindManager::pass(std::string regexp) { +SDispatchResult CKeybindManager::pass(std::string regexp) { // find the first window passing the regex const auto PWINDOW = g_pCompositor->getWindowByRegex(regexp); if (!PWINDOW) { Debug::log(ERR, "pass: window not found"); - return; + return {.success = false, .error = "pass: window not found"}; } if (!g_pSeatManager->keyboard) { Debug::log(ERR, "No kb in pass?"); - return; + return {.success = false, .error = "No kb in pass?"}; } const auto XWTOXW = PWINDOW->m_bIsX11 && g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bIsX11; @@ -2093,7 +2194,7 @@ void CKeybindManager::pass(std::string regexp) { } if (XWTOXW) - return; + return {}; // Massive hack: // this will make g_pSeatManager NOT send the leave event to XWayland apps, provided we are not on an XWayland window already. @@ -2114,14 +2215,16 @@ void CKeybindManager::pass(std::string regexp) { g_pSeatManager->setKeyboardFocus(LASTKBSURF); else g_pSeatManager->setPointerFocus(LASTMOUSESURF, SL); + + return {}; } -void CKeybindManager::sendshortcut(std::string args) { +SDispatchResult CKeybindManager::sendshortcut(std::string args) { // args=<NEW_MODKEYS><NEW_KEY>[,WINDOW_RULES] const auto ARGS = CVarList(args, 3); if (ARGS.size() != 3) { Debug::log(ERR, "sendshortcut: invalid args"); - return; + return {.success = false, .error = "sendshortcut: invalid args"}; } const auto MOD = g_pKeybindManager->stringToModMask(ARGS[0]); @@ -2139,7 +2242,7 @@ void CKeybindManager::sendshortcut(std::string args) { isMouse = 1; if (keycode < 272) { Debug::log(ERR, "sendshortcut: invalid mouse button"); - return; + return {.success = false, .error = "sendshortcut: invalid mouse button"}; } } else { @@ -2154,7 +2257,7 @@ void CKeybindManager::sendshortcut(std::string args) { if (!KB) { Debug::log(ERR, "sendshortcut: no kb"); - return; + return {.success = false, .error = "sendshortcut: no kb"}; } const auto KEYPAIRSTRING = std::format("{}{}", (uintptr_t)KB.get(), KEY); @@ -2178,7 +2281,7 @@ void CKeybindManager::sendshortcut(std::string args) { if (!keycode) { Debug::log(ERR, "sendshortcut: key not found"); - return; + return {.success = false, .error = "sendshortcut: key not found"}; } } else @@ -2187,7 +2290,7 @@ void CKeybindManager::sendshortcut(std::string args) { if (!keycode) { Debug::log(ERR, "sendshortcut: invalid key"); - return; + return {.success = false, .error = "sendshortcut: invalid key"}; } const std::string regexp = ARGS[2]; @@ -2201,12 +2304,12 @@ void CKeybindManager::sendshortcut(std::string args) { if (!PWINDOW) { Debug::log(ERR, "sendshortcut: window not found"); - return; + return {.success = false, .error = "sendshortcut: window not found"}; } if (!g_pSeatManager->keyboard) { Debug::log(ERR, "No kb in sendshortcut?"); - return; + return {.success = false, .error = "No kb in sendshortcut?"}; } if (!isMouse) @@ -2247,7 +2350,7 @@ void CKeybindManager::sendshortcut(std::string args) { } if (!PWINDOW) - return; + return {}; if (PWINDOW->m_bIsX11) { //xwayland hack, see pass if (!isMouse) { @@ -2265,16 +2368,21 @@ void CKeybindManager::sendshortcut(std::string args) { g_pSeatManager->setKeyboardFocus(LASTSURFACE); else g_pSeatManager->setPointerFocus(LASTSURFACE, SL); + + return {}; } -void CKeybindManager::layoutmsg(std::string msg) { +SDispatchResult CKeybindManager::layoutmsg(std::string msg) { SLayoutMessageHeader hd = {g_pCompositor->m_pLastWindow.lock()}; g_pLayoutManager->getCurrentLayout()->layoutMessage(hd, msg); + + return {}; } -void CKeybindManager::dpms(std::string arg) { - bool enable = arg.starts_with("on"); - std::string port = ""; +SDispatchResult CKeybindManager::dpms(std::string arg) { + SDispatchResult res; + bool enable = arg.starts_with("on"); + std::string port = ""; if (arg.starts_with("toggle")) enable = !std::any_of(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](const auto& other) { return !other->dpmsStatus; }); // enable if any is off @@ -2294,6 +2402,8 @@ void CKeybindManager::dpms(std::string arg) { if (!m->state.commit()) { Debug::log(ERR, "Couldn't commit output {}", m->szName); + res.success = false; + res.error = "Couldn't commit output {}"; } if (enable) @@ -2305,14 +2415,16 @@ void CKeybindManager::dpms(std::string arg) { g_pCompositor->m_bDPMSStateON = enable; g_pPointerManager->recheckEnteredOutputs(); + + return res; } -void CKeybindManager::swapnext(std::string arg) { +SDispatchResult CKeybindManager::swapnext(std::string arg) { PHLWINDOW toSwap = nullptr; if (g_pCompositor->m_pLastWindow.expired()) - return; + return {}; const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); @@ -2339,9 +2451,11 @@ void CKeybindManager::swapnext(std::string arg) { PLASTWINDOW->m_pLastCycledWindow = toSwap; g_pCompositor->focusWindow(PLASTWINDOW); + + return {}; } -void CKeybindManager::swapActiveWorkspaces(std::string args) { +SDispatchResult CKeybindManager::swapActiveWorkspaces(std::string args) { const auto MON1 = args.substr(0, args.find_first_of(' ')); const auto MON2 = args.substr(args.find_first_of(' ') + 1); @@ -2349,12 +2463,14 @@ void CKeybindManager::swapActiveWorkspaces(std::string args) { const auto PMON2 = g_pCompositor->getMonitorFromString(MON2); if (!PMON1 || !PMON2 || PMON1 == PMON2) - return; + return {}; g_pCompositor->swapActiveWorkspaces(PMON1, PMON2); + + return {}; } -void CKeybindManager::pinActive(std::string args) { +SDispatchResult CKeybindManager::pinActive(std::string args) { PHLWINDOW PWINDOW = nullptr; @@ -2365,11 +2481,11 @@ void CKeybindManager::pinActive(std::string args) { if (!PWINDOW) { Debug::log(ERR, "pin: window not found"); - return; + return {.success = false, .error = "pin: window not found"}; } if (!PWINDOW->m_bIsFloating || PWINDOW->isFullscreen()) - return; + return {}; PWINDOW->m_bPinned = !PWINDOW->m_bPinned; @@ -2377,7 +2493,7 @@ void CKeybindManager::pinActive(std::string args) { if (!PMONITOR) { Debug::log(ERR, "pin: monitor not found"); - return; + return {.success = false, .error = "pin: window not found"}; } PWINDOW->m_pWorkspace = PMONITOR->activeWorkspace; @@ -2391,40 +2507,41 @@ void CKeybindManager::pinActive(std::string args) { g_pEventManager->postEvent(SHyprIPCEvent{"pin", std::format("{:x},{}", (uintptr_t)PWINDOW.get(), (int)PWINDOW->m_bPinned)}); EMIT_HOOK_EVENT("pin", PWINDOW); + + return {}; } -void CKeybindManager::mouse(std::string args) { +SDispatchResult CKeybindManager::mouse(std::string args) { const auto ARGS = CVarList(args.substr(1), 2, ' '); const auto PRESSED = args[0] == '1'; if (!PRESSED) { - changeMouseBindMode(MBIND_INVALID); - return; + return changeMouseBindMode(MBIND_INVALID); } if (ARGS[0] == "movewindow") { - changeMouseBindMode(MBIND_MOVE); + return changeMouseBindMode(MBIND_MOVE); } else { try { switch (std::stoi(ARGS[1])) { - case 1: changeMouseBindMode(MBIND_RESIZE_FORCE_RATIO); break; - case 2: changeMouseBindMode(MBIND_RESIZE_BLOCK_RATIO); break; - default: changeMouseBindMode(MBIND_RESIZE); + case 1: return changeMouseBindMode(MBIND_RESIZE_FORCE_RATIO); break; + case 2: return changeMouseBindMode(MBIND_RESIZE_BLOCK_RATIO); break; + default: return changeMouseBindMode(MBIND_RESIZE); } - } catch (std::exception& e) { changeMouseBindMode(MBIND_RESIZE); } + } catch (std::exception& e) { return changeMouseBindMode(MBIND_RESIZE); } } } -void CKeybindManager::changeMouseBindMode(const eMouseBindMode MODE) { +SDispatchResult CKeybindManager::changeMouseBindMode(const eMouseBindMode MODE) { if (MODE != MBIND_INVALID) { if (!g_pInputManager->currentlyDraggedWindow.expired() || g_pInputManager->dragMode != MBIND_INVALID) - return; + return {}; const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); const PHLWINDOW PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!PWINDOW) - return; + return SDispatchResult{.passEvent = true}; if (!PWINDOW->isFullscreen() && MODE == MBIND_MOVE) PWINDOW->checkInputOnDecos(INPUT_TYPE_DRAG_START, MOUSECOORDS); @@ -2437,19 +2554,23 @@ void CKeybindManager::changeMouseBindMode(const eMouseBindMode MODE) { g_pLayoutManager->getCurrentLayout()->onBeginDragWindow(); } else { if (g_pInputManager->currentlyDraggedWindow.expired() || g_pInputManager->dragMode == MBIND_INVALID) - return; + return {}; g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); g_pInputManager->dragMode = MODE; } + + return {}; } -void CKeybindManager::bringActiveToTop(std::string args) { +SDispatchResult CKeybindManager::bringActiveToTop(std::string args) { if (g_pCompositor->m_pLastWindow.lock() && g_pCompositor->m_pLastWindow->m_bIsFloating) g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow.lock(), true); + + return {}; } -void CKeybindManager::alterZOrder(std::string args) { +SDispatchResult CKeybindManager::alterZOrder(std::string args) { const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1); const auto POSITION = args.substr(0, args.find_first_of(',')); auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX); @@ -2459,7 +2580,7 @@ void CKeybindManager::alterZOrder(std::string args) { if (!PWINDOW) { Debug::log(ERR, "alterZOrder: no window"); - return; + return {.success = false, .error = "alterZOrder: no window"}; } if (POSITION == "top") @@ -2468,13 +2589,15 @@ void CKeybindManager::alterZOrder(std::string args) { g_pCompositor->changeWindowZOrder(PWINDOW, 0); else { Debug::log(ERR, "alterZOrder: bad position: {}", POSITION); - return; + return {.success = false, .error = "alterZOrder: bad position: {}"}; } g_pInputManager->simulateMouseMovement(); + + return {}; } -void CKeybindManager::lockGroups(std::string args) { +SDispatchResult CKeybindManager::lockGroups(std::string args) { if (args == "lock" || args.empty() || args == "lockgroups") g_pKeybindManager->m_bGroupsLocked = true; else if (args == "toggle") @@ -2483,13 +2606,15 @@ void CKeybindManager::lockGroups(std::string args) { g_pKeybindManager->m_bGroupsLocked = false; g_pEventManager->postEvent(SHyprIPCEvent{"lockgroups", g_pKeybindManager->m_bGroupsLocked ? "1" : "0"}); + + return {}; } -void CKeybindManager::lockActiveGroup(std::string args) { +SDispatchResult CKeybindManager::lockActiveGroup(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || !PWINDOW->m_sGroupData.pNextWindow.lock()) - return; + return {}; const auto PHEAD = PWINDOW->getGroupHead(); @@ -2501,6 +2626,8 @@ void CKeybindManager::lockActiveGroup(std::string args) { PHEAD->m_sGroupData.locked = false; g_pCompositor->updateWindowAnimatedDecorationValues(PWINDOW); + + return {}; } void CKeybindManager::moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection) { @@ -2573,41 +2700,43 @@ void CKeybindManager::moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& g_pEventManager->postEvent(SHyprIPCEvent{"moveoutofgroup", std::format("{:x}", (uintptr_t)pWindow.get())}); } -void CKeybindManager::moveIntoGroup(std::string args) { +SDispatchResult CKeybindManager::moveIntoGroup(std::string args) { char arg = args[0]; static auto PIGNOREGROUPLOCK = CConfigValue<Hyprlang::INT>("binds:ignore_group_lock"); if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) - return; + return {}; if (!isDirection(args)) { Debug::log(ERR, "Cannot move into group in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); - return; + return {.success = false, .error = std::format("Cannot move into group in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg)}; } const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || PWINDOW->m_bIsFloating || PWINDOW->m_sGroupData.deny) - return; + return {}; auto PWINDOWINDIR = g_pCompositor->getWindowInDirection(PWINDOW, arg); if (!PWINDOWINDIR || !PWINDOWINDIR->m_sGroupData.pNextWindow.lock()) - return; + return {}; // Do not move window into locked group if binds:ignore_group_lock is false if (!*PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || (PWINDOW->m_sGroupData.pNextWindow.lock() && PWINDOW->getGroupHead()->m_sGroupData.locked))) - return; + return {}; moveWindowIntoGroup(PWINDOW, PWINDOWINDIR); + + return {}; } -void CKeybindManager::moveOutOfGroup(std::string args) { +SDispatchResult CKeybindManager::moveOutOfGroup(std::string args) { static auto PIGNOREGROUPLOCK = CConfigValue<Hyprlang::INT>("binds:ignore_group_lock"); if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) - return; + return {}; PHLWINDOW PWINDOW = nullptr; @@ -2617,28 +2746,30 @@ void CKeybindManager::moveOutOfGroup(std::string args) { PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || !PWINDOW->m_sGroupData.pNextWindow.lock()) - return; + return {}; moveWindowOutOfGroup(PWINDOW); + + return {}; } -void CKeybindManager::moveWindowOrGroup(std::string args) { +SDispatchResult CKeybindManager::moveWindowOrGroup(std::string args) { char arg = args[0]; static auto PIGNOREGROUPLOCK = CConfigValue<Hyprlang::INT>("binds:ignore_group_lock"); if (!isDirection(args)) { Debug::log(ERR, "Cannot move into group in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); - return; + return {.success = false, .error = std::format("Cannot move into group in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg)}; } const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || PWINDOW->isFullscreen()) - return; + return {}; if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args); - return; + return {}; } const auto PWINDOWINDIR = g_pCompositor->getWindowInDirection(PWINDOW, arg); @@ -2670,9 +2801,11 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { } g_pCompositor->updateWindowAnimatedDecorationValues(PWINDOW); + + return {}; } -void CKeybindManager::setIgnoreGroupLock(std::string args) { +SDispatchResult CKeybindManager::setIgnoreGroupLock(std::string args) { static auto PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); if (args == "toggle") @@ -2681,12 +2814,14 @@ void CKeybindManager::setIgnoreGroupLock(std::string args) { **PIGNOREGROUPLOCK = args == "on"; g_pEventManager->postEvent(SHyprIPCEvent{"ignoregrouplock", std::to_string(**PIGNOREGROUPLOCK)}); + + return {}; } -void CKeybindManager::denyWindowFromGroup(std::string args) { +SDispatchResult CKeybindManager::denyWindowFromGroup(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PWINDOW || (PWINDOW && PWINDOW->m_sGroupData.pNextWindow.lock())) - return; + return {}; if (args == "toggle") PWINDOW->m_sGroupData.deny = !PWINDOW->m_sGroupData.deny; @@ -2694,28 +2829,32 @@ void CKeybindManager::denyWindowFromGroup(std::string args) { PWINDOW->m_sGroupData.deny = args == "on"; g_pCompositor->updateWindowAnimatedDecorationValues(PWINDOW); + + return {}; } -void CKeybindManager::global(std::string args) { +SDispatchResult CKeybindManager::global(std::string args) { const auto APPID = args.substr(0, args.find_first_of(':')); const auto NAME = args.substr(args.find_first_of(':') + 1); if (NAME.empty()) - return; + return {}; if (!PROTO::globalShortcuts->isTaken(APPID, NAME)) - return; + return {}; PROTO::globalShortcuts->sendGlobalShortcutEvent(APPID, NAME, g_pKeybindManager->m_iPassPressed); + + return {}; } -void CKeybindManager::moveGroupWindow(std::string args) { +SDispatchResult CKeybindManager::moveGroupWindow(std::string args) { const auto BACK = args == "b" || args == "prev"; const auto PLASTWINDOW = g_pCompositor->m_pLastWindow.lock(); if (!PLASTWINDOW || !PLASTWINDOW->m_sGroupData.pNextWindow.lock()) - return; + return {}; if ((!BACK && PLASTWINDOW->m_sGroupData.pNextWindow->m_sGroupData.head) || (BACK && PLASTWINDOW->m_sGroupData.head)) { std::swap(PLASTWINDOW->m_sGroupData.head, PLASTWINDOW->m_sGroupData.pNextWindow->m_sGroupData.head); @@ -2724,8 +2863,11 @@ void CKeybindManager::moveGroupWindow(std::string args) { PLASTWINDOW->switchWithWindowInGroup(BACK ? PLASTWINDOW->getGroupPrevious() : PLASTWINDOW->m_sGroupData.pNextWindow.lock()); PLASTWINDOW->updateWindowDecos(); + + return {}; } -void CKeybindManager::event(std::string args) { +SDispatchResult CKeybindManager::event(std::string args) { g_pEventManager->postEvent(SHyprIPCEvent{"custom", args}); + return {}; } diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 26b42b00..d1f26c2c 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -71,33 +71,39 @@ enum eMultiKeyCase { MK_FULL_MATCH }; +struct SDispatchResult { + bool passEvent = false; + bool success = true; + std::string error; +}; + class CKeybindManager { public: CKeybindManager(); ~CKeybindManager(); - bool onKeyEvent(std::any, SP<IKeyboard>); - bool onAxisEvent(const IPointer::SAxisEvent&); - bool onMouseEvent(const IPointer::SButtonEvent&); - void resizeWithBorder(const IPointer::SButtonEvent&); - void onSwitchEvent(const std::string&); - void onSwitchOnEvent(const std::string&); - void onSwitchOffEvent(const std::string&); + bool onKeyEvent(std::any, SP<IKeyboard>); + bool onAxisEvent(const IPointer::SAxisEvent&); + bool onMouseEvent(const IPointer::SButtonEvent&); + void resizeWithBorder(const IPointer::SButtonEvent&); + void onSwitchEvent(const std::string&); + void onSwitchOnEvent(const std::string&); + void onSwitchOffEvent(const std::string&); - void addKeybind(SKeybind); - void removeKeybind(uint32_t, const SParsedKey&); - uint32_t stringToModMask(std::string); - uint32_t keycodeToModifier(xkb_keycode_t); - void clearKeybinds(); - void shadowKeybinds(const xkb_keysym_t& doesntHave = 0, const uint32_t doesntHaveCode = 0); + void addKeybind(SKeybind); + void removeKeybind(uint32_t, const SParsedKey&); + uint32_t stringToModMask(std::string); + uint32_t keycodeToModifier(xkb_keycode_t); + void clearKeybinds(); + void shadowKeybinds(const xkb_keysym_t& doesntHave = 0, const uint32_t doesntHaveCode = 0); - std::unordered_map<std::string, std::function<void(std::string)>> m_mDispatchers; + std::unordered_map<std::string, std::function<SDispatchResult(std::string)>> m_mDispatchers; - wl_event_source* m_pActiveKeybindEventSource = nullptr; + wl_event_source* m_pActiveKeybindEventSource = nullptr; - bool m_bGroupsLocked = false; + bool m_bGroupsLocked = false; - std::list<SKeybind> m_lKeybinds; + std::list<SKeybind> m_lKeybinds; //since we cant find keycode through keyname in xkb: //on sendshortcut call, we once search for keyname (e.g. "g") the correct keycode (e.g. 42) @@ -105,7 +111,7 @@ class CKeybindManager { //we also store the keyboard pointer (in the string) to differentiate between different keyboard (layouts) std::unordered_map<std::string, xkb_keycode_t> m_mKeyToCodeCache; - static void changeMouseBindMode(const eMouseBindMode mode); + static SDispatchResult changeMouseBindMode(const eMouseBindMode mode); private: std::deque<SPressedKeyWithMods> m_dPressedKeys; @@ -124,7 +130,7 @@ class CKeybindManager { CTimer m_tScrollTimer; - bool handleKeybinds(const uint32_t, const SPressedKeyWithMods&, bool); + SDispatchResult handleKeybinds(const uint32_t, const SPressedKeyWithMods&, bool); std::set<xkb_keysym_t> m_sMkKeys = {}; std::set<xkb_keysym_t> m_sMkMods = {}; @@ -143,71 +149,72 @@ class CKeybindManager { static void moveWindowOutOfGroup(PHLWINDOW pWindow, const std::string& dir = ""); static void moveWindowIntoGroup(PHLWINDOW pWindow, PHLWINDOW pWindowInDirection); static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO); + static uint64_t spawnRawProc(std::string); // -------------- Dispatchers -------------- // - static void killActive(std::string); - static void kill(std::string); - static void spawn(std::string); - static uint64_t spawnRaw(std::string); - static void toggleActiveFloating(std::string); - static void toggleActivePseudo(std::string); - static void setActiveFloating(std::string); - static void setActiveTiled(std::string); - static void changeworkspace(std::string); - static void fullscreenActive(std::string); - static void fullscreenStateActive(std::string args); - static void moveActiveToWorkspace(std::string); - static void moveActiveToWorkspaceSilent(std::string); - static void moveFocusTo(std::string); - static void focusUrgentOrLast(std::string); - static void focusCurrentOrLast(std::string); - static void centerWindow(std::string); - static void moveActiveTo(std::string); - static void swapActive(std::string); - static void toggleGroup(std::string); - static void changeGroupActive(std::string); - static void alterSplitRatio(std::string); - static void focusMonitor(std::string); - static void toggleSplit(std::string); - static void swapSplit(std::string); - static void moveCursorToCorner(std::string); - static void moveCursor(std::string); - static void workspaceOpt(std::string); - static void renameWorkspace(std::string); - static void exitHyprland(std::string); - static void moveCurrentWorkspaceToMonitor(std::string); - static void moveWorkspaceToMonitor(std::string); - static void focusWorkspaceOnCurrentMonitor(std::string); - static void toggleSpecialWorkspace(std::string); - static void forceRendererReload(std::string); - static void resizeActive(std::string); - static void moveActive(std::string); - static void moveWindow(std::string); - static void resizeWindow(std::string); - static void circleNext(std::string); - static void focusWindow(std::string); - static void tagWindow(std::string); - static void setSubmap(std::string); - static void pass(std::string); - static void sendshortcut(std::string); - static void layoutmsg(std::string); - static void dpms(std::string); - static void swapnext(std::string); - static void swapActiveWorkspaces(std::string); - static void pinActive(std::string); - static void mouse(std::string); - static void bringActiveToTop(std::string); - static void alterZOrder(std::string); - static void lockGroups(std::string); - static void lockActiveGroup(std::string); - static void moveIntoGroup(std::string); - static void moveOutOfGroup(std::string); - static void moveGroupWindow(std::string); - static void moveWindowOrGroup(std::string); - static void setIgnoreGroupLock(std::string); - static void denyWindowFromGroup(std::string); - static void global(std::string); - static void event(std::string); + static SDispatchResult killActive(std::string); + static SDispatchResult kill(std::string); + static SDispatchResult spawn(std::string); + static SDispatchResult spawnRaw(std::string); + static SDispatchResult toggleActiveFloating(std::string); + static SDispatchResult toggleActivePseudo(std::string); + static SDispatchResult setActiveFloating(std::string); + static SDispatchResult setActiveTiled(std::string); + static SDispatchResult changeworkspace(std::string); + static SDispatchResult fullscreenActive(std::string); + static SDispatchResult fullscreenStateActive(std::string args); + static SDispatchResult moveActiveToWorkspace(std::string); + static SDispatchResult moveActiveToWorkspaceSilent(std::string); + static SDispatchResult moveFocusTo(std::string); + static SDispatchResult focusUrgentOrLast(std::string); + static SDispatchResult focusCurrentOrLast(std::string); + static SDispatchResult centerWindow(std::string); + static SDispatchResult moveActiveTo(std::string); + static SDispatchResult swapActive(std::string); + static SDispatchResult toggleGroup(std::string); + static SDispatchResult changeGroupActive(std::string); + static SDispatchResult alterSplitRatio(std::string); + static SDispatchResult focusMonitor(std::string); + static SDispatchResult toggleSplit(std::string); + static SDispatchResult swapSplit(std::string); + static SDispatchResult moveCursorToCorner(std::string); + static SDispatchResult moveCursor(std::string); + static SDispatchResult workspaceOpt(std::string); + static SDispatchResult renameWorkspace(std::string); + static SDispatchResult exitHyprland(std::string); + static SDispatchResult moveCurrentWorkspaceToMonitor(std::string); + static SDispatchResult moveWorkspaceToMonitor(std::string); + static SDispatchResult focusWorkspaceOnCurrentMonitor(std::string); + static SDispatchResult toggleSpecialWorkspace(std::string); + static SDispatchResult forceRendererReload(std::string); + static SDispatchResult resizeActive(std::string); + static SDispatchResult moveActive(std::string); + static SDispatchResult moveWindow(std::string); + static SDispatchResult resizeWindow(std::string); + static SDispatchResult circleNext(std::string); + static SDispatchResult focusWindow(std::string); + static SDispatchResult tagWindow(std::string); + static SDispatchResult setSubmap(std::string); + static SDispatchResult pass(std::string); + static SDispatchResult sendshortcut(std::string); + static SDispatchResult layoutmsg(std::string); + static SDispatchResult dpms(std::string); + static SDispatchResult swapnext(std::string); + static SDispatchResult swapActiveWorkspaces(std::string); + static SDispatchResult pinActive(std::string); + static SDispatchResult mouse(std::string); + static SDispatchResult bringActiveToTop(std::string); + static SDispatchResult alterZOrder(std::string); + static SDispatchResult lockGroups(std::string); + static SDispatchResult lockActiveGroup(std::string); + static SDispatchResult moveIntoGroup(std::string); + static SDispatchResult moveOutOfGroup(std::string); + static SDispatchResult moveGroupWindow(std::string); + static SDispatchResult moveWindowOrGroup(std::string); + static SDispatchResult setIgnoreGroupLock(std::string); + static SDispatchResult denyWindowFromGroup(std::string); + static SDispatchResult global(std::string); + static SDispatchResult event(std::string); friend class CCompositor; friend class CInputManager; diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index 098e3f12..398d4ce1 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -194,7 +194,10 @@ APICALL bool HyprlandAPI::addDispatcher(HANDLE handle, const std::string& name, PLUGIN->registeredDispatchers.push_back(name); - g_pKeybindManager->m_mDispatchers[name] = handler; + g_pKeybindManager->m_mDispatchers[name] = [handler](std::string arg1) -> SDispatchResult { + handler(arg1); + return {}; + }; return true; } @@ -378,4 +381,4 @@ APICALL bool HyprlandAPI::unregisterHyprCtlCommand(HANDLE handle, SP<SHyprCtlCom g_pHyprCtl->unregisterCommand(cmd); return true; -}
\ No newline at end of file +} |