mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-29 22:05:58 +01:00
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()`.
This commit is contained in:
parent
f4e99a36a9
commit
f7f70c9e72
2 changed files with 36 additions and 94 deletions
|
@ -214,6 +214,41 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) {
|
||||||
return true;
|
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) {
|
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
|
||||||
if (!g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) {
|
if (!g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) {
|
||||||
m_dPressedKeycodes.clear();
|
m_dPressedKeycodes.clear();
|
||||||
|
@ -989,35 +1024,6 @@ void CKeybindManager::moveFocusTo(std::string args) {
|
||||||
// remove constraints
|
// remove constraints
|
||||||
g_pInputManager->unconstrainMouse();
|
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 ?
|
const auto PWINDOWTOCHANGETO = PLASTWINDOW->m_bIsFullscreen ?
|
||||||
(arg == 'd' || arg == 'b' || arg == 'r' ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true) : g_pCompositor->getPrevWindowOnWorkspace(PLASTWINDOW, true)) :
|
(arg == 'd' || arg == 'b' || arg == 'r' ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true) : g_pCompositor->getPrevWindowOnWorkspace(PLASTWINDOW, true)) :
|
||||||
g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
||||||
|
@ -1055,28 +1061,6 @@ void CKeybindManager::focusUrgentOrLast(std::string args) {
|
||||||
// remove constraints
|
// remove constraints
|
||||||
g_pInputManager->unconstrainMouse();
|
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);
|
switchToWindow(PWINDOWURGENT ? PWINDOWURGENT : PWINDOWPREV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1090,28 +1074,6 @@ void CKeybindManager::focusCurrentOrLast(std::string args) {
|
||||||
// remove constraints
|
// remove constraints
|
||||||
g_pInputManager->unconstrainMouse();
|
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);
|
switchToWindow(PWINDOWPREV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1614,27 +1576,6 @@ void CKeybindManager::resizeWindow(std::string args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeybindManager::circleNext(std::string arg) {
|
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 (!g_pCompositor->m_pLastWindow) {
|
||||||
// if we have a clear focus, find the first window and get the next focusable.
|
// if we have a clear focus, find the first window and get the next focusable.
|
||||||
|
|
|
@ -91,6 +91,7 @@ class CKeybindManager {
|
||||||
bool ensureMouseBindState();
|
bool ensureMouseBindState();
|
||||||
|
|
||||||
static bool tryMoveFocusToMonitor(CMonitor* monitor);
|
static bool tryMoveFocusToMonitor(CMonitor* monitor);
|
||||||
|
static void switchToWindow(CWindow* PWINDOWTOCHANGETO);
|
||||||
|
|
||||||
// -------------- Dispatchers -------------- //
|
// -------------- Dispatchers -------------- //
|
||||||
static void killActive(std::string);
|
static void killActive(std::string);
|
||||||
|
|
Loading…
Reference in a new issue