Skip to content

Commit

Permalink
window: move size reporting to animation begin callback (#9298)
Browse files Browse the repository at this point in the history
* window: fix resizes with an update callback

* window: fixup sendWindowSize

Remove the size argument from sendWindowSize, since it is now a member of the Window class
and we don't want any mismatches between m_vRealSize and what we report.

Remove sendWindowSize from mapWindow, since we shouldn't need it.

* window: sendWindowSize on animation begin

* window: move most calls to sendWindowSize to the animation begin
callback

* window: remove sendWindowSize in unmanaged if not fullscreen
  • Loading branch information
PaideiaDilemma authored Feb 6, 2025
1 parent f1e32cd commit ff9e059
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,7 @@ void CCompositor::setWindowFullscreenState(const PHLWINDOW PWINDOW, SFullscreenS

updateFullscreenFadeOnWorkspace(PWORKSPACE);

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

PWORKSPACE->forceReportSizesToWindows();

Expand Down
26 changes: 15 additions & 11 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,6 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) {
}
}

// update xwayland coords
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)
PMONITOR->setSpecialWorkspace(nullptr);
Expand Down Expand Up @@ -563,6 +560,15 @@ void CWindow::onMap() {
*m_fBorderAngleAnimationProgress = 1.f;
}

m_vRealSize->setCallbackOnBegin(
[this](auto) {
if (!m_bIsMapped || isX11OverrideRedirect())
return;

sendWindowSize();
},
false);

m_fMovingFromWorkspaceAlpha->setValueAndWarp(1.F);

g_pCompositor->m_vWindowFocusHistory.push_back(m_pSelf);
Expand Down Expand Up @@ -1315,7 +1321,6 @@ void CWindow::clampWindowSize(const std::optional<Vector2D> minSize, const std::

*m_vRealPosition = m_vRealPosition->goal() + DELTA / 2.0;
*m_vRealSize = NEWSIZE;
sendWindowSize(NEWSIZE);
}

bool CWindow::isFullscreen() {
Expand Down Expand Up @@ -1539,7 +1544,7 @@ void CWindow::onX11Configure(CBox box) {
g_pHyprRenderer->damageWindow(m_pSelf.lock());

if (!m_bIsFloating || isFullscreen() || g_pInputManager->currentlyDraggedWindow == m_pSelf) {
sendWindowSize(m_vRealSize->goal(), true);
sendWindowSize(true);
g_pInputManager->refocus();
g_pHyprRenderer->damageWindow(m_pSelf.lock());
return;
Expand All @@ -1566,8 +1571,6 @@ void CWindow::onX11Configure(CBox box) {
m_vPosition = m_vRealPosition->goal();
m_vSize = m_vRealSize->goal();

sendWindowSize(box.size(), true);

m_vPendingReportedSize = box.size();
m_vReportedSize = box.size();

Expand Down Expand Up @@ -1697,15 +1700,16 @@ Vector2D CWindow::requestedMaxSize() {
return maxSize;
}

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

size = size.clamp(Vector2D{1, 1}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()});
Debug::log(TRACE, "sendWindowSize: window:{:x},title:{} with real pos {}, real size {} (force: {})", (uintptr_t)this, this->m_szTitle, m_vRealPosition->goal(),
m_vRealSize->goal(), force);

// calculate pos
// TODO: this should be decoupled from setWindowSize IMO
Vector2D windowPos = overridePos.value_or(m_vRealPosition->goal());
Vector2D windowPos = m_vRealPosition->goal();
Vector2D size = m_vRealSize->goal().clamp(Vector2D{1, 1}, Vector2D{std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()});

if (m_bIsX11 && PMONITOR) {
windowPos = g_pXWaylandManager->waylandToXWaylandCoords(windowPos);
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class CWindow {
bool isModal();
Vector2D requestedMinSize();
Vector2D requestedMaxSize();
void sendWindowSize(Vector2D size, bool force = false, std::optional<Vector2D> overridePos = std::nullopt);
void sendWindowSize(bool force = false);
NContentType::eContentType getContentType();
void setContentType(NContentType::eContentType contentType);

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;

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

Expand Down
9 changes: 1 addition & 8 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,6 @@ void Events::listener_mapWindow(void* owner, void* data) {

if (PMONITOR && PWINDOW->isX11OverrideRedirect())
PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale;

// 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 @@ -964,7 +957,7 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) {
PWINDOW->setHidden(true);

if (PWINDOW->isFullscreen() || !PWINDOW->m_bIsFloating) {
PWINDOW->sendWindowSize(PWINDOW->m_vRealSize->goal(), true);
PWINDOW->sendWindowSize(true);
g_pHyprRenderer->damageWindow(PWINDOW);
return;
}
Expand Down
4 changes: 0 additions & 4 deletions src/layout/DwindleLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,12 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for

*PWINDOW->m_vRealPosition = wb.pos();
*PWINDOW->m_vRealSize = 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();

PWINDOW->sendWindowSize(wb.size());
}

if (force) {
Expand Down
18 changes: 6 additions & 12 deletions src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,9 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) {
pWindow->m_vRealSize->warp();
}

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

if (!pWindow->isX11OverrideRedirect())
g_pCompositor->changeWindowZOrder(pWindow, true);
} else {
else {
pWindow->m_vPendingReportedSize = pWindow->m_vRealSize->goal();
pWindow->m_vReportedSize = pWindow->m_vPendingReportedSize;
}
Expand Down Expand Up @@ -362,9 +360,6 @@ void IHyprLayout::onEndDragWindow() {
DRAGGINGWINDOW->m_vLastFloatingSize = m_vDraggingWindowOriginalFloatSize;
DRAGGINGWINDOW->m_bDraggingTiled = false;

if (pWindow->m_bIsFloating)
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);
pWindow->setGroupCurrent(DRAGGINGWINDOW);
Expand Down Expand Up @@ -606,10 +601,11 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) {

if (*PANIMATEMOUSE)
*DRAGGINGWINDOW->m_vRealPosition = wb.pos();
else
else {
DRAGGINGWINDOW->m_vRealPosition->setValueAndWarp(wb.pos());
DRAGGINGWINDOW->sendWindowSize();
}

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 @@ -679,9 +675,8 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
} else {
DRAGGINGWINDOW->m_vRealSize->setValueAndWarp(wb.size());
DRAGGINGWINDOW->m_vRealPosition->setValueAndWarp(wb.pos());
DRAGGINGWINDOW->sendWindowSize();
}

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

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

Expand Down
4 changes: 0 additions & 4 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,16 +678,12 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) {

*PWINDOW->m_vRealPosition = wb.pos();
*PWINDOW->m_vRealSize = 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();

PWINDOW->sendWindowSize(wb.size());
}

if (m_bForceWarps && !*PANIMATE) {
Expand Down
1 change: 0 additions & 1 deletion src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,6 @@ SDispatchResult CKeybindManager::workspaceOpt(std::string args) {
if (PWORKSPACE->m_bDefaultFloating) {
w->m_vRealPosition->setValueAndWarp(SAVEDPOS);
w->m_vRealSize->setValueAndWarp(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
2 changes: 1 addition & 1 deletion 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) {
pWindow->sendWindowSize(pWindow->m_vRealSize->value(), true); // update xwayland output pos
pWindow->sendWindowSize(true); // update xwayland output pos
pWindow->m_pXWaylandSurface->setMinimized(false);

if (!pWindow->isX11OverrideRedirect())
Expand Down
3 changes: 0 additions & 3 deletions src/render/decorations/CHyprGroupBarDecoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,6 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, PHLWIND

pDraggedWindow->m_bIsFloating = pWindowInsertAfter->m_bIsFloating; // match the floating state of the window

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

pWindowInsertAfter->insertWindowToGroup(pDraggedWindow);

if (WINDOWINDEX == -1)
Expand Down

0 comments on commit ff9e059

Please sign in to comment.