summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authormemchr <118117622+memchr@users.noreply.github.com>2023-09-10 11:51:27 +0000
committerGitHub <noreply@github.com>2023-09-10 12:51:27 +0100
commitf7f70c9e72e210dea0326d19aacb018aaba866be (patch)
tree96f440911cbdedc7a02f54973f4b2420d6c2767c /src/managers/KeybindManager.cpp
parentf4e99a36a9768b05c5d828bb630f31d8ae4c8270 (diff)
refactor: replace lambdas with CKeybindManager::switchToWindow (#3229)
moves `switchToWindow` lambdas to a single private method `CKeybindManager::switchToWindow()`. fixes #3227, as a by-product of the mouse motion simulation at the end of `CKeybindManager::switchToWindow()`.
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp129
1 files changed, 35 insertions, 94 deletions
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.