diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index cfa20ac8672..3267506c9f2 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -25,6 +25,7 @@ #include "../managers/HookSystemManager.hpp" #include "../managers/EventManager.hpp" #include "../managers/input/InputManager.hpp" +#include "../managers/AppFloatSizeManager.hpp" #include @@ -1213,10 +1214,22 @@ void CWindow::updateWindowData(const SWorkspaceRule& workspaceRule) { void CWindow::handleFloatingSizeRestoration() { if (m_bIsFloating) { - Debug::log(LOG, "handleFloatingSizeRestoration: window:{:x},title:{} is floating, restored:{}, lastSize:{},{}", (uintptr_t)this, m_szTitle, m_bRestoredFloatingSize, m_vLastFloatingSize.x, m_vLastFloatingSize.y); - if (!m_bRestoredFloatingSize && m_vLastFloatingSize.x > 0 && m_vLastFloatingSize.y > 0) { - Debug::log(LOG, "handleFloatingSizeRestoration: window:{:x},title:{} restoring to size {},{}", (uintptr_t)this, m_szTitle, m_vLastFloatingSize.x, m_vLastFloatingSize.y); - m_vRealSize->setValueAndWarp(m_vLastFloatingSize); + const auto appSize = CAppFloatSizeManager::getInstance()->getAppFloatSize(m_szClass); + Debug::log(LOG, "handleFloatingSizeRestoration: window:{:x},title:{} is floating, restored:{}, sizeFlag:{}, lastSize:{},{}, appSize:{},{}", + (uintptr_t)this, m_szTitle, m_bRestoredFloatingSize, + m_vUserLastFloatingSize.x > 0 && m_vUserLastFloatingSize.y > 0, + m_vUserLastFloatingSize.x, m_vUserLastFloatingSize.y, + appSize.x, appSize.y); + + if (!m_bRestoredFloatingSize) { + Vector2D sizeToUse = m_vUserLastFloatingSize; + if (sizeToUse.x <= 0 || sizeToUse.y <= 0) + sizeToUse = appSize; + if (sizeToUse.x > 0 && sizeToUse.y > 0) { + Debug::log(LOG, "handleFloatingSizeRestoration: window:{:x},title:{} restoring to size {},{}", + (uintptr_t)this, m_szTitle, sizeToUse.x, sizeToUse.y); + m_vRealSize->setValueAndWarp(sizeToUse); + } } m_bRestoredFloatingSize = true; } else { diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index 697c9fcd22f..d7753eb7d5f 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -249,6 +249,9 @@ class CWindow { // for restoring floating statuses Vector2D m_vLastFloatingSize; Vector2D m_vLastFloatingPosition; + Vector2D m_vUserLastFloatingSize; + bool m_bRestoredFloatingSize = false; + void handleFloatingSizeRestoration(); // for floating window offset in workspace animations Vector2D m_vFloatingOffset = Vector2D(0, 0); @@ -514,9 +517,6 @@ class CWindow { bool m_bHidden = false; bool m_bSuspended = false; WORKSPACEID m_iLastWorkspace = WORKSPACE_INVALID; - - bool m_bRestoredFloatingSize = false; - void handleFloatingSizeRestoration(); }; inline bool valid(PHLWINDOW w) { diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 9d3c70b624c..b71830558be 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -12,6 +12,7 @@ #include "../managers/LayoutManager.hpp" #include "../managers/EventManager.hpp" #include "../managers/HookSystemManager.hpp" +#include "../managers/AppFloatSizeManager.hpp" void IHyprLayout::onWindowCreated(PHLWINDOW pWindow, eDirection direction) { CBox desiredGeometry = g_pXWaylandManager->getGeometryForWindow(pWindow); @@ -678,8 +679,11 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { DRAGGINGWINDOW->sendWindowSize(); } - if (DRAGGINGWINDOW->m_bIsFloating) + if (DRAGGINGWINDOW->m_bIsFloating) { DRAGGINGWINDOW->m_vLastFloatingSize = wb.size(); + DRAGGINGWINDOW->m_vUserLastFloatingSize = wb.size(); + CAppFloatSizeManager::getInstance()->setAppFloatSize(DRAGGINGWINDOW->m_szClass, wb.size()); + } } else { resizeActiveWindow(TICKDELTA, m_eGrabbedCorner, DRAGGINGWINDOW); diff --git a/src/managers/AppFloatSizeManager.hpp b/src/managers/AppFloatSizeManager.hpp new file mode 100644 index 00000000000..90f0ac6a343 --- /dev/null +++ b/src/managers/AppFloatSizeManager.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include "../helpers/math/Math.hpp" + +class CAppFloatSizeManager { + public: + static CAppFloatSizeManager* getInstance() { + static CAppFloatSizeManager instance; + return &instance; + } + + void setAppFloatSize(const std::string& appClass, const Vector2D& size) { + m_mAppFloatSizes[appClass] = size; + } + + Vector2D getAppFloatSize(const std::string& appClass) { + auto it = m_mAppFloatSizes.find(appClass); + return it != m_mAppFloatSizes.end() ? it->second : Vector2D{}; + } + + private: + CAppFloatSizeManager() = default; + std::unordered_map m_mAppFloatSizes; +}; \ No newline at end of file