mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-22 19:29:49 +01:00
better keyboard window switching
This commit is contained in:
parent
a558bcdfbf
commit
158af1eb09
3 changed files with 45 additions and 5 deletions
|
@ -649,4 +649,27 @@ void CCompositor::deactivateAllWLRWorkspaces() {
|
|||
if (w.m_pWlrHandle)
|
||||
wlr_ext_workspace_handle_v1_set_active(w.m_pWlrHandle, false);
|
||||
}
|
||||
}
|
||||
|
||||
CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) {
|
||||
bool gotToWindow = false;
|
||||
for (auto& w : m_lWindows) {
|
||||
if (&w != pWindow && !gotToWindow)
|
||||
continue;
|
||||
|
||||
if (&w == pWindow) {
|
||||
gotToWindow = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (w.m_iWorkspaceID == pWindow->m_iWorkspaceID && windowValidMapped(&w))
|
||||
return &w;
|
||||
}
|
||||
|
||||
for (auto& w : m_lWindows) {
|
||||
if (&w != pWindow && w.m_iWorkspaceID == pWindow->m_iWorkspaceID && windowValidMapped(&w))
|
||||
return &w;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
|
@ -103,6 +103,7 @@ public:
|
|||
void cleanupWindows();
|
||||
CWindow* getWindowInDirection(CWindow*, char);
|
||||
void deactivateAllWLRWorkspaces();
|
||||
CWindow* getNextWindowOnWorkspace(CWindow*);
|
||||
|
||||
private:
|
||||
void initAllSignals();
|
||||
|
|
|
@ -281,16 +281,32 @@ void CKeybindManager::moveFocusTo(std::string args) {
|
|||
|
||||
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
||||
|
||||
if (!g_pCompositor->windowValidMapped(PLASTWINDOW))
|
||||
auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) {
|
||||
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
||||
Vector2D middle = PWINDOWTOCHANGETO->m_vEffectivePosition + PWINDOWTOCHANGETO->m_vEffectiveSize / 2.f;
|
||||
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y);
|
||||
};
|
||||
|
||||
if (!g_pCompositor->windowValidMapped(PLASTWINDOW)) {
|
||||
const auto PWINDOWTOCHANGETO = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace);
|
||||
if (!PWINDOWTOCHANGETO)
|
||||
return;
|
||||
|
||||
switchToWindow(PWINDOWTOCHANGETO);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
||||
|
||||
if (PWINDOWTOCHANGETO) {
|
||||
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
||||
Vector2D middle = PWINDOWTOCHANGETO->m_vPosition + PWINDOWTOCHANGETO->m_vSize / 2.f;
|
||||
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y);
|
||||
}
|
||||
switchToWindow(PWINDOWTOCHANGETO);
|
||||
} else {
|
||||
const auto PWINDOWNEXT = g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW);
|
||||
if (PWINDOWNEXT) {
|
||||
switchToWindow(PWINDOWNEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CKeybindManager::toggleGroup(std::string args) {
|
||||
|
|
Loading…
Reference in a new issue