Skip to content

Commit

Permalink
no
Browse files Browse the repository at this point in the history
  • Loading branch information
nnyyxxxx committed Feb 24, 2025
1 parent c5d22ce commit 556a817
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../managers/HookSystemManager.hpp"
#include "../managers/EventManager.hpp"
#include "../managers/input/InputManager.hpp"
#include "../managers/AppFloatSizeManager.hpp"

#include <hyprutils/string/String.hpp>

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/desktop/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions src/managers/AppFloatSizeManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <string>
#include <unordered_map>
#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<std::string, Vector2D> m_mAppFloatSizes;
};

0 comments on commit 556a817

Please sign in to comment.