diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-03-02 18:57:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-02 18:57:09 +0000 |
| commit | d98f7ffaf5ce8fcfe901e4cdcb3dc0d1a5f48816 (patch) | |
| tree | e4d35bfca286f36d56f859370aa0b5b2f8681c24 /src/layout/algorithm | |
| parent | 5f650f8ed99705f51b473e592c974a7ddaa3c9d7 (diff) | |
layout: store and preserve size and pos after fullscreen (#13500)
ref https://github.com/hyprwm/Hyprland/discussions/13401
Diffstat (limited to 'src/layout/algorithm')
| -rw-r--r-- | src/layout/algorithm/Algorithm.cpp | 7 | ||||
| -rw-r--r-- | src/layout/algorithm/Algorithm.hpp | 2 | ||||
| -rw-r--r-- | src/layout/algorithm/FloatingAlgorithm.hpp | 3 | ||||
| -rw-r--r-- | src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.cpp | 33 | ||||
| -rw-r--r-- | src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.hpp | 14 |
5 files changed, 59 insertions, 0 deletions
diff --git a/src/layout/algorithm/Algorithm.cpp b/src/layout/algorithm/Algorithm.cpp index a5f7ffcc..cfb5b7e3 100644 --- a/src/layout/algorithm/Algorithm.cpp +++ b/src/layout/algorithm/Algorithm.cpp @@ -262,3 +262,10 @@ SP<ITarget> CAlgorithm::getNextCandidate(SP<ITarget> old) { // god damn it, maybe empty? return nullptr; } + +void CAlgorithm::setTargetGeom(const CBox& box, SP<ITarget> target) { + if (!target->floating() || !std::ranges::contains(m_floatingTargets, target)) + return; + + m_floating->setTargetGeom(box, target); +} diff --git a/src/layout/algorithm/Algorithm.hpp b/src/layout/algorithm/Algorithm.hpp index 3ee26a3c..7df6c5c1 100644 --- a/src/layout/algorithm/Algorithm.hpp +++ b/src/layout/algorithm/Algorithm.hpp @@ -40,6 +40,8 @@ namespace Layout { void resizeTarget(const Vector2D& Δ, SP<ITarget> target, eRectCorner corner = CORNER_NONE); void moveTarget(const Vector2D& Δ, SP<ITarget> target); + void setTargetGeom(const CBox& box, SP<ITarget> target); // only for float + void updateFloatingAlgo(UP<IFloatingAlgorithm>&& algo); void updateTiledAlgo(UP<ITiledAlgorithm>&& algo); diff --git a/src/layout/algorithm/FloatingAlgorithm.hpp b/src/layout/algorithm/FloatingAlgorithm.hpp index 2c9ff14b..40e53034 100644 --- a/src/layout/algorithm/FloatingAlgorithm.hpp +++ b/src/layout/algorithm/FloatingAlgorithm.hpp @@ -17,6 +17,9 @@ namespace Layout { // a target is being moved by a delta virtual void moveTarget(const Vector2D& Δ, SP<ITarget> target) = 0; + // a target is moved to a pos x size + virtual void setTargetGeom(const CBox& geom, SP<ITarget> target) = 0; + virtual void recenter(SP<ITarget> t); virtual void recalculate(); diff --git a/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.cpp b/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.cpp index 1fe3b068..0d069e4f 100644 --- a/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.cpp +++ b/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.cpp @@ -116,6 +116,8 @@ void CDefaultFloatingAlgorithm::newTarget(SP<ITarget> target) { PWINDOW->m_reportedSize = PWINDOW->m_pendingReportedSize; } } + + updateTarget(target); } void CDefaultFloatingAlgorithm::movedTarget(SP<ITarget> target, std::optional<Vector2D> focalPoint) { @@ -152,6 +154,8 @@ void CDefaultFloatingAlgorithm::movedTarget(SP<ITarget> target, std::optional<Ve // put around the current center, fit in workArea target->setPositionGlobal(fitBoxInWorkArea(CBox{NEW_POS, LAST_SIZE}, target)); } + + updateTarget(target); } CBox CDefaultFloatingAlgorithm::fitBoxInWorkArea(const CBox& box, SP<ITarget> t) { @@ -173,6 +177,7 @@ CBox CDefaultFloatingAlgorithm::fitBoxInWorkArea(const CBox& box, SP<ITarget> t) void CDefaultFloatingAlgorithm::removeTarget(SP<ITarget> target) { target->rememberFloatingSize(target->position().size()); + m_datas.erase(target); } void CDefaultFloatingAlgorithm::resizeTarget(const Vector2D& Δ, SP<ITarget> target, eRectCorner corner) { @@ -184,6 +189,8 @@ void CDefaultFloatingAlgorithm::resizeTarget(const Vector2D& Δ, SP<ITarget> tar if (g_layoutManager->dragController()->target() == target) target->warpPositionSize(); + + updateTarget(target); } void CDefaultFloatingAlgorithm::moveTarget(const Vector2D& Δ, SP<ITarget> target) { @@ -193,12 +200,17 @@ void CDefaultFloatingAlgorithm::moveTarget(const Vector2D& Δ, SP<ITarget> targe if (g_layoutManager->dragController()->target() == target) target->warpPositionSize(); + + updateTarget(target); } void CDefaultFloatingAlgorithm::swapTargets(SP<ITarget> a, SP<ITarget> b) { auto posABackup = a->position(); a->setPositionGlobal(b->position()); b->setPositionGlobal(posABackup); + + updateTarget(a); + updateTarget(b); } void CDefaultFloatingAlgorithm::moveTargetInDirection(SP<ITarget> t, Math::eDirection dir, bool silent) { @@ -216,4 +228,25 @@ void CDefaultFloatingAlgorithm::moveTargetInDirection(SP<ITarget> t, Math::eDire } t->setPositionGlobal(pos); + + updateTarget(t); +} + +void CDefaultFloatingAlgorithm::recenter(SP<ITarget> t) { + if (!m_datas.contains(t)) { + IFloatingAlgorithm::recenter(t); + return; + } + + t->setPositionGlobal(m_datas.at(t).lastBox); +} + +void CDefaultFloatingAlgorithm::setTargetGeom(const CBox& geom, SP<ITarget> target) { + target->setPositionGlobal(geom); + + updateTarget(target); +} + +void CDefaultFloatingAlgorithm::updateTarget(SP<ITarget> t) { + m_datas[t] = {.lastBox = t->position()}; } diff --git a/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.hpp b/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.hpp index ef94e371..1e87fac1 100644 --- a/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.hpp +++ b/src/layout/algorithm/floating/default/DefaultFloatingAlgorithm.hpp @@ -1,5 +1,7 @@ #include "../../FloatingAlgorithm.hpp" +#include <map> + namespace Layout { class CAlgorithm; } @@ -17,10 +19,22 @@ namespace Layout::Floating { virtual void resizeTarget(const Vector2D& Δ, SP<ITarget> target, eRectCorner corner = CORNER_NONE); virtual void moveTarget(const Vector2D& Δ, SP<ITarget> target); + virtual void setTargetGeom(const CBox& geom, SP<ITarget> target); + virtual void swapTargets(SP<ITarget> a, SP<ITarget> b); virtual void moveTargetInDirection(SP<ITarget> t, Math::eDirection dir, bool silent); + virtual void recenter(SP<ITarget> t); + private: CBox fitBoxInWorkArea(const CBox& box, SP<ITarget> t); + + void updateTarget(SP<ITarget>); + + struct SWindowData { + CBox lastBox; + }; + + std::map<WP<ITarget>, SWindowData> m_datas; }; };
\ No newline at end of file |
