Skip to content

Commit abffe75

Browse files
committed
desktop/window: improve fullscreen handling for grouped windows
fixes #12700
1 parent 60efbf3 commit abffe75

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

src/desktop/state/FocusState.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,8 @@ PHLWINDOW CFocusState::window() {
289289
PHLMONITOR CFocusState::monitor() {
290290
return m_focusMonitor.lock();
291291
}
292+
293+
void CFocusState::resetWindowFocus() {
294+
m_focusWindow.reset();
295+
m_focusSurface.reset();
296+
}

src/desktop/state/FocusState.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace Desktop {
2020
void rawSurfaceFocus(SP<CWLSurfaceResource> s, PHLWINDOW pWindowOwner = nullptr);
2121
void rawMonitorFocus(PHLMONITOR m);
2222

23+
void resetWindowFocus();
24+
2325
SP<CWLSurfaceResource> surface();
2426
PHLWINDOW window();
2527
PHLMONITOR monitor();

src/desktop/view/Window.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,10 @@ void CWindow::mapWindow() {
19301930
static auto PNEWTAKESOVERFS = CConfigValue<Hyprlang::INT>("misc:on_focus_under_fullscreen");
19311931
static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking");
19321932

1933+
const auto LAST_FOCUS_WINDOW = Desktop::focusState()->window();
1934+
const bool IS_LAST_IN_FS = LAST_FOCUS_WINDOW ? LAST_FOCUS_WINDOW->m_fullscreenState.internal != FSMODE_NONE : false;
1935+
const auto LAST_FS_MODE = LAST_FOCUS_WINDOW ? LAST_FOCUS_WINDOW->m_fullscreenState.internal : FSMODE_NONE;
1936+
19331937
auto PMONITOR = Desktop::focusState()->monitor();
19341938
if (!Desktop::focusState()->monitor()) {
19351939
Desktop::focusState()->rawMonitorFocus(g_pCompositor->getMonitorFromVector({}));
@@ -2305,7 +2309,16 @@ void CWindow::mapWindow() {
23052309

23062310
if (!m_ruleApplicator->noFocus().valueOrDefault() && !m_noInitialFocus && (!isX11OverrideRedirect() || (m_isX11 && m_xwaylandSurface->wantsFocus())) && !workspaceSilent &&
23072311
(!PFORCEFOCUS || PFORCEFOCUS == m_self.lock()) && !g_pInputManager->isConstrained()) {
2308-
Desktop::focusState()->fullWindowFocus(m_self.lock());
2312+
2313+
// this window should gain focus: if it's grouped, preserve fullscreen state.
2314+
const bool SAME_GROUP = hasInGroup(LAST_FOCUS_WINDOW);
2315+
2316+
if (IS_LAST_IN_FS && SAME_GROUP) {
2317+
Desktop::focusState()->rawWindowFocus(m_self.lock());
2318+
g_pCompositor->setWindowFullscreenInternal(m_self.lock(), LAST_FS_MODE);
2319+
} else
2320+
Desktop::focusState()->fullWindowFocus(m_self.lock());
2321+
23092322
m_activeInactiveAlpha->setValueAndWarp(*PACTIVEALPHA);
23102323
m_dimPercent->setValueAndWarp(m_ruleApplicator->noDim().valueOrDefault() ? 0.f : *PDIMSTRENGTH);
23112324
} else {
@@ -2451,12 +2464,12 @@ void CWindow::unmapWindow() {
24512464
m_swallowed.reset();
24522465
}
24532466

2454-
bool wasLastWindow = false;
2467+
bool wasLastWindow = false;
2468+
PHLWINDOW nextInGroup = m_groupData.pNextWindow ? m_groupData.pNextWindow.lock() : nullptr;
24552469

24562470
if (m_self.lock() == Desktop::focusState()->window()) {
24572471
wasLastWindow = true;
2458-
Desktop::focusState()->window().reset();
2459-
Desktop::focusState()->surface().reset();
2472+
Desktop::focusState()->resetWindowFocus();
24602473

24612474
g_pInputManager->releaseAllMouseButtons();
24622475
}
@@ -2479,23 +2492,30 @@ void CWindow::unmapWindow() {
24792492

24802493
// refocus on a new window if needed
24812494
if (wasLastWindow) {
2482-
static auto FOCUSONCLOSE = CConfigValue<Hyprlang::INT>("input:focus_on_close");
2483-
PHLWINDOW PWINDOWCANDIDATE = nullptr;
2484-
if (*FOCUSONCLOSE)
2485-
PWINDOWCANDIDATE = (g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(),
2486-
Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING));
2487-
else
2488-
PWINDOWCANDIDATE = g_pLayoutManager->getCurrentLayout()->getNextWindowCandidate(m_self.lock());
2495+
static auto FOCUSONCLOSE = CConfigValue<Hyprlang::INT>("input:focus_on_close");
2496+
PHLWINDOW candidate = nextInGroup;
24892497

2490-
Log::logger->log(Log::DEBUG, "On closed window, new focused candidate is {}", PWINDOWCANDIDATE);
2498+
if (!candidate) {
2499+
if (*FOCUSONCLOSE)
2500+
candidate = (g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(),
2501+
Desktop::View::RESERVED_EXTENTS | Desktop::View::INPUT_EXTENTS | Desktop::View::ALLOW_FLOATING));
2502+
else
2503+
candidate = g_pLayoutManager->getCurrentLayout()->getNextWindowCandidate(m_self.lock());
2504+
}
2505+
2506+
Log::logger->log(Log::DEBUG, "On closed window, new focused candidate is {}", candidate);
2507+
2508+
if (candidate != Desktop::focusState()->window() && candidate) {
2509+
if (candidate == nextInGroup)
2510+
Desktop::focusState()->rawWindowFocus(candidate);
2511+
else
2512+
Desktop::focusState()->fullWindowFocus(candidate);
24912513

2492-
if (PWINDOWCANDIDATE != Desktop::focusState()->window() && PWINDOWCANDIDATE) {
2493-
Desktop::focusState()->fullWindowFocus(PWINDOWCANDIDATE);
2494-
if (*PEXITRETAINSFS && CURRENTWINDOWFSSTATE)
2495-
g_pCompositor->setWindowFullscreenInternal(PWINDOWCANDIDATE, CURRENTFSMODE);
2514+
if ((*PEXITRETAINSFS || candidate == nextInGroup) && CURRENTWINDOWFSSTATE)
2515+
g_pCompositor->setWindowFullscreenInternal(candidate, CURRENTFSMODE);
24962516
}
24972517

2498-
if (!PWINDOWCANDIDATE && m_workspace && m_workspace->getWindows() == 0)
2518+
if (!candidate && m_workspace && m_workspace->getWindows() == 0)
24992519
g_pInputManager->refocus();
25002520

25012521
g_pInputManager->sendMotionEventsToFocused();

0 commit comments

Comments
 (0)