Skip to content

core: recheck floating windows after monitor layout changes #10031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2901,6 +2901,38 @@ void CCompositor::arrangeMonitors() {
PROTO::xdgOutput->updateAllOutputs();
}

void CCompositor::recheckFloatingWindowsOnScreen() {
for (auto& w : m_vWindows) {
if (!w->m_bIsMapped || !w->m_bIsFloating)
continue;

const CBox WBOX = w->getWindowMainSurfaceBox();

const bool IN = std::ranges::any_of(m_vMonitors, [w, WBOX](const auto& m) {
if (!m->m_bEnabled)
return false;
CBox MONBOX = m->logicalBox();
return !MONBOX.intersection(WBOX).empty();
});

if (IN)
continue;

auto monitor = w->m_pMonitor;

if (!monitor || !monitor->m_bEnabled)
monitor = getMonitorFromVector(WBOX.middle());

if (!monitor)
continue; // ?!?!?!

const auto NEW_POS = monitor->middle() - WBOX.size() / 2.F;

*w->m_vRealPosition = NEW_POS;
w->m_vPosition = NEW_POS;
}
}

void CCompositor::enterUnsafeState() {
if (m_bUnsafeState)
return;
Expand Down
1 change: 1 addition & 0 deletions src/Compositor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class CCompositor {
void moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWorkspace);
PHLWINDOW getForceFocus();
void arrangeMonitors();
void recheckFloatingWindowsOnScreen();
void enterUnsafeState();
void leaveUnsafeState();
void setPreferredScaleForSurface(SP<CWLSurfaceResource> pSurface, double scale);
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {

events.modeChanged.emit();

g_pEventLoopManager->doLater([]() { g_pCompositor->recheckFloatingWindowsOnScreen(); });

return true;
}

Expand Down
Loading