layout: properly assign workspace and monitor when moving a child to the parent (#10338)

This commit is contained in:
Vaxry 2025-05-08 21:00:28 +02:00 committed by GitHub
parent 53bfb92d65
commit 04c98abd1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 6 deletions

View file

@ -1822,3 +1822,24 @@ std::optional<std::string> CWindow::xdgDescription() {
return m_xdgSurface->m_toplevel->m_toplevelDescription; return m_xdgSurface->m_toplevel->m_toplevelDescription;
} }
PHLWINDOW CWindow::parent() {
if (m_isX11) {
auto t = x11TransientFor();
// don't return a parent that's not mapped
if (!validMapped(t))
return nullptr;
return t;
}
if (!m_xdgSurface || !m_xdgSurface->m_toplevel || !m_xdgSurface->m_toplevel->m_parent)
return nullptr;
// don't return a parent that's not mapped
if (!m_xdgSurface->m_toplevel->m_parent->m_window || !validMapped(m_xdgSurface->m_toplevel->m_parent->m_window))
return nullptr;
return m_xdgSurface->m_toplevel->m_parent->m_window.lock();
}

View file

@ -409,6 +409,7 @@ class CWindow {
bool isNotResponding(); bool isNotResponding();
std::optional<std::string> xdgTag(); std::optional<std::string> xdgTag();
std::optional<std::string> xdgDescription(); std::optional<std::string> xdgDescription();
PHLWINDOW parent();
CBox getWindowMainSurfaceBox() const { CBox getWindowMainSurfaceBox() const {
return {m_realPosition->value().x, m_realPosition->value().y, m_realSize->value().x, m_realSize->value().y}; return {m_realPosition->value().x, m_realPosition->value().y, m_realSize->value().x, m_realSize->value().y};

View file

@ -159,12 +159,19 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) {
// TODO: detect a popup in a more consistent way. // TODO: detect a popup in a more consistent way.
if ((desiredGeometry.x == 0 && desiredGeometry.y == 0) || !visible || !pWindow->m_isX11) { if ((desiredGeometry.x == 0 && desiredGeometry.y == 0) || !visible || !pWindow->m_isX11) {
// if the pos isn't set, fall back to the center placement if it's not a child, otherwise middle of parent if available // if the pos isn't set, fall back to the center placement if it's not a child
if (!pWindow->m_isX11 && pWindow->m_xdgSurface->m_toplevel->m_parent && validMapped(pWindow->m_xdgSurface->m_toplevel->m_parent->m_window)) auto pos = PMONITOR->m_position + PMONITOR->m_size / 2.F - desiredGeometry.size() / 2.F;
*pWindow->m_realPosition = pWindow->m_xdgSurface->m_toplevel->m_parent->m_window->m_realPosition->goal() +
pWindow->m_xdgSurface->m_toplevel->m_parent->m_window->m_realSize->goal() / 2.F - desiredGeometry.size() / 2.F; // otherwise middle of parent if available
else if (!pWindow->m_isX11) {
*pWindow->m_realPosition = PMONITOR->m_position + PMONITOR->m_size / 2.F - desiredGeometry.size() / 2.F; if (const auto PARENT = pWindow->parent(); PARENT) {
*pWindow->m_realPosition = PARENT->m_realPosition->goal() + PARENT->m_realSize->goal() / 2.F - desiredGeometry.size() / 2.F;
pWindow->m_workspace = PARENT->m_workspace;
pWindow->m_monitor = PARENT->m_monitor;
}
}
*pWindow->m_realPosition = pos;
} else { } else {
// if it is, we respect where it wants to put itself, but apply monitor offset if outside // if it is, we respect where it wants to put itself, but apply monitor offset if outside
// most of these are popups // most of these are popups