Skip to content

Commit

Permalink
core: move sendWindowSize off of xwaylandmgr
Browse files Browse the repository at this point in the history
additionally fixes that one weird x11 issue with floating windows being mis-sized on open
  • Loading branch information
vaxerski committed Jan 25, 2025
1 parent 45c3787 commit 445acec
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, SFullscreenS

updateFullscreenFadeOnWorkspace(PWORKSPACE);

g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize->goal(), true);
PWINDOW->sendWindowSize(PWINDOW->m_vRealSize->goal(), true);

PWORKSPACE->forceReportSizesToWindows();

Expand Down
45 changes: 41 additions & 4 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1309,7 +1309,7 @@ void CWindow::clampWindowSize(const std::optional<Vector2D> 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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -1690,3 +1690,40 @@ Vector2D CWindow::requestedMaxSize() {

return maxSize;
}

void CWindow::sendWindowSize(Vector2D size, bool force, std::optional<Vector2D> overridePos) {
static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");

const auto PMONITOR = m_pMonitor.lock();

size = size.clamp(Vector2D{0, 0}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::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());
}
2 changes: 2 additions & 0 deletions src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vector>
#include <string>
#include <optional>

#include "../config/ConfigDataValues.hpp"
#include "../helpers/AnimatedVariable.hpp"
Expand Down Expand Up @@ -468,6 +469,7 @@ class CWindow {
bool isModal();
Vector2D requestedMinSize();
Vector2D requestedMaxSize();
void sendWindowSize(Vector2D size, bool force = false, std::optional<Vector2D> overridePos = std::nullopt);

CBox getWindowMainSurfaceBox() const {
return {m_vRealPosition->value().x, m_vRealPosition->value().y, m_vRealSize->value().x, m_vRealSize->value().y};
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void CWorkspace::forceReportSizesToWindows() {
if (w->m_pWorkspace != m_pSelf || !w->m_bIsMapped || w->isHidden())
continue;

g_pXWaylandManager->setWindowSize(w, w->m_vRealSize->goal(), true);
w->sendWindowSize(w->m_vRealSize->goal(), true);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,12 @@ void Events::listener_mapWindow(void* owner, void* data) {
if (PMONITOR && PWINDOW->isX11OverrideRedirect())
PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale;

if (!PWINDOW->isX11OverrideRedirect() && PWINDOW->m_bIsX11 && PWINDOW->m_bIsFloating)
g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize->goal(), true);
// Fix some X11 popups being invisible / having incorrect size on open.
// What the ACTUAL FUCK is going on?????? I HATE X11
if (!PWINDOW->isX11OverrideRedirect() && PWINDOW->m_bIsX11 && PWINDOW->m_bIsFloating) {
PWINDOW->sendWindowSize(PWINDOW->m_vRealSize->goal(), true, PWINDOW->m_vRealPosition->goal() - Vector2D{1, 1});
PWINDOW->sendWindowSize(PWINDOW->m_vRealSize->goal(), true);
}
}

void Events::listener_unmapWindow(void* owner, void* data) {
Expand Down Expand Up @@ -949,7 +953,7 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) {
PWINDOW->setHidden(true);

if (PWINDOW->isFullscreen() || !PWINDOW->m_bIsFloating) {
g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize->goal(), true);
PWINDOW->sendWindowSize(PWINDOW->m_vRealSize->goal(), true);
g_pHyprRenderer->damageWindow(PWINDOW);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/layout/DwindleLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
*PWINDOW->m_vRealPosition = wb.pos();
*PWINDOW->m_vRealSize = wb.size();

g_pXWaylandManager->setWindowSize(PWINDOW, wb.size());
PWINDOW->sendWindowSize(wb.size());
} else {
CBox wb = {calcPos, calcSize};
wb.round(); // avoid rounding mess

*PWINDOW->m_vRealSize = wb.size();
*PWINDOW->m_vRealPosition = wb.pos();

g_pXWaylandManager->setWindowSize(PWINDOW, wb.size());
PWINDOW->sendWindowSize(wb.size());
}

if (force) {
Expand Down
10 changes: 5 additions & 5 deletions src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) {
}

if (!pWindow->isX11OverrideRedirect()) {
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize->goal());
pWindow->sendWindowSize(pWindow->m_vRealSize->goal());

g_pCompositor->changeWindowZOrder(pWindow, true);
} else {
Expand Down Expand Up @@ -365,7 +365,7 @@ void IHyprLayout::onEndDragWindow() {
DRAGGINGWINDOW->m_bDraggingTiled = false;

if (pWindow->m_bIsFloating)
g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, pWindow->m_vRealSize->goal()); // match the size of the window
DRAGGINGWINDOW->sendWindowSize(DRAGGINGWINDOW->m_vRealSize->goal()); // match the size of the window

static auto USECURRPOS = CConfigValue<Hyprlang::INT>("group:insert_after_current");
(*USECURRPOS ? pWindow : pWindow->getGroupTail())->insertWindowToGroup(DRAGGINGWINDOW);
Expand Down Expand Up @@ -611,7 +611,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
else
DRAGGINGWINDOW->m_vRealPosition->setValueAndWarp(wb.pos());

g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize->goal());
DRAGGINGWINDOW->sendWindowSize(DRAGGINGWINDOW->m_vRealSize->goal());
} else if (g_pInputManager->dragMode == MBIND_RESIZE || g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) {
if (DRAGGINGWINDOW->m_bIsFloating) {

Expand Down Expand Up @@ -683,7 +683,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
DRAGGINGWINDOW->m_vRealPosition->setValueAndWarp(wb.pos());
}

g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize->goal());
DRAGGINGWINDOW->sendWindowSize(DRAGGINGWINDOW->m_vRealSize->goal());
} else {
resizeActiveWindow(TICKDELTA, m_eGrabbedCorner, DRAGGINGWINDOW);
}
Expand Down Expand Up @@ -789,7 +789,7 @@ void IHyprLayout::changeWindowFloatingMode(PHLWINDOW pWindow) {

g_pCompositor->updateWindowAnimatedDecorationValues(pWindow);
pWindow->updateToplevel();
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize->goal());
pWindow->sendWindowSize(pWindow->m_vRealSize->goal());
g_pHyprRenderer->damageWindow(pWindow);
}

Expand Down
4 changes: 2 additions & 2 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,15 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) {
*PWINDOW->m_vRealPosition = wb.pos();
*PWINDOW->m_vRealSize = wb.size();

g_pXWaylandManager->setWindowSize(PWINDOW, wb.size());
PWINDOW->sendWindowSize(wb.size());
} else {
CBox wb = {calcPos, calcSize};
wb.round(); // avoid rounding mess

*PWINDOW->m_vRealPosition = wb.pos();
*PWINDOW->m_vRealSize = wb.size();

g_pXWaylandManager->setWindowSize(PWINDOW, wb.size());
PWINDOW->sendWindowSize(wb.size());
}

if (m_bForceWarps && !*PANIMATE) {
Expand Down
2 changes: 1 addition & 1 deletion src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ SDispatchResult CKeybindManager::workspaceOpt(std::string args) {
if (PWORKSPACE->m_bDefaultFloating) {
w->m_vRealPosition->setValueAndWarp(SAVEDPOS);
w->m_vRealSize->setValueAndWarp(SAVEDSIZE);
g_pXWaylandManager->setWindowSize(w, SAVEDSIZE);
w->sendWindowSize(SAVEDSIZE);
*w->m_vRealSize = w->m_vRealSize->value() + Vector2D(4, 4);
*w->m_vRealPosition = w->m_vRealPosition->value() - Vector2D(2, 2);
}
Expand Down
40 changes: 1 addition & 39 deletions src/managers/XWaylandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void CHyprXWaylandManager::activateWindow(PHLWINDOW pWindow, bool activate) {
if (pWindow->m_bIsX11) {

if (activate) {
setWindowSize(pWindow, pWindow->m_vRealSize->value(), true); // update xwayland output pos
pWindow->sendWindowSize(pWindow->m_vRealSize->value(), true); // update xwayland output pos
pWindow->m_pXWaylandSurface->setMinimized(false);

if (!pWindow->isX11OverrideRedirect())
Expand Down Expand Up @@ -113,44 +113,6 @@ void CHyprXWaylandManager::sendCloseWindow(PHLWINDOW pWindow) {
pWindow->m_pXDGSurface->toplevel->close();
}

void CHyprXWaylandManager::setWindowSize(PHLWINDOW pWindow, Vector2D size, bool force) {

static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling");

const auto PMONITOR = pWindow->m_pMonitor.lock();

size = size.clamp(Vector2D{0, 0}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()});

// calculate pos
// TODO: this should be decoupled from setWindowSize IMO
Vector2D windowPos = pWindow->m_vRealPosition->goal();

if (pWindow->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 && pWindow->m_vPendingReportedSize == size && (windowPos == pWindow->m_vReportedPosition || !pWindow->m_bIsX11))
return;

pWindow->m_vReportedPosition = windowPos;
pWindow->m_vPendingReportedSize = size;

pWindow->m_fX11SurfaceScaledBy = 1.0f;

if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11 && PMONITOR) {
size *= PMONITOR->scale;
pWindow->m_fX11SurfaceScaledBy = PMONITOR->scale;
}

if (pWindow->m_bIsX11)
pWindow->m_pXWaylandSurface->configure({windowPos, size});
else if (pWindow->m_pXDGSurface->toplevel)
pWindow->m_vPendingSizeAcks.emplace_back(pWindow->m_pXDGSurface->toplevel->setSize(size), size.floor());
}

bool CHyprXWaylandManager::shouldBeFloated(PHLWINDOW pWindow, bool pending) {
if (pWindow->m_bIsX11) {
for (const auto& a : pWindow->m_pXWaylandSurface->atoms)
Expand Down
1 change: 0 additions & 1 deletion src/managers/XWaylandManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class CHyprXWaylandManager {
void activateWindow(PHLWINDOW, bool);
void getGeometryForWindow(PHLWINDOW, CBox*);
void sendCloseWindow(PHLWINDOW);
void setWindowSize(PHLWINDOW, Vector2D, bool force = false);
void setWindowFullscreen(PHLWINDOW, bool);
bool shouldBeFloated(PHLWINDOW, bool pending = false);
void checkBorders(PHLWINDOW);
Expand Down
2 changes: 1 addition & 1 deletion src/render/decorations/CHyprGroupBarDecoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, PHLWIND
pDraggedWindow->m_bIsFloating = pWindowInsertAfter->m_bIsFloating; // match the floating state of the window

if (pWindowInsertAfter->m_bIsFloating)
g_pXWaylandManager->setWindowSize(pDraggedWindow, pWindowInsertAfter->m_vRealSize->goal()); // match the size of the window
pDraggedWindow->sendWindowSize(pWindowInsertAfter->m_vRealSize->goal()); // match the size of the window

pWindowInsertAfter->insertWindowToGroup(pDraggedWindow);

Expand Down

0 comments on commit 445acec

Please sign in to comment.