diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 1a21b499..e97e2456 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -32,8 +32,10 @@ void Events::listener_mapWindow(wl_listener* listener, void* data) { wl_signal_add(&PWINDOWSURFACE->events.new_subsurface, &PWINDOW->listen_newSubsurfaceWindow); - if (g_pXWaylandManager->shouldBeFloated(PWINDOW)) + if (g_pXWaylandManager->shouldBeFloated(PWINDOW)) { g_pLayoutManager->getCurrentLayout()->onWindowCreatedFloating(PWINDOW); + PWINDOW->m_bIsFloating = true; + } else g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 57f2703f..e496fbd9 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -291,9 +291,30 @@ void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) { } void CHyprDwindleLayout::onWindowCreatedFloating(CWindow* pWindow) { - const auto PWINDOWSURFACE = g_pXWaylandManager->getWindowSurface(pWindow); + wlr_box desiredGeometry = {0}; + g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry); const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - pWindow->m_vRealSize = Vector2D(PWINDOWSURFACE->current.width, PWINDOWSURFACE->current.height); - pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.x) / 2.f, PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.y) / 2.f); + if (desiredGeometry.width <= 0 || desiredGeometry.height <= 0) { + const auto PWINDOWSURFACE = g_pXWaylandManager->getWindowSurface(pWindow); + pWindow->m_vRealSize = Vector2D(PWINDOWSURFACE->current.width, PWINDOWSURFACE->current.height); + pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.x) / 2.f, PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.y) / 2.f); + + } else { + // we respect the size. + pWindow->m_vRealSize = Vector2D(desiredGeometry.width, desiredGeometry.height); + + // check if it's on the correct monitor! + Vector2D middlePoint = Vector2D(desiredGeometry.x, desiredGeometry.y) + Vector2D(desiredGeometry.width, desiredGeometry.height) / 2.f; + + if (g_pCompositor->getMonitorFromVector(middlePoint)->ID != pWindow->m_iMonitorID) { + // if it's not, fall back to the center placement + pWindow->m_vRealPosition = PMONITOR->vecPosition + Vector2D((PMONITOR->vecSize.x - desiredGeometry.width) / 2.f, (PMONITOR->vecSize.y - desiredGeometry.height) / 2.f); + } else { + // if it is, we respect where it wants to put itself. + // most of these are popups + // TODO: detect a popup in a more consistent way. + pWindow->m_vRealPosition = Vector2D(desiredGeometry.x, desiredGeometry.y); + } + } } \ No newline at end of file diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 8369fe4f..46e7a84b 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -101,6 +101,11 @@ bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow) { const auto SIZEHINTS = pWindow->m_uSurface.xwayland->size_hints; if (SIZEHINTS && SIZEHINTS->min_width > 0 && SIZEHINTS->min_height > 0 && (SIZEHINTS->max_width == SIZEHINTS->min_width || SIZEHINTS->max_height == SIZEHINTS->min_height)) return true; + } else { + const auto PSTATE = &pWindow->m_uSurface.xdg->toplevel->current; + + if ((PSTATE->min_width != 0 && PSTATE->min_height != 0 && (PSTATE->min_width == PSTATE->max_width || PSTATE->min_height == PSTATE->max_height)) || pWindow->m_uSurface.xdg->toplevel->parent) + return true; } return false;