From 445acec2a29adbb30196d8b92f86270a038b7ee5 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 25 Jan 2025 20:36:44 +0000 Subject: core: move sendWindowSize off of xwaylandmgr additionally fixes that one weird x11 issue with floating windows being mis-sized on open --- src/desktop/Window.cpp | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'src/desktop/Window.cpp') diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 5f84aa3a..96b87205 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -453,7 +453,7 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) { } // update xwayland coords - g_pXWaylandManager->setWindowSize(m_pSelf.lock(), m_vRealSize->goal()); + sendWindowSize(m_vRealSize->goal()); if (OLDWORKSPACE && g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE->m_iID) && OLDWORKSPACE->getWindows() == 0 && *PCLOSEONLASTSPECIAL) { if (const auto PMONITOR = OLDWORKSPACE->m_pMonitor.lock(); PMONITOR) @@ -1309,7 +1309,7 @@ void CWindow::clampWindowSize(const std::optional minSize, const std:: *m_vRealPosition = m_vRealPosition->goal() + DELTA / 2.0; *m_vRealSize = NEWSIZE; - g_pXWaylandManager->setWindowSize(m_pSelf.lock(), NEWSIZE); + sendWindowSize(NEWSIZE); } bool CWindow::isFullscreen() { @@ -1533,7 +1533,7 @@ void CWindow::onX11Configure(CBox box) { g_pHyprRenderer->damageWindow(m_pSelf.lock()); if (!m_bIsFloating || isFullscreen() || g_pInputManager->currentlyDraggedWindow == m_pSelf) { - g_pXWaylandManager->setWindowSize(m_pSelf.lock(), m_vRealSize->goal(), true); + sendWindowSize(m_vRealSize->goal(), true); g_pInputManager->refocus(); g_pHyprRenderer->damageWindow(m_pSelf.lock()); return; @@ -1560,7 +1560,7 @@ void CWindow::onX11Configure(CBox box) { m_vPosition = m_vRealPosition->goal(); m_vSize = m_vRealSize->goal(); - g_pXWaylandManager->setWindowSize(m_pSelf.lock(), box.size(), true); + sendWindowSize(box.size(), true); m_vPendingReportedSize = box.size(); m_vReportedSize = box.size(); @@ -1690,3 +1690,40 @@ Vector2D CWindow::requestedMaxSize() { return maxSize; } + +void CWindow::sendWindowSize(Vector2D size, bool force, std::optional overridePos) { + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); + + const auto PMONITOR = m_pMonitor.lock(); + + size = size.clamp(Vector2D{0, 0}, Vector2D{std::numeric_limits::infinity(), std::numeric_limits::infinity()}); + + // calculate pos + // TODO: this should be decoupled from setWindowSize IMO + Vector2D windowPos = overridePos.value_or(m_vRealPosition->goal()); + + if (m_bIsX11 && PMONITOR) { + windowPos -= PMONITOR->vecPosition; // normalize to monitor + if (*PXWLFORCESCALEZERO) + windowPos *= PMONITOR->scale; // scale if applicable + windowPos += PMONITOR->vecXWaylandPosition; // move to correct position for xwayland + } + + if (!force && m_vPendingReportedSize == size && (windowPos == m_vReportedPosition || !m_bIsX11)) + return; + + m_vReportedPosition = windowPos; + m_vPendingReportedSize = size; + + m_fX11SurfaceScaledBy = 1.0f; + + if (*PXWLFORCESCALEZERO && m_bIsX11 && PMONITOR) { + size *= PMONITOR->scale; + m_fX11SurfaceScaledBy = PMONITOR->scale; + } + + if (m_bIsX11 && m_pXWaylandSurface) + m_pXWaylandSurface->configure({windowPos, size}); + else if (m_pXDGSurface && m_pXDGSurface->toplevel) + m_vPendingSizeAcks.emplace_back(m_pXDGSurface->toplevel->setSize(size), size.floor()); +} -- cgit v1.2.3