move half da dispatchers to refactor

This commit is contained in:
ikalco 2024-08-13 21:32:32 -05:00
parent 3b4aabe04c
commit eab8af326f
2 changed files with 245 additions and 199 deletions

View File

@ -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,19 @@ 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()) {
// TODO: debug log errors from SDipatchResult somewhere else
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 +848,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 +860,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 +871,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)};
}
uint64_t CKeybindManager::spawnRaw(std::string 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::spawnRawProc(std::string args) {
Debug::log(LOG, "Executing {}", args);
const auto HLENV = getHyprlandLaunchEnv();
@ -924,16 +941,17 @@ 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());
}
void CKeybindManager::kill(std::string args) {
SDispatchResult CKeybindManager::kill(std::string args) {
const auto PWINDOW = g_pCompositor->getWindowByRegex(args);
if (!PWINDOW) {
// TODO: debug log errors from SDipatchResult somewhere else
Debug::log(ERR, "kill: no window found");
return;
return {.success = false, .error = "kill: no window found"};
}
g_pCompositor->closeWindow(PWINDOW);
@ -943,7 +961,7 @@ 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 +970,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())
@ -983,23 +1001,23 @@ static void toggleActiveFloatingCore(std::string args, std::optional<bool> float
g_pCompositor->updateAllWindowsAnimatedDecorationValues();
}
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);
@ -1011,7 +1029,7 @@ void CKeybindManager::centerWindow(std::string args) {
PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goal();
}
void CKeybindManager::toggleActivePseudo(std::string args) {
SDispatchResult CKeybindManager::toggleActivePseudo(std::string args) {
PHLWINDOW PWINDOW = nullptr;
if (args != "active" && args.length() > 1)
@ -1020,7 +1038,7 @@ 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;
@ -1051,7 +1069,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,26 +1079,26 @@ 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");
const auto& [workspaceToChangeTo, workspaceName] = getWorkspaceToChangeFromArgs(args, PCURRENTWORKSPACE);
if (workspaceToChangeTo == WORKSPACE_INVALID) {
// TODO: debug log errors from SDipatchResult somewhere else
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 +1111,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 +1119,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();
@ -1145,11 +1163,11 @@ void CKeybindManager::changeworkspace(std::string args) {
}
}
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;
@ -1159,12 +1177,12 @@ void CKeybindManager::fullscreenActive(std::string args) {
g_pCompositor->setWindowFullscreenInternal(PWINDOW, MODE);
}
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);
@ -1182,23 +1200,23 @@ void CKeybindManager::fullscreenStateActive(std::string args) {
if (internalMode != -1 && clientMode != -1 && PWINDOW->m_sFullscreenState.internal == STATE.internal && PWINDOW->m_sFullscreenState.client == STATE.client) {
g_pCompositor->setWindowFullscreenState(PWINDOW, sFullscreenState{.internal = FSMODE_NONE, .client = FSMODE_NONE});
PWINDOW->m_sWindowData.syncFullscreen = CWindowOverridableVar(true, PRIORITY_SET_PROP);
return;
return {};
}
if (internalMode != -1 && clientMode == -1 && PWINDOW->m_sFullscreenState.internal == STATE.internal) {
g_pCompositor->setWindowFullscreenState(PWINDOW, sFullscreenState{.internal = FSMODE_NONE, .client = PWINDOW->m_sFullscreenState.client});
return;
return {};
}
if (internalMode == -1 && clientMode != -1 && PWINDOW->m_sFullscreenState.client == STATE.client) {
g_pCompositor->setWindowFullscreenState(PWINDOW, sFullscreenState{.internal = PWINDOW->m_sFullscreenState.internal, .client = FSMODE_NONE});
return;
return {};
}
g_pCompositor->setWindowFullscreenState(PWINDOW, STATE);
}
void CKeybindManager::moveActiveToWorkspace(std::string args) {
SDispatchResult CKeybindManager::moveActiveToWorkspace(std::string args) {
PHLWINDOW PWINDOW = nullptr;
@ -1210,17 +1228,19 @@ 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) {
// TODO: debug log errors from SDipatchResult somewhere else
Debug::log(LOG, "Invalid workspace in moveActiveToWorkspace");
return;
return {.success = false, .error = "Invalid workspace in moveActiveToWorkspace"};
}
if (WORKSPACEID == PWINDOW->workspaceID()) {
// TODO: debug log errors from SDipatchResult somewhere else
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);
@ -1258,7 +1278,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
PWINDOW->warpCursor();
}
void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
SDispatchResult CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
PHLWINDOW PWINDOW = nullptr;
const auto ORIGINALARGS = args;
@ -1271,16 +1291,17 @@ 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) {
// TODO: debug log errors from SDipatchResult somewhere else
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);
@ -1302,14 +1323,14 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
}
}
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();
@ -1317,7 +1338,7 @@ void CKeybindManager::moveFocusTo(std::string args) {
if (*PMONITORFALLBACK)
tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg));
return;
return {};
}
const auto PWINDOWTOCHANGETO = *PFULLCYCLE && PLASTWINDOW->isFullscreen() ?
@ -1327,17 +1348,17 @@ 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);
@ -1346,50 +1367,55 @@ void CKeybindManager::moveFocusTo(std::string args) {
switchToWindow(PWINDOWNEXT);
}
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);
}
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);
}
void CKeybindManager::swapActive(std::string args) {
SDispatchResult CKeybindManager::swapActive(std::string args) {
char arg = args[0];
if (!isDirection(args)) {
// TODO: debug log errors from SDipatchResult somewhere else
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();
}
void CKeybindManager::moveActiveTo(std::string args) {
SDispatchResult CKeybindManager::moveActiveTo(std::string args) {
char arg = args[0];
bool silent = args.ends_with(" silent");
if (silent)
@ -1398,25 +1424,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;
@ -1434,7 +1463,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
@ -1445,17 +1474,17 @@ 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)
@ -1464,11 +1493,11 @@ void CKeybindManager::moveActiveTo(std::string args) {
moveActiveToWorkspace(PWORKSPACE->getConfigName());
}
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);
@ -1479,17 +1508,17 @@ void CKeybindManager::toggleGroup(std::string args) {
PWINDOW->destroyGroup();
}
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
@ -1500,7 +1529,7 @@ void CKeybindManager::changeGroupActive(std::string args) {
PWINDOW->setGroupCurrent(PWINDOW->getGroupTail());
else
PWINDOW->setGroupCurrent(PWINDOW->getGroupWindowByIndex(INDEX - 1));
return;
return {};
}
if (args != "b" && args != "prev") {
@ -1510,37 +1539,37 @@ void CKeybindManager::changeGroupActive(std::string args) {
}
}
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");
}
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");
}
void CKeybindManager::alterSplitRatio(std::string args) {
SDispatchResult CKeybindManager::alterSplitRatio(std::string args) {
std::optional<float> splitResult;
bool exact = false;
@ -1551,40 +1580,43 @@ void CKeybindManager::alterSplitRatio(std::string args) {
splitResult = getPlusMinusKeywordResult(args, 0);
if (!splitResult.has_value()) {
// TODO: debug log errors from SDipatchResult somewhere else
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);
}
void CKeybindManager::focusMonitor(std::string arg) {
SDispatchResult CKeybindManager::focusMonitor(std::string arg) {
const auto PMONITOR = g_pCompositor->getMonitorFromString(arg);
tryMoveFocusToMonitor(PMONITOR);
}
void CKeybindManager::moveCursorToCorner(std::string arg) {
SDispatchResult CKeybindManager::moveCursorToCorner(std::string arg) {
if (!isNumber(arg)) {
// TODO: debug log errors from SDipatchResult somewhere else
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) {
// TODO: debug log errors from SDipatchResult somewhere else
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:
@ -1607,26 +1639,29 @@ void CKeybindManager::moveCursorToCorner(std::string arg) {
}
}
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) {
// TODO: debug log errors from SDipatchResult somewhere else
Debug::log(ERR, "moveCursor, takes 2 arguments.");
return;
return {.success = false, .error = "moveCursor, takes 2 arguments"};
}
x_str = args.substr(0, i);
y_str = args.substr(i + 1);
if (!isNumber(x_str)) {
// TODO: debug log errors from SDipatchResult somewhere else
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)) {
// TODO: debug log errors from SDipatchResult somewhere else
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);
@ -1635,13 +1670,13 @@ void CKeybindManager::moveCursor(std::string args) {
g_pCompositor->warpCursorTo({x, y}, true);
}
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;
@ -1683,15 +1718,16 @@ void CKeybindManager::workspaceOpt(std::string args) {
}
}
} else {
// TODO: debug log errors from SDipatchResult somewhere 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);
}
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) {
@ -1701,7 +1737,11 @@ 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) {
// TODO: debug log errors from SDipatchResult somewhere else
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())};
}
}
void CKeybindManager::exitHyprland(std::string argz) {
@ -2400,38 +2440,37 @@ void CKeybindManager::pinActive(std::string args) {
EMIT_HOOK_EVENT("pin", PWINDOW);
}
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);
@ -2444,7 +2483,7 @@ 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;

View File

@ -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 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 SDispatchResult 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);
friend class CCompositor;
friend class CInputManager;