diff options
author | nub <[email protected]> | 2023-02-14 06:16:58 +0530 |
---|---|---|
committer | GitHub <[email protected]> | 2023-02-14 00:46:58 +0000 |
commit | 98c95aa34d31bcbb792227d00dc37bfd627a564a (patch) | |
tree | 0c2ef81216fb0a08707571fbf98cd94347253d0b | |
parent | 6b7e409f05536e45baa3dabeab0df77d05c9a96f (diff) | |
download | Hyprland-98c95aa34d31bcbb792227d00dc37bfd627a564a.tar.gz Hyprland-98c95aa34d31bcbb792227d00dc37bfd627a564a.zip |
focusCurrentOrLast dispatcher (#1545)
-rw-r--r-- | src/managers/KeybindManager.cpp | 36 | ||||
-rw-r--r-- | src/managers/KeybindManager.hpp | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 58be9ea9..26bc3565 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -58,6 +58,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["mouse"] = mouse; m_mDispatchers["bringactivetotop"] = bringActiveToTop; m_mDispatchers["focusurgentorlast"] = focusUrgentOrLast; + m_mDispatchers["focuscurrentorlast"] = focusCurrentOrLast; m_tScrollTimer.reset(); } @@ -1148,6 +1149,41 @@ void CKeybindManager::focusUrgentOrLast(std::string args) { switchToWindow(PWINDOWURGENT ? PWINDOWURGENT : PWINDOWPREV); } +void CKeybindManager::focusCurrentOrLast(std::string args) { + const auto PWINDOWPREV = g_pCompositor->m_pLastWindow ? (g_pCompositor->m_vWindowFocusHistory.size() < 2 ? nullptr : g_pCompositor->m_vWindowFocusHistory[1]) : + (g_pCompositor->m_vWindowFocusHistory.empty() ? nullptr : g_pCompositor->m_vWindowFocusHistory[0]); + + if (!PWINDOWPREV) + return; + + // remove constraints + g_pInputManager->unconstrainMouse(); + + auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) { + if (PWINDOWTOCHANGETO == g_pCompositor->m_pLastWindow || !PWINDOWTOCHANGETO) + return; + + if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_iWorkspaceID == PWINDOWTOCHANGETO->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsFullscreen) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastWindow->m_iWorkspaceID); + const auto FSMODE = PWORKSPACE->m_efFullscreenMode; + + if (!PWINDOWTOCHANGETO->m_bPinned) + g_pCompositor->setWindowFullscreen(g_pCompositor->m_pLastWindow, false, FULLSCREEN_FULL); + + g_pCompositor->focusWindow(PWINDOWTOCHANGETO); + + if (!PWINDOWTOCHANGETO->m_bPinned) + g_pCompositor->setWindowFullscreen(PWINDOWTOCHANGETO, true, FSMODE); + } else { + g_pCompositor->focusWindow(PWINDOWTOCHANGETO); + Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f; + g_pCompositor->warpCursorTo(middle); + } + }; + + switchToWindow(PWINDOWPREV); +} + void CKeybindManager::moveActiveTo(std::string args) { char arg = args[0]; diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 689426f2..3ed09cb4 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -98,6 +98,7 @@ class CKeybindManager { 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 toggleGroup(std::string); |