mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 00:25:57 +01:00
layout: improve initial size prediction for floating
This commit is contained in:
parent
2930c5cb6f
commit
fcd9d77b64
7 changed files with 67 additions and 23 deletions
|
@ -782,22 +782,7 @@ void Events::listener_commitWindow(void* owner, void* data) {
|
|||
CWindow* PWINDOW = (CWindow*)owner;
|
||||
|
||||
if (!PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xdg->initial_commit) {
|
||||
Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow();
|
||||
|
||||
if (g_pXWaylandManager->shouldBeFloated(PWINDOW, true))
|
||||
predSize = {};
|
||||
|
||||
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 < predSize.x) || (maxSize.y > 0 && maxSize.y < predSize.y))
|
||||
predSize = {};
|
||||
|
||||
for (auto& r : g_pConfigManager->getMatchingRules(PWINDOW, true, true)) {
|
||||
if (r.szRule.starts_with("float")) {
|
||||
predSize = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(PWINDOW);
|
||||
|
||||
Debug::log(LOG, "Layout predicts size {} for {}", predSize, PWINDOW);
|
||||
|
||||
|
|
|
@ -1116,7 +1116,7 @@ void CHyprDwindleLayout::onDisable() {
|
|||
m_lDwindleNodesData.clear();
|
||||
}
|
||||
|
||||
Vector2D CHyprDwindleLayout::predictSizeForNewWindow() {
|
||||
Vector2D CHyprDwindleLayout::predictSizeForNewWindowTiled() {
|
||||
if (!g_pCompositor->m_pLastMonitor)
|
||||
return {};
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class CHyprDwindleLayout : public IHyprLayout {
|
|||
virtual void alterSplitRatio(CWindow*, float, bool);
|
||||
virtual std::string getLayoutName();
|
||||
virtual void replaceWindowDataWith(CWindow* from, CWindow* to);
|
||||
virtual Vector2D predictSizeForNewWindow();
|
||||
virtual Vector2D predictSizeForNewWindowTiled();
|
||||
|
||||
virtual void onEnable();
|
||||
virtual void onDisable();
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -187,7 +187,13 @@ class IHyprLayout {
|
|||
Called to predict the size of a newly opened window to send it a configure.
|
||||
Return 0,0 if unpredictable
|
||||
*/
|
||||
virtual Vector2D predictSizeForNewWindow();
|
||||
virtual Vector2D predictSizeForNewWindowTiled() = 0;
|
||||
|
||||
/*
|
||||
Prefer not overriding, use predictSizeForNewWindowTiled.
|
||||
*/
|
||||
virtual Vector2D predictSizeForNewWindow(CWindow* pWindow);
|
||||
virtual Vector2D predictSizeForNewWindowFloating(CWindow* pWindow);
|
||||
|
||||
private:
|
||||
int m_iMouseMoveEventCount;
|
||||
|
|
|
@ -1435,7 +1435,7 @@ void CHyprMasterLayout::replaceWindowDataWith(CWindow* from, CWindow* to) {
|
|||
applyNodeDataToWindow(PNODE);
|
||||
}
|
||||
|
||||
Vector2D CHyprMasterLayout::predictSizeForNewWindow() {
|
||||
Vector2D CHyprMasterLayout::predictSizeForNewWindowTiled() {
|
||||
static auto PNEWISMASTER = CConfigValue<Hyprlang::INT>("master:new_is_master");
|
||||
|
||||
if (!g_pCompositor->m_pLastMonitor)
|
||||
|
|
|
@ -65,7 +65,7 @@ class CHyprMasterLayout : public IHyprLayout {
|
|||
virtual void alterSplitRatio(CWindow*, float, bool);
|
||||
virtual std::string getLayoutName();
|
||||
virtual void replaceWindowDataWith(CWindow* from, CWindow* to);
|
||||
virtual Vector2D predictSizeForNewWindow();
|
||||
virtual Vector2D predictSizeForNewWindowTiled();
|
||||
|
||||
virtual void onEnable();
|
||||
virtual void onDisable();
|
||||
|
|
Loading…
Reference in a new issue