diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 8feff81c..e679d6da 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -214,6 +214,41 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { return true; } +void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) { + const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; + + if (PWINDOWTOCHANGETO == PLASTWINDOW || !PWINDOWTOCHANGETO) + return; + + if (PLASTWINDOW && PLASTWINDOW->m_iWorkspaceID == PWINDOWTOCHANGETO->m_iWorkspaceID && PLASTWINDOW->m_bIsFullscreen) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PLASTWINDOW->m_iWorkspaceID); + const auto FSMODE = PWORKSPACE->m_efFullscreenMode; + + if (!PWINDOWTOCHANGETO->m_bPinned) + g_pCompositor->setWindowFullscreen(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); + + g_pInputManager->m_pForcedFocus = PWINDOWTOCHANGETO; + g_pInputManager->simulateMouseMovement(); + g_pInputManager->m_pForcedFocus = nullptr; + + if (PLASTWINDOW && PLASTWINDOW->m_iMonitorID != PWINDOWTOCHANGETO->m_iMonitorID) { + // event + const auto PNEWMON = g_pCompositor->getMonitorFromID(PWINDOWTOCHANGETO->m_iMonitorID); + + g_pCompositor->setActiveMonitor(PNEWMON); + } + } +}; + bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) { if (!g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) { m_dPressedKeycodes.clear(); @@ -989,35 +1024,6 @@ void CKeybindManager::moveFocusTo(std::string args) { // remove constraints g_pInputManager->unconstrainMouse(); - auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) { - if (PLASTWINDOW->m_iWorkspaceID == PWINDOWTOCHANGETO->m_iWorkspaceID && PLASTWINDOW->m_bIsFullscreen) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PLASTWINDOW->m_iWorkspaceID); - const auto FSMODE = PWORKSPACE->m_efFullscreenMode; - - if (!PWINDOWTOCHANGETO->m_bPinned) - g_pCompositor->setWindowFullscreen(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); - g_pInputManager->m_pForcedFocus = PWINDOWTOCHANGETO; - g_pInputManager->simulateMouseMovement(); - g_pInputManager->m_pForcedFocus = nullptr; - - if (PLASTWINDOW->m_iMonitorID != PWINDOWTOCHANGETO->m_iMonitorID) { - // event - const auto PNEWMON = g_pCompositor->getMonitorFromID(PWINDOWTOCHANGETO->m_iMonitorID); - - g_pCompositor->setActiveMonitor(PNEWMON); - } - } - }; - const auto PWINDOWTOCHANGETO = PLASTWINDOW->m_bIsFullscreen ? (arg == 'd' || arg == 'b' || arg == 'r' ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true) : g_pCompositor->getPrevWindowOnWorkspace(PLASTWINDOW, true)) : g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); @@ -1055,28 +1061,6 @@ void CKeybindManager::focusUrgentOrLast(std::string args) { // 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(PWINDOWURGENT ? PWINDOWURGENT : PWINDOWPREV); } @@ -1090,28 +1074,6 @@ void CKeybindManager::focusCurrentOrLast(std::string args) { // 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); } @@ -1614,27 +1576,6 @@ void CKeybindManager::resizeWindow(std::string args) { } void CKeybindManager::circleNext(std::string arg) { - 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); - } - }; if (!g_pCompositor->m_pLastWindow) { // if we have a clear focus, find the first window and get the next focusable. diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index e7c78a2c..5151710e 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -91,6 +91,7 @@ class CKeybindManager { bool ensureMouseBindState(); static bool tryMoveFocusToMonitor(CMonitor* monitor); + static void switchToWindow(CWindow* PWINDOWTOCHANGETO); // -------------- Dispatchers -------------- // static void killActive(std::string);