windows/focus: add fallbacks when focussing workspaces (#14270)

This commit is contained in:
fazzi 2026-05-04 17:00:56 +01:00 committed by GitHub
parent 2824ffdda0
commit eff3bfe261
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 29 additions and 12 deletions

View file

@ -94,7 +94,7 @@ static bool tryMoveFocusToMonitor(PHLMONITOR monitor) {
const auto PNEWMAINWORKSPACE = monitor->m_activeWorkspace;
const auto PNEWWORKSPACE = monitor->m_activeSpecialWorkspace ? monitor->m_activeSpecialWorkspace : PNEWMAINWORKSPACE;
const auto PNEWWINDOW = PNEWWORKSPACE->getLastFocusedWindow();
auto PNEWWINDOW = PNEWWORKSPACE->getFocusCandidate();
if (PNEWWINDOW) {
updateRelativeCursorCoords();
@ -931,11 +931,13 @@ ActionResult Actions::changeWorkspace(PHLWORKSPACE ws) {
PMONITORWORKSPACEOWNER->changeWorkspace(ws, false, true);
if (PMONITOR != PMONITORWORKSPACEOWNER) {
Vector2D middle = PMONITORWORKSPACEOWNER->middle();
if (const auto PLAST = ws->getLastFocusedWindow(); PLAST) {
Desktop::focusState()->fullWindowFocus(PLAST, Desktop::FOCUS_REASON_KEYBIND);
Vector2D middle = PMONITORWORKSPACEOWNER->middle();
auto pWindow = ws->getFocusCandidate();
if (pWindow) {
Desktop::focusState()->fullWindowFocus(pWindow, Desktop::FOCUS_REASON_KEYBIND);
if (*PWORKSPACECENTERON == 1)
middle = PLAST->middle();
middle = pWindow->middle();
}
g_pCompositor->warpCursorTo(middle);
}

View file

@ -83,6 +83,18 @@ PHLWINDOW CWorkspace::getLastFocusedWindow() {
return m_lastFocusedWindow.lock();
}
PHLWINDOW CWorkspace::getFocusCandidate() {
auto pWindow = getLastFocusedWindow();
if (!pWindow)
pWindow = getTopLeftWindow();
if (!pWindow)
pWindow = getFirstWindow();
return pWindow;
}
std::string CWorkspace::getConfigName() {
if (m_isSpecialWorkspace) {
return m_name;

View file

@ -61,6 +61,7 @@ class CWorkspace {
bool inert();
MONITORID monitorID();
PHLWINDOW getLastFocusedWindow();
PHLWINDOW getFocusCandidate();
std::string getConfigName();
bool matchesStaticSelector(const std::string& selector);
void markInert();

View file

@ -167,8 +167,12 @@ void CFocusState::rawWindowFocus(PHLWINDOW pWindow, eFocusReason reason, SP<CWLS
return;
}
const auto PLASTWINDOW = m_focusWindow.lock();
m_focusWindow = pWindow;
if (PMONITOR && !pWindow->m_pinned)
rawMonitorFocus(PMONITOR);
const auto PLASTWINDOW = m_focusWindow.lock();
m_focusWindow = pWindow;
pWindow->m_workspace->m_lastFocusedWindow = pWindow;
/* If special fallthrough is enabled, this behavior will be disabled, as I have no better idea of nicely tracking which
window focuses are "via keybinds" and which ones aren't. */

View file

@ -1406,10 +1406,7 @@ void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bo
Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING);
if (!pWindow)
pWindow = pWorkspace->getTopLeftWindow();
if (!pWindow)
pWindow = pWorkspace->getFirstWindow();
pWindow = pWorkspace->getFocusCandidate();
}
Desktop::focusState()->fullWindowFocus(pWindow, Desktop::FOCUS_REASON_KEYBIND);

View file

@ -1694,7 +1694,8 @@ bool CInputManager::refocusLastWindow(PHLMONITOR pMonitor) {
foundSurface = nullptr;
}
if (!foundSurface && Desktop::focusState()->window() && Desktop::focusState()->window()->m_workspace && Desktop::focusState()->window()->m_workspace->isVisibleNotCovered()) {
if (!foundSurface && Desktop::focusState()->window() && Desktop::focusState()->window()->m_monitor == pMonitor && Desktop::focusState()->window()->m_workspace &&
Desktop::focusState()->window()->m_workspace->isVisibleNotCovered()) {
// then the last focused window if we're on the same workspace as it
const auto PLASTWINDOW = Desktop::focusState()->window();
Desktop::focusState()->fullWindowFocus(PLASTWINDOW, Desktop::FOCUS_REASON_FFM);