summaryrefslogtreecommitdiff
path: root/src/layout/IHyprLayout.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-03-29 00:43:50 +0000
committerVaxry <vaxry@vaxry.net>2024-03-29 00:43:50 +0000
commitfcd9d77b642c0cd45cae61cf10ed1924f2e7945b (patch)
tree89390e51077b58973fb444327687ee279523499c /src/layout/IHyprLayout.cpp
parent2930c5cb6f5d71dbdfd4d396287f90e19cd41228 (diff)
layout: improve initial size prediction for floating
Diffstat (limited to 'src/layout/IHyprLayout.cpp')
-rw-r--r--src/layout/IHyprLayout.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp
index 6a32144e..1570fd73 100644
--- a/src/layout/IHyprLayout.cpp
+++ b/src/layout/IHyprLayout.cpp
@@ -644,8 +644,61 @@ void IHyprLayout::requestFocusForWindow(CWindow* pWindow) {
g_pCompositor->warpCursorTo(pWindow->middle());
}
-Vector2D IHyprLayout::predictSizeForNewWindow() {
- return Vector2D{};
+Vector2D IHyprLayout::predictSizeForNewWindowFloating(CWindow* pWindow) { // get all rules, see if we have any size overrides.
+ Vector2D sizeOverride = {};
+ if (g_pCompositor->m_pLastMonitor) {
+ for (auto& r : g_pConfigManager->getMatchingRules(pWindow, true, true)) {
+ if (r.szRule.starts_with("size")) {
+ try {
+ const auto VALUE = r.szRule.substr(r.szRule.find(' ') + 1);
+ const auto SIZEXSTR = VALUE.substr(0, VALUE.find(' '));
+ const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1);
+
+ const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow);
+
+ const auto SIZEX = SIZEXSTR == "max" ?
+ std::clamp(MAXSIZE.x, 20.0, g_pCompositor->m_pLastMonitor->vecSize.x) :
+ (!SIZEXSTR.contains('%') ? std::stoi(SIZEXSTR) : std::stof(SIZEXSTR.substr(0, SIZEXSTR.length() - 1)) * 0.01 * g_pCompositor->m_pLastMonitor->vecSize.x);
+ const auto SIZEY = SIZEYSTR == "max" ?
+ std::clamp(MAXSIZE.y, 20.0, g_pCompositor->m_pLastMonitor->vecSize.y) :
+ (!SIZEYSTR.contains('%') ? std::stoi(SIZEYSTR) : std::stof(SIZEYSTR.substr(0, SIZEYSTR.length() - 1)) * 0.01 * g_pCompositor->m_pLastMonitor->vecSize.y);
+
+ sizeOverride = {SIZEX, SIZEY};
+
+ } catch (...) { Debug::log(LOG, "Rule size failed, rule: {} -> {}", r.szRule, r.szValue); }
+ break;
+ }
+ }
+ }
+
+ return sizeOverride;
+}
+
+Vector2D IHyprLayout::predictSizeForNewWindow(CWindow* pWindow) {
+ bool shouldBeFloated = g_pXWaylandManager->shouldBeFloated(pWindow, true);
+
+ if (!shouldBeFloated) {
+ for (auto& r : g_pConfigManager->getMatchingRules(pWindow, true, true)) {
+ if (r.szRule.starts_with("float")) {
+ shouldBeFloated = true;
+ break;
+ }
+ }
+ }
+
+ Vector2D sizePredicted = {};
+
+ if (!shouldBeFloated)
+ sizePredicted = predictSizeForNewWindowTiled();
+ else
+ sizePredicted = predictSizeForNewWindowFloating(pWindow);
+
+ Vector2D maxSize = Vector2D{pWindow->m_uSurface.xdg->toplevel->pending.max_width, pWindow->m_uSurface.xdg->toplevel->pending.max_height};
+
+ if ((maxSize.x > 0 && maxSize.x < sizePredicted.x) || (maxSize.y > 0 && maxSize.y < sizePredicted.y))
+ sizePredicted = {};
+
+ return sizePredicted;
}
IHyprLayout::~IHyprLayout() {}