2022-03-19 15:59:53 +01:00
|
|
|
#include "DwindleLayout.hpp"
|
2023-09-20 17:25:03 +02:00
|
|
|
#include "../render/decorations/CHyprGroupBarDecoration.hpp"
|
2022-03-19 15:59:53 +01:00
|
|
|
#include "../Compositor.hpp"
|
2024-03-03 19:39:20 +01:00
|
|
|
#include "../config/ConfigValue.hpp"
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2023-05-06 02:02:18 +02:00
|
|
|
void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverride, bool verticalOverride) {
|
2022-03-19 20:30:21 +01:00
|
|
|
if (children[0]) {
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PSMARTSPLIT = CConfigValue<Hyprlang::INT>("dwindle:smart_split");
|
|
|
|
static auto PPRESERVESPLIT = CConfigValue<Hyprlang::INT>("dwindle:preserve_split");
|
|
|
|
static auto PFLMULT = CConfigValue<Hyprlang::FLOAT>("dwindle:split_width_multiplier");
|
2022-08-26 19:06:10 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PPRESERVESPLIT == 0 && *PSMARTSPLIT == 0)
|
|
|
|
splitTop = box.h * *PFLMULT > box.w;
|
2022-05-16 17:27:55 +02:00
|
|
|
|
2023-05-06 02:02:18 +02:00
|
|
|
if (verticalOverride == true)
|
|
|
|
splitTop = true;
|
|
|
|
else if (horizontalOverride == true)
|
|
|
|
splitTop = false;
|
|
|
|
|
2022-05-16 17:27:55 +02:00
|
|
|
const auto SPLITSIDE = !splitTop;
|
|
|
|
|
|
|
|
if (SPLITSIDE) {
|
2022-06-20 18:11:59 +02:00
|
|
|
// split left/right
|
2023-11-04 22:45:34 +01:00
|
|
|
const float FIRSTSIZE = box.w / 2.0 * splitRatio;
|
2024-02-02 16:04:04 +01:00
|
|
|
children[0]->box = CBox{box.x, box.y, FIRSTSIZE, box.h}.noNegativeSize();
|
|
|
|
children[1]->box = CBox{box.x + FIRSTSIZE, box.y, box.w - FIRSTSIZE, box.h}.noNegativeSize();
|
2022-03-19 20:30:21 +01:00
|
|
|
} else {
|
2022-06-20 18:11:59 +02:00
|
|
|
// split top/bottom
|
2023-11-04 22:45:34 +01:00
|
|
|
const float FIRSTSIZE = box.h / 2.0 * splitRatio;
|
2024-02-02 16:04:04 +01:00
|
|
|
children[0]->box = CBox{box.x, box.y, box.w, FIRSTSIZE}.noNegativeSize();
|
|
|
|
children[1]->box = CBox{box.x, box.y + FIRSTSIZE, box.w, box.h - FIRSTSIZE}.noNegativeSize();
|
2022-03-19 20:30:21 +01:00
|
|
|
}
|
|
|
|
|
2022-08-03 12:30:28 +02:00
|
|
|
children[0]->recalcSizePosRecursive(force);
|
|
|
|
children[1]->recalcSizePosRecursive(force);
|
2022-03-19 20:30:21 +01:00
|
|
|
} else {
|
2022-08-03 12:27:20 +02:00
|
|
|
layout->applyNodeDataToWindow(this, force);
|
2022-03-19 20:30:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 16:44:18 +02:00
|
|
|
void SDwindleNodeData::getAllChildrenRecursive(std::deque<SDwindleNodeData*>* pDeque) {
|
|
|
|
if (children[0]) {
|
|
|
|
children[0]->getAllChildrenRecursive(pDeque);
|
|
|
|
children[1]->getAllChildrenRecursive(pDeque);
|
|
|
|
} else {
|
|
|
|
pDeque->push_back(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-20 16:06:17 +01:00
|
|
|
int CHyprDwindleLayout::getNodesOnWorkspace(const int& id) {
|
2022-03-19 15:59:53 +01:00
|
|
|
int no = 0;
|
|
|
|
for (auto& n : m_lDwindleNodesData) {
|
2022-08-01 12:51:52 +02:00
|
|
|
if (n.workspaceID == id && n.valid)
|
2022-03-19 15:59:53 +01:00
|
|
|
++no;
|
|
|
|
}
|
|
|
|
return no;
|
|
|
|
}
|
|
|
|
|
2022-03-20 16:06:17 +01:00
|
|
|
SDwindleNodeData* CHyprDwindleLayout::getFirstNodeOnWorkspace(const int& id) {
|
2022-03-19 15:59:53 +01:00
|
|
|
for (auto& n : m_lDwindleNodesData) {
|
2022-03-24 19:05:25 +01:00
|
|
|
if (n.workspaceID == id && n.pWindow && g_pCompositor->windowValidMapped(n.pWindow))
|
2022-03-19 15:59:53 +01:00
|
|
|
return &n;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-01-26 23:30:36 +01:00
|
|
|
SDwindleNodeData* CHyprDwindleLayout::getClosestNodeOnWorkspace(const int& id, const Vector2D& point) {
|
|
|
|
SDwindleNodeData* res = nullptr;
|
|
|
|
double distClosest = -1;
|
|
|
|
for (auto& n : m_lDwindleNodesData) {
|
|
|
|
if (n.workspaceID == id && n.pWindow && g_pCompositor->windowValidMapped(n.pWindow)) {
|
|
|
|
auto distAnother = vecToRectDistanceSquared(point, n.box.pos(), n.box.pos() + n.box.size());
|
|
|
|
if (!res || distAnother < distClosest) {
|
|
|
|
res = &n;
|
|
|
|
distClosest = distAnother;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
SDwindleNodeData* CHyprDwindleLayout::getNodeFromWindow(CWindow* pWindow) {
|
|
|
|
for (auto& n : m_lDwindleNodesData) {
|
2022-03-19 20:30:21 +01:00
|
|
|
if (n.pWindow == pWindow && !n.isNode)
|
2022-03-19 15:59:53 +01:00
|
|
|
return &n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-03-20 16:06:17 +01:00
|
|
|
SDwindleNodeData* CHyprDwindleLayout::getMasterNodeOnWorkspace(const int& id) {
|
2022-03-19 20:30:21 +01:00
|
|
|
for (auto& n : m_lDwindleNodesData) {
|
2022-03-20 16:06:17 +01:00
|
|
|
if (!n.pParent && n.workspaceID == id)
|
2022-03-19 20:30:21 +01:00
|
|
|
return &n;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-08-03 12:27:20 +02:00
|
|
|
void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool force) {
|
2022-07-03 23:14:51 +02:00
|
|
|
// Don't set nodes, only windows.
|
2022-09-25 20:07:48 +02:00
|
|
|
if (pNode->isNode)
|
2022-07-03 23:14:51 +02:00
|
|
|
return;
|
|
|
|
|
2022-07-27 12:32:00 +02:00
|
|
|
CMonitor* PMONITOR = nullptr;
|
2022-07-03 23:16:42 +02:00
|
|
|
|
2022-11-27 23:42:22 +01:00
|
|
|
if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) {
|
2022-07-03 23:16:42 +02:00
|
|
|
for (auto& m : g_pCompositor->m_vMonitors) {
|
2022-11-27 23:42:22 +01:00
|
|
|
if (m->specialWorkspaceID == pNode->workspaceID) {
|
2022-07-03 23:16:42 +02:00
|
|
|
PMONITOR = m.get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PMONITOR = g_pCompositor->getMonitorFromID(g_pCompositor->getWorkspaceByID(pNode->workspaceID)->m_iMonitorID);
|
|
|
|
}
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2022-07-03 23:14:51 +02:00
|
|
|
if (!PMONITOR) {
|
2023-09-20 17:25:03 +02:00
|
|
|
Debug::log(ERR, "Orphaned Node {}!!", pNode);
|
2022-03-19 15:59:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for gaps outer
|
2023-11-04 22:45:34 +01:00
|
|
|
const bool DISPLAYLEFT = STICKS(pNode->box.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
|
|
|
|
const bool DISPLAYRIGHT = STICKS(pNode->box.x + pNode->box.w, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
|
|
|
|
const bool DISPLAYTOP = STICKS(pNode->box.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
|
|
|
|
const bool DISPLAYBOTTOM = STICKS(pNode->box.y + pNode->box.h, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
|
2023-05-01 23:28:27 +02:00
|
|
|
|
|
|
|
const auto PWINDOW = pNode->pWindow;
|
|
|
|
// get specific gaps and rules for this workspace,
|
|
|
|
// if user specified them in config
|
2024-02-28 12:45:43 +01:00
|
|
|
const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(pNode->workspaceID));
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowExists(PWINDOW)) {
|
|
|
|
Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW);
|
|
|
|
onWindowRemovedTiling(PWINDOW);
|
|
|
|
return;
|
|
|
|
}
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2023-11-03 13:19:23 +01:00
|
|
|
if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks)
|
2023-11-01 02:28:43 +01:00
|
|
|
return;
|
|
|
|
|
2023-08-17 10:13:19 +02:00
|
|
|
PWINDOW->updateSpecialRenderData();
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PNOGAPSWHENONLY = CConfigValue<Hyprlang::INT>("dwindle:no_gaps_when_only");
|
|
|
|
static auto PGAPSINDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_in");
|
|
|
|
static auto PGAPSOUTDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_out");
|
|
|
|
auto* const PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData();
|
|
|
|
auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData();
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN);
|
|
|
|
auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT);
|
2023-07-23 15:49:49 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
CBox nodeBox = pNode->box;
|
2023-11-04 22:45:34 +01:00
|
|
|
nodeBox.round();
|
|
|
|
|
|
|
|
PWINDOW->m_vSize = nodeBox.size();
|
|
|
|
PWINDOW->m_vPosition = nodeBox.pos();
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2023-08-17 10:13:19 +02:00
|
|
|
const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->m_iWorkspaceID);
|
2022-09-01 19:46:35 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) &&
|
2023-02-19 22:07:32 +01:00
|
|
|
(NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) {
|
2022-08-01 12:51:52 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(*PNOGAPSWHENONLY == 2);
|
2023-08-17 10:13:19 +02:00
|
|
|
PWINDOW->m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true);
|
2022-08-01 12:51:52 +02:00
|
|
|
PWINDOW->m_sSpecialRenderData.rounding = false;
|
2023-08-12 23:37:55 +02:00
|
|
|
PWINDOW->m_sSpecialRenderData.shadow = false;
|
2023-07-24 12:13:40 +02:00
|
|
|
|
2023-12-10 17:28:12 +01:00
|
|
|
PWINDOW->updateWindowDecos();
|
2023-07-24 12:13:40 +02:00
|
|
|
|
2023-12-10 17:28:12 +01:00
|
|
|
const auto RESERVED = PWINDOW->getFullWindowReservedArea();
|
2023-07-24 12:13:40 +02:00
|
|
|
|
2023-12-10 17:28:12 +01:00
|
|
|
PWINDOW->m_vRealPosition = PWINDOW->m_vPosition + RESERVED.topLeft;
|
|
|
|
PWINDOW->m_vRealSize = PWINDOW->m_vSize - (RESERVED.topLeft + RESERVED.bottomRight);
|
2022-08-01 12:51:52 +02:00
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal());
|
2023-11-05 00:00:20 +01:00
|
|
|
|
2022-08-01 12:51:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-10 17:28:12 +01:00
|
|
|
auto calcPos = PWINDOW->m_vPosition;
|
|
|
|
auto calcSize = PWINDOW->m_vSize;
|
2023-07-24 12:13:40 +02:00
|
|
|
|
2024-02-21 12:07:39 +01:00
|
|
|
const auto OFFSETTOPLEFT = Vector2D(DISPLAYLEFT ? gapsOut.left : gapsIn.left, DISPLAYTOP ? gapsOut.top : gapsIn.top);
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2024-02-21 12:07:39 +01:00
|
|
|
const auto OFFSETBOTTOMRIGHT = Vector2D(DISPLAYRIGHT ? gapsOut.right : gapsIn.right, DISPLAYBOTTOM ? gapsOut.bottom : gapsIn.bottom);
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
calcPos = calcPos + OFFSETTOPLEFT;
|
2022-04-23 14:35:34 +02:00
|
|
|
calcSize = calcSize - OFFSETTOPLEFT - OFFSETBOTTOMRIGHT;
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2022-04-02 20:04:32 +02:00
|
|
|
if (PWINDOW->m_bIsPseudotiled) {
|
|
|
|
// Calculate pseudo
|
|
|
|
float scale = 1;
|
|
|
|
|
|
|
|
// adjust if doesnt fit
|
2022-04-23 14:35:34 +02:00
|
|
|
if (PWINDOW->m_vPseudoSize.x > calcSize.x || PWINDOW->m_vPseudoSize.y > calcSize.y) {
|
|
|
|
if (PWINDOW->m_vPseudoSize.x > calcSize.x) {
|
|
|
|
scale = calcSize.x / PWINDOW->m_vPseudoSize.x;
|
2022-04-02 20:04:32 +02:00
|
|
|
}
|
|
|
|
|
2022-04-23 14:35:34 +02:00
|
|
|
if (PWINDOW->m_vPseudoSize.y * scale > calcSize.y) {
|
|
|
|
scale = calcSize.y / PWINDOW->m_vPseudoSize.y;
|
2022-04-02 20:04:32 +02:00
|
|
|
}
|
|
|
|
|
2022-04-23 14:35:34 +02:00
|
|
|
auto DELTA = calcSize - PWINDOW->m_vPseudoSize * scale;
|
2022-12-16 18:17:31 +01:00
|
|
|
calcSize = PWINDOW->m_vPseudoSize * scale;
|
|
|
|
calcPos = calcPos + DELTA / 2.f; // center
|
2022-04-02 20:04:32 +02:00
|
|
|
} else {
|
2022-04-23 14:35:34 +02:00
|
|
|
auto DELTA = calcSize - PWINDOW->m_vPseudoSize;
|
2022-12-16 18:17:31 +01:00
|
|
|
calcPos = calcPos + DELTA / 2.f; // center
|
|
|
|
calcSize = PWINDOW->m_vPseudoSize;
|
2022-04-02 20:04:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 22:18:09 +01:00
|
|
|
const auto RESERVED = PWINDOW->getFullWindowReservedArea();
|
|
|
|
calcPos = calcPos + RESERVED.topLeft;
|
|
|
|
calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight);
|
|
|
|
|
2024-03-05 00:29:45 +01:00
|
|
|
if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && !PWINDOW->m_bIsFullscreen) {
|
2022-05-31 14:01:00 +02:00
|
|
|
// if special, we adjust the coords a bit
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PSCALEFACTOR = CConfigValue<Hyprlang::FLOAT>("dwindle:special_scale_factor");
|
2022-05-31 14:01:00 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
CBox wb = {calcPos + (calcSize - calcSize * *PSCALEFACTOR) / 2.f, calcSize * *PSCALEFACTOR};
|
2023-11-05 20:57:11 +01:00
|
|
|
wb.round(); // avoid rounding mess
|
2022-06-03 19:03:33 +02:00
|
|
|
|
2023-11-05 20:57:11 +01:00
|
|
|
PWINDOW->m_vRealPosition = wb.pos();
|
|
|
|
PWINDOW->m_vRealSize = wb.size();
|
|
|
|
|
|
|
|
g_pXWaylandManager->setWindowSize(PWINDOW, wb.size());
|
2022-05-31 14:01:00 +02:00
|
|
|
} else {
|
2024-02-14 12:28:43 +01:00
|
|
|
CBox wb = {calcPos, calcSize};
|
|
|
|
wb.round(); // avoid rounding mess
|
|
|
|
|
|
|
|
PWINDOW->m_vRealSize = wb.size();
|
|
|
|
PWINDOW->m_vRealPosition = wb.pos();
|
2022-05-31 14:01:00 +02:00
|
|
|
|
2024-02-14 12:28:43 +01:00
|
|
|
g_pXWaylandManager->setWindowSize(PWINDOW, wb.size());
|
2022-05-31 14:01:00 +02:00
|
|
|
}
|
2022-06-27 00:25:37 +02:00
|
|
|
|
2022-08-03 12:27:20 +02:00
|
|
|
if (force) {
|
2022-08-24 13:44:48 +02:00
|
|
|
g_pHyprRenderer->damageWindow(PWINDOW);
|
|
|
|
|
2022-08-03 12:27:20 +02:00
|
|
|
PWINDOW->m_vRealPosition.warp();
|
|
|
|
PWINDOW->m_vRealSize.warp();
|
2022-08-23 15:08:15 +02:00
|
|
|
|
|
|
|
g_pHyprRenderer->damageWindow(PWINDOW);
|
2022-08-03 12:27:20 +02:00
|
|
|
}
|
|
|
|
|
2022-06-27 00:25:37 +02:00
|
|
|
PWINDOW->updateWindowDecos();
|
2022-03-19 15:59:53 +01:00
|
|
|
}
|
|
|
|
|
2023-09-13 12:13:29 +02:00
|
|
|
void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direction) {
|
2022-03-23 16:51:48 +01:00
|
|
|
if (pWindow->m_bIsFloating)
|
|
|
|
return;
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
m_lDwindleNodesData.push_back(SDwindleNodeData());
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto PNODE = &m_lDwindleNodesData.back();
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
2022-03-20 16:06:17 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PUSEACTIVE = CConfigValue<Hyprlang::INT>("dwindle:use_active_for_splits");
|
|
|
|
static auto PDEFAULTSPLIT = CConfigValue<Hyprlang::FLOAT>("dwindle:default_split_ratio");
|
2022-08-19 22:03:35 +02:00
|
|
|
|
2023-09-13 12:13:29 +02:00
|
|
|
if (direction != DIRECTION_DEFAULT && overrideDirection == DIRECTION_DEFAULT)
|
|
|
|
overrideDirection = direction;
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
// Populate the node with our window's data
|
2022-05-18 12:18:58 +02:00
|
|
|
PNODE->workspaceID = pWindow->m_iWorkspaceID;
|
2022-12-16 18:17:31 +01:00
|
|
|
PNODE->pWindow = pWindow;
|
|
|
|
PNODE->isNode = false;
|
|
|
|
PNODE->layout = this;
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2022-03-23 16:51:48 +01:00
|
|
|
SDwindleNodeData* OPENINGON;
|
2023-09-04 15:34:07 +02:00
|
|
|
|
|
|
|
const auto MOUSECOORDS = m_vOverrideFocalPoint.value_or(g_pInputManager->getMouseCoordsInternal());
|
|
|
|
const auto MONFROMCURSOR = g_pCompositor->getMonitorFromVector(MOUSECOORDS);
|
2022-03-23 16:51:48 +01:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (PMONITOR->ID == MONFROMCURSOR->ID &&
|
2024-03-03 19:39:20 +01:00
|
|
|
(PNODE->workspaceID == PMONITOR->activeWorkspace || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->specialWorkspaceID)) && !*PUSEACTIVE) {
|
2024-02-04 16:40:20 +01:00
|
|
|
OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS));
|
2022-05-25 18:40:03 +02:00
|
|
|
|
2024-01-26 23:30:36 +01:00
|
|
|
if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR))
|
|
|
|
OPENINGON = getClosestNodeOnWorkspace(PNODE->workspaceID, MOUSECOORDS);
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
} else if (*PUSEACTIVE) {
|
2022-12-16 18:17:31 +01:00
|
|
|
if (g_pCompositor->m_pLastWindow && !g_pCompositor->m_pLastWindow->m_bIsFloating && g_pCompositor->m_pLastWindow != pWindow &&
|
|
|
|
g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsMapped) {
|
2022-08-19 22:03:35 +02:00
|
|
|
OPENINGON = getNodeFromWindow(g_pCompositor->m_pLastWindow);
|
|
|
|
} else {
|
2024-02-04 16:40:20 +01:00
|
|
|
OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS));
|
2022-08-19 22:03:35 +02:00
|
|
|
}
|
|
|
|
|
2024-01-26 23:30:36 +01:00
|
|
|
if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR))
|
|
|
|
OPENINGON = getClosestNodeOnWorkspace(PNODE->workspaceID, MOUSECOORDS);
|
|
|
|
|
2022-05-25 18:40:03 +02:00
|
|
|
} else
|
2022-07-16 15:57:31 +02:00
|
|
|
OPENINGON = getFirstNodeOnWorkspace(pWindow->m_iWorkspaceID);
|
2022-03-24 19:05:25 +01:00
|
|
|
|
2023-09-20 17:25:03 +02:00
|
|
|
Debug::log(LOG, "OPENINGON: {}, Monitor: {}", OPENINGON, PMONITOR->ID);
|
2022-03-22 22:04:35 +01:00
|
|
|
|
2022-05-31 14:04:11 +02:00
|
|
|
if (OPENINGON && OPENINGON->workspaceID != PNODE->workspaceID) {
|
2022-05-31 14:01:00 +02:00
|
|
|
// special workspace handling
|
|
|
|
OPENINGON = getFirstNodeOnWorkspace(PNODE->workspaceID);
|
|
|
|
}
|
|
|
|
|
2022-08-05 18:10:59 +02:00
|
|
|
// first, check if OPENINGON isn't too big.
|
2023-11-04 22:45:34 +01:00
|
|
|
const auto PREDSIZEMAX = OPENINGON ? Vector2D(OPENINGON->box.w, OPENINGON->box.h) : PMONITOR->vecSize;
|
2022-08-05 20:00:17 +02:00
|
|
|
if (const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow); MAXSIZE.x < PREDSIZEMAX.x || MAXSIZE.y < PREDSIZEMAX.y) {
|
2022-08-05 18:10:59 +02:00
|
|
|
// we can't continue. make it floating.
|
|
|
|
pWindow->m_bIsFloating = true;
|
|
|
|
m_lDwindleNodesData.remove(*PNODE);
|
|
|
|
g_pLayoutManager->getCurrentLayout()->onWindowCreatedFloating(pWindow);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-07 19:53:10 +01:00
|
|
|
// last fail-safe to avoid duplicate fullscreens
|
|
|
|
if ((!OPENINGON || OPENINGON->pWindow == pWindow) && getNodesOnWorkspace(PNODE->workspaceID) > 1) {
|
|
|
|
for (auto& node : m_lDwindleNodesData) {
|
2023-09-13 12:13:29 +02:00
|
|
|
if (node.workspaceID == PNODE->workspaceID && node.pWindow != nullptr && node.pWindow != pWindow) {
|
2022-12-07 19:53:10 +01:00
|
|
|
OPENINGON = &node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
// if it's the first, it's easy. Make it fullscreen.
|
2022-03-24 19:05:25 +01:00
|
|
|
if (!OPENINGON || OPENINGON->pWindow == pWindow) {
|
2023-11-04 22:45:34 +01:00
|
|
|
PNODE->box = CBox{PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight};
|
2022-03-19 15:59:53 +01:00
|
|
|
|
|
|
|
applyNodeDataToWindow(PNODE);
|
|
|
|
|
2023-09-22 01:42:00 +02:00
|
|
|
pWindow->applyGroupRules();
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-08-11 19:29:39 +02:00
|
|
|
|
2023-10-29 21:14:47 +01:00
|
|
|
if (!m_vOverrideFocalPoint && g_pInputManager->m_bWasDraggingWindow) {
|
2023-12-28 23:54:41 +01:00
|
|
|
if (OPENINGON->pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_END, MOUSECOORDS, pWindow))
|
|
|
|
return;
|
2023-10-29 21:14:47 +01:00
|
|
|
}
|
|
|
|
|
2022-08-11 19:29:39 +02:00
|
|
|
// if it's a group, add the window
|
2023-10-30 15:54:12 +01:00
|
|
|
if (OPENINGON->pWindow->m_sGroupData.pNextWindow // target is group
|
|
|
|
&& pWindow->canBeGroupedInto(OPENINGON->pWindow) && !m_vOverrideFocalPoint) { // we are not moving window
|
2023-09-14 13:27:16 +02:00
|
|
|
m_lDwindleNodesData.remove(*PNODE);
|
2023-07-03 12:49:56 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto USECURRPOS = CConfigValue<Hyprlang::INT>("group:insert_after_current");
|
|
|
|
(*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow);
|
2023-09-14 13:27:16 +02:00
|
|
|
|
|
|
|
OPENINGON->pWindow->setGroupCurrent(pWindow);
|
2023-09-22 01:42:00 +02:00
|
|
|
pWindow->applyGroupRules();
|
2023-09-14 13:27:16 +02:00
|
|
|
pWindow->updateWindowDecos();
|
|
|
|
recalculateWindow(pWindow);
|
|
|
|
|
2023-11-11 15:37:17 +01:00
|
|
|
if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
|
|
|
|
pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));
|
|
|
|
|
2023-09-14 13:27:16 +02:00
|
|
|
return;
|
2022-08-11 19:29:39 +02:00
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-03-20 18:31:58 +01:00
|
|
|
// If it's not, get the node under our cursor
|
2022-03-19 15:59:53 +01:00
|
|
|
|
|
|
|
m_lDwindleNodesData.push_back(SDwindleNodeData());
|
|
|
|
const auto NEWPARENT = &m_lDwindleNodesData.back();
|
|
|
|
|
|
|
|
// make the parent have the OPENINGON's stats
|
2023-11-04 22:45:34 +01:00
|
|
|
NEWPARENT->box = OPENINGON->box;
|
2022-03-20 16:06:17 +01:00
|
|
|
NEWPARENT->workspaceID = OPENINGON->workspaceID;
|
2022-12-16 18:17:31 +01:00
|
|
|
NEWPARENT->pParent = OPENINGON->pParent;
|
|
|
|
NEWPARENT->isNode = true; // it is a node
|
2024-03-03 19:39:20 +01:00
|
|
|
NEWPARENT->splitRatio = std::clamp(*PDEFAULTSPLIT, 0.1f, 1.9f);
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PWIDTHMULTIPLIER = CConfigValue<Hyprlang::FLOAT>("dwindle:split_width_multiplier");
|
2022-06-20 18:11:59 +02:00
|
|
|
|
2022-04-13 16:24:31 +02:00
|
|
|
// if cursor over first child, make it first, etc
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto SIDEBYSIDE = NEWPARENT->box.w > NEWPARENT->box.h * *PWIDTHMULTIPLIER;
|
2022-12-16 18:17:31 +01:00
|
|
|
NEWPARENT->splitTop = !SIDEBYSIDE;
|
2022-06-20 18:11:59 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PFORCESPLIT = CConfigValue<Hyprlang::INT>("dwindle:force_split");
|
|
|
|
static auto PERMANENTDIRECTIONOVERRIDE = CConfigValue<Hyprlang::INT>("dwindle:permanent_direction_override");
|
|
|
|
static auto PSMARTSPLIT = CConfigValue<Hyprlang::INT>("dwindle:smart_split");
|
2023-05-06 02:02:18 +02:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
bool horizontalOverride = false;
|
|
|
|
bool verticalOverride = false;
|
2023-05-06 02:02:18 +02:00
|
|
|
|
|
|
|
// let user select position -> top, right, bottom, left
|
2023-09-13 12:13:29 +02:00
|
|
|
if (overrideDirection != DIRECTION_DEFAULT) {
|
2023-05-06 02:02:18 +02:00
|
|
|
|
|
|
|
// this is horizontal
|
|
|
|
if (overrideDirection % 2 == 0)
|
|
|
|
verticalOverride = true;
|
|
|
|
else
|
|
|
|
horizontalOverride = true;
|
|
|
|
|
|
|
|
// 0 -> top and left | 1,2 -> right and bottom
|
|
|
|
if (overrideDirection % 3 == 0) {
|
|
|
|
NEWPARENT->children[1] = OPENINGON;
|
|
|
|
NEWPARENT->children[0] = PNODE;
|
|
|
|
} else {
|
|
|
|
NEWPARENT->children[0] = OPENINGON;
|
|
|
|
NEWPARENT->children[1] = PNODE;
|
|
|
|
}
|
2022-04-13 16:24:31 +02:00
|
|
|
|
2023-05-06 02:02:18 +02:00
|
|
|
// whether or not the override persists after opening one window
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PERMANENTDIRECTIONOVERRIDE == 0)
|
2023-09-13 12:13:29 +02:00
|
|
|
overrideDirection = DIRECTION_DEFAULT;
|
2024-03-03 19:39:20 +01:00
|
|
|
} else if (*PSMARTSPLIT == 1) {
|
2024-01-26 23:30:36 +01:00
|
|
|
const auto PARENT_CENTER = NEWPARENT->box.pos() + NEWPARENT->box.size() / 2;
|
|
|
|
const auto PARENT_PROPORTIONS = NEWPARENT->box.h / NEWPARENT->box.w;
|
|
|
|
const auto DELTA = MOUSECOORDS - PARENT_CENTER;
|
|
|
|
const auto DELTA_SLOPE = DELTA.y / DELTA.x;
|
|
|
|
|
|
|
|
if (abs(DELTA_SLOPE) < PARENT_PROPORTIONS) {
|
|
|
|
if (DELTA.x > 0) {
|
|
|
|
// right
|
|
|
|
NEWPARENT->splitTop = false;
|
|
|
|
NEWPARENT->children[0] = OPENINGON;
|
|
|
|
NEWPARENT->children[1] = PNODE;
|
|
|
|
} else {
|
|
|
|
// left
|
|
|
|
NEWPARENT->splitTop = false;
|
|
|
|
NEWPARENT->children[0] = PNODE;
|
|
|
|
NEWPARENT->children[1] = OPENINGON;
|
|
|
|
}
|
2023-07-11 13:37:25 +02:00
|
|
|
} else {
|
2024-01-26 23:30:36 +01:00
|
|
|
if (DELTA.y > 0) {
|
|
|
|
// bottom
|
|
|
|
NEWPARENT->splitTop = true;
|
|
|
|
NEWPARENT->children[0] = OPENINGON;
|
|
|
|
NEWPARENT->children[1] = PNODE;
|
|
|
|
} else {
|
|
|
|
// top
|
|
|
|
NEWPARENT->splitTop = true;
|
|
|
|
NEWPARENT->children[0] = PNODE;
|
|
|
|
NEWPARENT->children[1] = OPENINGON;
|
|
|
|
}
|
2023-07-11 13:37:25 +02:00
|
|
|
}
|
2024-03-03 19:39:20 +01:00
|
|
|
} else if (*PFORCESPLIT == 0 || !pWindow->m_bFirstMap) {
|
2022-12-16 18:17:31 +01:00
|
|
|
if ((SIDEBYSIDE &&
|
2024-03-03 19:39:20 +01:00
|
|
|
VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y + NEWPARENT->box.h)) ||
|
2022-12-16 18:17:31 +01:00
|
|
|
(!SIDEBYSIDE &&
|
2024-03-03 19:39:20 +01:00
|
|
|
VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w, NEWPARENT->box.y + NEWPARENT->box.h / 2.f))) {
|
2022-05-08 15:36:17 +02:00
|
|
|
// we are hovering over the first node, make PNODE first.
|
|
|
|
NEWPARENT->children[1] = OPENINGON;
|
|
|
|
NEWPARENT->children[0] = PNODE;
|
|
|
|
} else {
|
|
|
|
// we are hovering over the second node, make PNODE second.
|
|
|
|
NEWPARENT->children[0] = OPENINGON;
|
|
|
|
NEWPARENT->children[1] = PNODE;
|
|
|
|
}
|
2022-04-13 16:24:31 +02:00
|
|
|
} else {
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PFORCESPLIT == 1) {
|
2022-05-08 15:36:17 +02:00
|
|
|
NEWPARENT->children[1] = OPENINGON;
|
|
|
|
NEWPARENT->children[0] = PNODE;
|
|
|
|
} else {
|
|
|
|
NEWPARENT->children[0] = OPENINGON;
|
|
|
|
NEWPARENT->children[1] = PNODE;
|
|
|
|
}
|
2022-04-13 16:24:31 +02:00
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
// and update the previous parent if it exists
|
|
|
|
if (OPENINGON->pParent) {
|
|
|
|
if (OPENINGON->pParent->children[0] == OPENINGON) {
|
2022-03-19 20:30:21 +01:00
|
|
|
OPENINGON->pParent->children[0] = NEWPARENT;
|
2022-03-19 15:59:53 +01:00
|
|
|
} else {
|
2022-03-19 20:30:21 +01:00
|
|
|
OPENINGON->pParent->children[1] = NEWPARENT;
|
2022-03-19 15:59:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the children
|
2024-03-03 19:39:20 +01:00
|
|
|
if (!verticalOverride && (NEWPARENT->box.w * *PWIDTHMULTIPLIER > NEWPARENT->box.h || horizontalOverride)) {
|
2023-05-06 02:02:18 +02:00
|
|
|
// split left/right -> forced
|
2023-11-04 22:45:34 +01:00
|
|
|
OPENINGON->box = {NEWPARENT->box.pos(), Vector2D(NEWPARENT->box.w / 2.f, NEWPARENT->box.h)};
|
|
|
|
PNODE->box = {Vector2D(NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y), Vector2D(NEWPARENT->box.w / 2.f, NEWPARENT->box.h)};
|
2022-03-19 15:59:53 +01:00
|
|
|
} else {
|
2022-06-20 18:11:59 +02:00
|
|
|
// split top/bottom
|
2023-11-04 22:45:34 +01:00
|
|
|
OPENINGON->box = {NEWPARENT->box.pos(), Vector2D(NEWPARENT->box.w, NEWPARENT->box.h / 2.f)};
|
|
|
|
PNODE->box = {Vector2D(NEWPARENT->box.x, NEWPARENT->box.y + NEWPARENT->box.h / 2.f), Vector2D(NEWPARENT->box.w, NEWPARENT->box.h / 2.f)};
|
2022-03-19 15:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OPENINGON->pParent = NEWPARENT;
|
2022-12-16 18:17:31 +01:00
|
|
|
PNODE->pParent = NEWPARENT;
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2023-05-06 02:02:18 +02:00
|
|
|
NEWPARENT->recalcSizePosRecursive(false, horizontalOverride, verticalOverride);
|
2022-03-21 19:28:43 +01:00
|
|
|
|
2023-09-28 18:49:33 +02:00
|
|
|
recalculateMonitor(pWindow->m_iMonitorID);
|
|
|
|
|
2023-09-22 01:42:00 +02:00
|
|
|
pWindow->applyGroupRules();
|
2022-03-19 15:59:53 +01:00
|
|
|
}
|
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
void CHyprDwindleLayout::onWindowRemovedTiling(CWindow* pWindow) {
|
2022-03-19 15:59:53 +01:00
|
|
|
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
2022-08-20 17:59:15 +02:00
|
|
|
if (!PNODE) {
|
|
|
|
Debug::log(ERR, "onWindowRemovedTiling node null?");
|
2022-03-19 15:59:53 +01:00
|
|
|
return;
|
2022-08-20 17:59:15 +02:00
|
|
|
}
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2023-08-17 10:13:19 +02:00
|
|
|
pWindow->updateSpecialRenderData();
|
2022-11-26 19:48:16 +01:00
|
|
|
|
2022-09-20 10:55:25 +02:00
|
|
|
if (pWindow->m_bIsFullscreen)
|
|
|
|
g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL);
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
const auto PPARENT = PNODE->pParent;
|
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
if (!PPARENT) {
|
2022-08-20 17:59:15 +02:00
|
|
|
Debug::log(LOG, "Removing last node (dwindle)");
|
2022-03-19 15:59:53 +01:00
|
|
|
m_lDwindleNodesData.remove(*PNODE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto PSIBLING = PPARENT->children[0] == PNODE ? PPARENT->children[1] : PPARENT->children[0];
|
|
|
|
|
2023-11-04 22:45:34 +01:00
|
|
|
PSIBLING->box = PPARENT->box;
|
|
|
|
PSIBLING->pParent = PPARENT->pParent;
|
2022-03-19 15:59:53 +01:00
|
|
|
|
|
|
|
if (PPARENT->pParent != nullptr) {
|
|
|
|
if (PPARENT->pParent->children[0] == PPARENT) {
|
|
|
|
PPARENT->pParent->children[0] = PSIBLING;
|
|
|
|
} else {
|
|
|
|
PPARENT->pParent->children[1] = PSIBLING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-01 12:51:52 +02:00
|
|
|
PPARENT->valid = false;
|
2022-12-16 18:17:31 +01:00
|
|
|
PNODE->valid = false;
|
2022-08-01 12:51:52 +02:00
|
|
|
|
2022-04-12 19:18:26 +02:00
|
|
|
if (PSIBLING->pParent)
|
|
|
|
PSIBLING->pParent->recalcSizePosRecursive();
|
2022-09-25 20:07:48 +02:00
|
|
|
else
|
2022-04-12 19:18:26 +02:00
|
|
|
PSIBLING->recalcSizePosRecursive();
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
m_lDwindleNodesData.remove(*PPARENT);
|
|
|
|
m_lDwindleNodesData.remove(*PNODE);
|
2022-03-19 20:30:21 +01:00
|
|
|
}
|
2022-03-19 20:56:19 +01:00
|
|
|
|
|
|
|
void CHyprDwindleLayout::recalculateMonitor(const int& monid) {
|
2022-03-19 20:59:22 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(monid);
|
2022-08-16 21:30:53 +02:00
|
|
|
|
|
|
|
if (!PMONITOR)
|
|
|
|
return; // ???
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
|
|
|
|
|
2022-05-31 14:01:00 +02:00
|
|
|
if (!PWORKSPACE)
|
|
|
|
return;
|
|
|
|
|
2022-07-11 15:40:41 +02:00
|
|
|
g_pHyprRenderer->damageMonitor(PMONITOR);
|
|
|
|
|
2022-11-27 23:42:22 +01:00
|
|
|
if (PMONITOR->specialWorkspaceID) {
|
2024-03-07 14:27:58 +01:00
|
|
|
const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID);
|
|
|
|
|
|
|
|
if (PSPECIALWS->m_bHasFullscreenWindow) {
|
|
|
|
const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PSPECIALWS->m_iID);
|
|
|
|
|
|
|
|
if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_FULL) {
|
|
|
|
PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition;
|
|
|
|
PFULLWINDOW->m_vRealSize = PMONITOR->vecSize;
|
|
|
|
} else if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) {
|
|
|
|
SDwindleNodeData fakeNode;
|
|
|
|
fakeNode.pWindow = PFULLWINDOW;
|
|
|
|
fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight};
|
|
|
|
fakeNode.workspaceID = PSPECIALWS->m_iID;
|
|
|
|
PFULLWINDOW->m_vPosition = fakeNode.box.pos();
|
|
|
|
PFULLWINDOW->m_vSize = fakeNode.box.size();
|
|
|
|
fakeNode.ignoreFullscreenChecks = true;
|
|
|
|
|
|
|
|
applyNodeDataToWindow(&fakeNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-27 23:42:22 +01:00
|
|
|
const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->specialWorkspaceID);
|
2022-05-31 14:01:00 +02:00
|
|
|
|
|
|
|
if (TOPNODE && PMONITOR) {
|
2023-11-04 22:45:34 +01:00
|
|
|
TOPNODE->box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight};
|
2022-05-31 14:01:00 +02:00
|
|
|
TOPNODE->recalcSizePosRecursive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 15:40:41 +02:00
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
|
|
|
// massive hack from the fullscreen func
|
|
|
|
const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID);
|
|
|
|
|
2023-03-20 17:07:18 +01:00
|
|
|
if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) {
|
|
|
|
PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition;
|
|
|
|
PFULLWINDOW->m_vRealSize = PMONITOR->vecSize;
|
|
|
|
} else if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) {
|
2022-08-16 21:32:12 +02:00
|
|
|
SDwindleNodeData fakeNode;
|
2023-11-04 22:45:34 +01:00
|
|
|
fakeNode.pWindow = PFULLWINDOW;
|
|
|
|
fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight};
|
|
|
|
fakeNode.workspaceID = PWORKSPACE->m_iID;
|
|
|
|
PFULLWINDOW->m_vPosition = fakeNode.box.pos();
|
|
|
|
PFULLWINDOW->m_vSize = fakeNode.box.size();
|
2023-11-03 13:19:23 +01:00
|
|
|
fakeNode.ignoreFullscreenChecks = true;
|
|
|
|
|
|
|
|
applyNodeDataToWindow(&fakeNode);
|
2022-08-16 21:32:12 +02:00
|
|
|
}
|
2023-03-20 17:07:18 +01:00
|
|
|
|
|
|
|
return;
|
2022-07-11 15:40:41 +02:00
|
|
|
}
|
2022-03-21 19:18:33 +01:00
|
|
|
|
2022-03-20 16:06:17 +01:00
|
|
|
const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->activeWorkspace);
|
2022-03-19 20:56:19 +01:00
|
|
|
|
2022-03-19 20:59:22 +01:00
|
|
|
if (TOPNODE && PMONITOR) {
|
2023-11-04 22:45:34 +01:00
|
|
|
TOPNODE->box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight};
|
2022-03-19 20:56:19 +01:00
|
|
|
TOPNODE->recalcSizePosRecursive();
|
2022-03-19 20:59:22 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-20 11:14:24 +01:00
|
|
|
|
2022-06-30 12:09:05 +02:00
|
|
|
bool CHyprDwindleLayout::isWindowTiled(CWindow* pWindow) {
|
|
|
|
return getNodeFromWindow(pWindow) != nullptr;
|
2022-03-20 13:37:07 +01:00
|
|
|
}
|
|
|
|
|
2023-04-25 17:53:18 +02:00
|
|
|
void CHyprDwindleLayout::onBeginDragWindow() {
|
|
|
|
m_PseudoDragFlags.started = false;
|
|
|
|
m_PseudoDragFlags.pseudo = false;
|
|
|
|
IHyprLayout::onBeginDragWindow();
|
|
|
|
}
|
|
|
|
|
2023-07-13 16:52:11 +02:00
|
|
|
void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorner corner, CWindow* pWindow) {
|
2022-06-06 19:32:14 +02:00
|
|
|
|
|
|
|
const auto PWINDOW = pWindow ? pWindow : g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto PNODE = getNodeFromWindow(PWINDOW);
|
|
|
|
|
|
|
|
if (!PNODE) {
|
2024-03-02 01:35:17 +01:00
|
|
|
PWINDOW->m_vRealSize = Vector2D(std::max((PWINDOW->m_vRealSize.goal() + pixResize).x, 20.0), std::max((PWINDOW->m_vRealSize.goal() + pixResize).y, 20.0));
|
2022-06-27 00:25:37 +02:00
|
|
|
PWINDOW->updateWindowDecos();
|
2022-06-06 19:32:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PANIMATE = CConfigValue<Hyprlang::INT>("misc:animate_manual_resizes");
|
|
|
|
static auto PSMARTRESIZING = CConfigValue<Hyprlang::INT>("dwindle:smart_resizing");
|
2022-08-16 21:56:54 +02:00
|
|
|
|
2022-06-06 19:32:14 +02:00
|
|
|
// get some data about our window
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
|
|
|
|
const bool DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
|
|
|
|
const bool DISPLAYRIGHT = STICKS(PWINDOW->m_vPosition.x + PWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
|
|
|
|
const bool DISPLAYTOP = STICKS(PWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
|
2022-06-06 19:32:14 +02:00
|
|
|
const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
|
|
|
|
|
2023-04-25 17:53:18 +02:00
|
|
|
if (PWINDOW->m_bIsPseudotiled) {
|
|
|
|
if (!m_PseudoDragFlags.started) {
|
|
|
|
m_PseudoDragFlags.started = true;
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
const auto pseudoSize = PWINDOW->m_vRealSize.goal();
|
2023-11-04 22:45:34 +01:00
|
|
|
const auto mouseOffset = g_pInputManager->getMouseCoordsInternal() - (PNODE->box.pos() + ((PNODE->box.size() / 2) - (pseudoSize / 2)));
|
2023-04-25 17:53:18 +02:00
|
|
|
|
|
|
|
if (mouseOffset.x > 0 && mouseOffset.x < pseudoSize.x && mouseOffset.y > 0 && mouseOffset.y < pseudoSize.y) {
|
|
|
|
m_PseudoDragFlags.pseudo = true;
|
|
|
|
m_PseudoDragFlags.xExtent = mouseOffset.x > pseudoSize.x / 2;
|
|
|
|
m_PseudoDragFlags.yExtent = mouseOffset.y > pseudoSize.y / 2;
|
|
|
|
|
|
|
|
PWINDOW->m_vPseudoSize = pseudoSize;
|
|
|
|
} else {
|
|
|
|
m_PseudoDragFlags.pseudo = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_PseudoDragFlags.pseudo) {
|
|
|
|
if (m_PseudoDragFlags.xExtent)
|
|
|
|
PWINDOW->m_vPseudoSize.x += pixResize.x * 2;
|
|
|
|
else
|
|
|
|
PWINDOW->m_vPseudoSize.x -= pixResize.x * 2;
|
|
|
|
if (m_PseudoDragFlags.yExtent)
|
|
|
|
PWINDOW->m_vPseudoSize.y += pixResize.y * 2;
|
|
|
|
else
|
|
|
|
PWINDOW->m_vPseudoSize.y -= pixResize.y * 2;
|
|
|
|
|
2024-02-14 12:28:43 +01:00
|
|
|
CBox wbox = PNODE->box;
|
|
|
|
wbox.round();
|
|
|
|
|
|
|
|
PWINDOW->m_vPseudoSize = {std::clamp(PWINDOW->m_vPseudoSize.x, 30.0, wbox.w), std::clamp(PWINDOW->m_vPseudoSize.y, 30.0, wbox.h)};
|
2023-04-25 17:53:18 +02:00
|
|
|
|
|
|
|
PWINDOW->m_vLastFloatingSize = PWINDOW->m_vPseudoSize;
|
2024-03-03 19:39:20 +01:00
|
|
|
PNODE->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-04-25 17:53:18 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:32:14 +02:00
|
|
|
// construct allowed movement
|
2022-12-31 16:23:56 +01:00
|
|
|
Vector2D allowedMovement = pixResize;
|
2022-06-06 19:32:14 +02:00
|
|
|
if (DISPLAYLEFT && DISPLAYRIGHT)
|
|
|
|
allowedMovement.x = 0;
|
|
|
|
|
|
|
|
if (DISPLAYBOTTOM && DISPLAYTOP)
|
|
|
|
allowedMovement.y = 0;
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
if (*PSMARTRESIZING == 1) {
|
2023-07-23 15:50:09 +02:00
|
|
|
// Identify inner and outer nodes for both directions
|
|
|
|
SDwindleNodeData* PVOUTER = nullptr;
|
|
|
|
SDwindleNodeData* PVINNER = nullptr;
|
|
|
|
SDwindleNodeData* PHOUTER = nullptr;
|
|
|
|
SDwindleNodeData* PHINNER = nullptr;
|
|
|
|
|
2023-08-21 20:57:55 +02:00
|
|
|
const auto LEFT = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT || DISPLAYRIGHT;
|
|
|
|
const auto TOP = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT || DISPLAYBOTTOM;
|
|
|
|
const auto RIGHT = corner == CORNER_TOPRIGHT || corner == CORNER_BOTTOMRIGHT || DISPLAYLEFT;
|
|
|
|
const auto BOTTOM = corner == CORNER_BOTTOMLEFT || corner == CORNER_BOTTOMRIGHT || DISPLAYTOP;
|
2023-07-23 15:50:09 +02:00
|
|
|
const auto NONE = corner == CORNER_NONE;
|
|
|
|
|
|
|
|
for (auto PCURRENT = PNODE; PCURRENT && PCURRENT->pParent; PCURRENT = PCURRENT->pParent) {
|
|
|
|
const auto PPARENT = PCURRENT->pParent;
|
|
|
|
|
|
|
|
if (!PVOUTER && PPARENT->splitTop && (NONE || (TOP && PPARENT->children[1] == PCURRENT) || (BOTTOM && PPARENT->children[0] == PCURRENT)))
|
|
|
|
PVOUTER = PCURRENT;
|
|
|
|
else if (!PVOUTER && !PVINNER && PPARENT->splitTop)
|
|
|
|
PVINNER = PCURRENT;
|
|
|
|
else if (!PHOUTER && !PPARENT->splitTop && (NONE || (LEFT && PPARENT->children[1] == PCURRENT) || (RIGHT && PPARENT->children[0] == PCURRENT)))
|
|
|
|
PHOUTER = PCURRENT;
|
|
|
|
else if (!PHOUTER && !PHINNER && !PPARENT->splitTop)
|
|
|
|
PHINNER = PCURRENT;
|
|
|
|
|
|
|
|
if (PVOUTER && PHOUTER)
|
|
|
|
break;
|
|
|
|
}
|
2022-06-06 19:32:14 +02:00
|
|
|
|
2023-07-23 15:50:09 +02:00
|
|
|
if (PHOUTER) {
|
2023-11-04 22:45:34 +01:00
|
|
|
PHOUTER->pParent->splitRatio = std::clamp(PHOUTER->pParent->splitRatio + allowedMovement.x * 2.f / PHOUTER->pParent->box.w, 0.1, 1.9);
|
2023-07-23 15:50:09 +02:00
|
|
|
|
|
|
|
if (PHINNER) {
|
2023-11-04 22:45:34 +01:00
|
|
|
const auto ORIGINAL = PHINNER->box.w;
|
2024-03-03 19:39:20 +01:00
|
|
|
PHOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
if (PHINNER->pParent->children[0] == PHINNER)
|
2023-11-04 22:45:34 +01:00
|
|
|
PHINNER->pParent->splitRatio = std::clamp((ORIGINAL - allowedMovement.x) / PHINNER->pParent->box.w * 2.f, 0.1, 1.9);
|
2023-07-23 15:50:09 +02:00
|
|
|
else
|
2023-11-04 22:45:34 +01:00
|
|
|
PHINNER->pParent->splitRatio = std::clamp(2 - (ORIGINAL + allowedMovement.x) / PHINNER->pParent->box.w * 2.f, 0.1, 1.9);
|
2024-03-03 19:39:20 +01:00
|
|
|
PHINNER->pParent->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
} else
|
2024-03-03 19:39:20 +01:00
|
|
|
PHOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
}
|
2022-06-06 19:32:14 +02:00
|
|
|
|
2023-07-23 15:50:09 +02:00
|
|
|
if (PVOUTER) {
|
2023-11-04 22:45:34 +01:00
|
|
|
PVOUTER->pParent->splitRatio = std::clamp(PVOUTER->pParent->splitRatio + allowedMovement.y * 2.f / PVOUTER->pParent->box.h, 0.1, 1.9);
|
2023-07-23 15:50:09 +02:00
|
|
|
|
|
|
|
if (PVINNER) {
|
2023-11-04 22:45:34 +01:00
|
|
|
const auto ORIGINAL = PVINNER->box.h;
|
2024-03-03 19:39:20 +01:00
|
|
|
PVOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
if (PVINNER->pParent->children[0] == PVINNER)
|
2023-11-04 22:45:34 +01:00
|
|
|
PVINNER->pParent->splitRatio = std::clamp((ORIGINAL - allowedMovement.y) / PVINNER->pParent->box.h * 2.f, 0.1, 1.9);
|
2023-07-23 15:50:09 +02:00
|
|
|
else
|
2023-11-04 22:45:34 +01:00
|
|
|
PVINNER->pParent->splitRatio = std::clamp(2 - (ORIGINAL + allowedMovement.y) / PVINNER->pParent->box.h * 2.f, 0.1, 1.9);
|
2024-03-03 19:39:20 +01:00
|
|
|
PVINNER->pParent->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
} else
|
2024-03-03 19:39:20 +01:00
|
|
|
PVOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// get the correct containers to apply splitratio to
|
|
|
|
const auto PPARENT = PNODE->pParent;
|
2022-06-06 19:32:14 +02:00
|
|
|
|
2023-07-23 15:50:09 +02:00
|
|
|
if (!PPARENT)
|
|
|
|
return; // the only window on a workspace, ignore
|
2022-06-06 19:32:14 +02:00
|
|
|
|
2023-07-23 15:50:09 +02:00
|
|
|
const bool PARENTSIDEBYSIDE = !PPARENT->splitTop;
|
|
|
|
|
|
|
|
// Get the parent's parent
|
|
|
|
auto PPARENT2 = PPARENT->pParent;
|
|
|
|
|
|
|
|
// No parent means we have only 2 windows, and thus one axis of freedom
|
|
|
|
if (!PPARENT2) {
|
|
|
|
if (PARENTSIDEBYSIDE) {
|
2023-11-04 22:45:34 +01:00
|
|
|
allowedMovement.x *= 2.f / PPARENT->box.w;
|
2023-07-23 15:50:09 +02:00
|
|
|
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, 0.1, 1.9);
|
2024-03-03 19:39:20 +01:00
|
|
|
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
} else {
|
2023-11-04 22:45:34 +01:00
|
|
|
allowedMovement.y *= 2.f / PPARENT->box.h;
|
2023-07-23 15:50:09 +02:00
|
|
|
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, 0.1, 1.9);
|
2024-03-03 19:39:20 +01:00
|
|
|
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get first parent with other split
|
|
|
|
while (PPARENT2 && PPARENT2->splitTop == !PARENTSIDEBYSIDE)
|
|
|
|
PPARENT2 = PPARENT2->pParent;
|
|
|
|
|
|
|
|
// no parent, one axis of freedom
|
|
|
|
if (!PPARENT2) {
|
|
|
|
if (PARENTSIDEBYSIDE) {
|
2023-11-04 22:45:34 +01:00
|
|
|
allowedMovement.x *= 2.f / PPARENT->box.w;
|
2023-07-23 15:50:09 +02:00
|
|
|
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, 0.1, 1.9);
|
2024-03-03 19:39:20 +01:00
|
|
|
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
} else {
|
2023-11-04 22:45:34 +01:00
|
|
|
allowedMovement.y *= 2.f / PPARENT->box.h;
|
2023-07-23 15:50:09 +02:00
|
|
|
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, 0.1, 1.9);
|
2024-03-03 19:39:20 +01:00
|
|
|
PPARENT->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-23 15:50:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2 axes of freedom
|
|
|
|
const auto SIDECONTAINER = PARENTSIDEBYSIDE ? PPARENT : PPARENT2;
|
|
|
|
const auto TOPCONTAINER = PARENTSIDEBYSIDE ? PPARENT2 : PPARENT;
|
|
|
|
|
2023-11-04 22:45:34 +01:00
|
|
|
allowedMovement.x *= 2.f / SIDECONTAINER->box.w;
|
|
|
|
allowedMovement.y *= 2.f / TOPCONTAINER->box.h;
|
2023-07-23 15:50:09 +02:00
|
|
|
|
|
|
|
SIDECONTAINER->splitRatio = std::clamp(SIDECONTAINER->splitRatio + allowedMovement.x, 0.1, 1.9);
|
|
|
|
TOPCONTAINER->splitRatio = std::clamp(TOPCONTAINER->splitRatio + allowedMovement.y, 0.1, 1.9);
|
2024-03-03 19:39:20 +01:00
|
|
|
SIDECONTAINER->recalcSizePosRecursive(*PANIMATE == 0);
|
|
|
|
TOPCONTAINER->recalcSizePosRecursive(*PANIMATE == 0);
|
2023-07-13 16:52:11 +02:00
|
|
|
}
|
2022-06-06 19:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-06-26 12:12:29 +02:00
|
|
|
void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreenMode fullscreenMode, bool on) {
|
2022-03-21 19:18:33 +01:00
|
|
|
if (!g_pCompositor->windowValidMapped(pWindow))
|
|
|
|
return;
|
|
|
|
|
2024-03-05 00:29:45 +01:00
|
|
|
if (on == pWindow->m_bIsFullscreen)
|
2022-06-26 12:12:29 +02:00
|
|
|
return; // ignore
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
2022-03-21 19:18:33 +01:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
|
|
|
|
|
2022-06-26 12:12:29 +02:00
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow && on) {
|
2022-03-21 19:18:33 +01:00
|
|
|
// if the window wants to be fullscreen but there already is one,
|
|
|
|
// ignore the request.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-26 18:24:00 +01:00
|
|
|
// save position and size if floating
|
|
|
|
if (pWindow->m_bIsFloating && on) {
|
2024-03-02 01:35:17 +01:00
|
|
|
pWindow->m_vLastFloatingSize = pWindow->m_vRealSize.goal();
|
|
|
|
pWindow->m_vLastFloatingPosition = pWindow->m_vRealPosition.goal();
|
|
|
|
pWindow->m_vPosition = pWindow->m_vRealPosition.goal();
|
|
|
|
pWindow->m_vSize = pWindow->m_vRealSize.goal();
|
2024-01-26 18:24:00 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
// otherwise, accept it.
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_bIsFullscreen = on;
|
2022-04-11 19:51:37 +02:00
|
|
|
PWORKSPACE->m_bHasFullscreenWindow = !PWORKSPACE->m_bHasFullscreenWindow;
|
2022-03-21 19:18:33 +01:00
|
|
|
|
2024-01-02 14:21:22 +01:00
|
|
|
pWindow->updateDynamicRules();
|
|
|
|
pWindow->updateWindowDecos();
|
|
|
|
|
2022-07-20 18:39:08 +02:00
|
|
|
g_pEventManager->postEvent(SHyprIPCEvent{"fullscreen", std::to_string((int)on)});
|
2023-02-19 21:54:53 +01:00
|
|
|
EMIT_HOOK_EVENT("fullscreen", pWindow);
|
2022-07-11 14:13:15 +02:00
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
if (!pWindow->m_bIsFullscreen) {
|
|
|
|
// if it got its fullscreen disabled, set back its node if it had one
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
if (PNODE)
|
|
|
|
applyNodeDataToWindow(PNODE);
|
|
|
|
else {
|
|
|
|
// get back its' dimensions from position and size
|
2022-12-17 13:14:43 +01:00
|
|
|
pWindow->m_vRealPosition = pWindow->m_vLastFloatingPosition;
|
|
|
|
pWindow->m_vRealSize = pWindow->m_vLastFloatingSize;
|
2023-01-31 13:15:34 +01:00
|
|
|
|
2023-08-17 10:13:19 +02:00
|
|
|
pWindow->updateSpecialRenderData();
|
2022-03-21 19:18:33 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if it now got fullscreen, make it fullscreen
|
|
|
|
|
2022-05-29 15:44:30 +02:00
|
|
|
PWORKSPACE->m_efFullscreenMode = fullscreenMode;
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
// apply new pos and size being monitors' box
|
2022-05-29 15:44:30 +02:00
|
|
|
if (fullscreenMode == FULLSCREEN_FULL) {
|
|
|
|
pWindow->m_vRealPosition = PMONITOR->vecPosition;
|
2022-12-16 18:17:31 +01:00
|
|
|
pWindow->m_vRealSize = PMONITOR->vecSize;
|
2022-05-29 15:44:30 +02:00
|
|
|
} else {
|
|
|
|
// This is a massive hack.
|
|
|
|
// We make a fake "only" node and apply
|
|
|
|
// To keep consistent with the settings without C+P code
|
|
|
|
|
|
|
|
SDwindleNodeData fakeNode;
|
2022-12-16 18:17:31 +01:00
|
|
|
fakeNode.pWindow = pWindow;
|
2023-11-04 22:45:34 +01:00
|
|
|
fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight};
|
2022-05-29 15:44:30 +02:00
|
|
|
fakeNode.workspaceID = pWindow->m_iWorkspaceID;
|
2023-11-04 22:45:34 +01:00
|
|
|
pWindow->m_vPosition = fakeNode.box.pos();
|
|
|
|
pWindow->m_vSize = fakeNode.box.size();
|
2024-03-05 00:29:45 +01:00
|
|
|
fakeNode.ignoreFullscreenChecks = true;
|
2022-05-29 15:44:30 +02:00
|
|
|
|
2024-03-05 00:29:45 +01:00
|
|
|
applyNodeDataToWindow(&fakeNode);
|
2022-05-29 15:44:30 +02:00
|
|
|
}
|
2022-03-21 19:18:33 +01:00
|
|
|
}
|
|
|
|
|
2022-07-15 19:33:09 +02:00
|
|
|
g_pCompositor->updateWindowAnimatedDecorationValues(pWindow);
|
|
|
|
|
2024-03-02 01:35:17 +01:00
|
|
|
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goal());
|
2022-04-24 17:42:59 +02:00
|
|
|
|
2023-09-21 23:18:26 +02:00
|
|
|
g_pCompositor->changeWindowZOrder(pWindow, true);
|
2022-04-04 16:25:30 +02:00
|
|
|
|
2022-07-11 15:40:41 +02:00
|
|
|
recalculateMonitor(PMONITOR->ID);
|
2022-03-22 17:31:19 +01:00
|
|
|
}
|
2022-04-02 20:04:32 +02:00
|
|
|
|
|
|
|
void CHyprDwindleLayout::recalculateWindow(CWindow* pWindow) {
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
|
|
|
if (!PNODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PNODE->recalcSizePosRecursive();
|
2022-04-12 16:44:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-11 19:29:39 +02:00
|
|
|
void addToDequeRecursive(std::deque<SDwindleNodeData*>* pDeque, std::deque<SDwindleNodeData*>* pParents, SDwindleNodeData* node) {
|
|
|
|
if (node->isNode) {
|
|
|
|
pParents->push_back(node);
|
|
|
|
addToDequeRecursive(pDeque, pParents, node->children[0]);
|
|
|
|
addToDequeRecursive(pDeque, pParents, node->children[1]);
|
|
|
|
} else {
|
|
|
|
pDeque->emplace_back(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 16:44:18 +02:00
|
|
|
SWindowRenderLayoutHints CHyprDwindleLayout::requestRenderHints(CWindow* pWindow) {
|
|
|
|
// window should be valid, insallah
|
|
|
|
SWindowRenderLayoutHints hints;
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
2022-04-12 16:44:18 +02:00
|
|
|
if (!PNODE)
|
|
|
|
return hints; // left for the future, maybe floating funkiness
|
|
|
|
|
|
|
|
return hints;
|
2022-04-20 16:18:58 +02:00
|
|
|
}
|
|
|
|
|
2023-09-04 15:34:07 +02:00
|
|
|
void CHyprDwindleLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) {
|
|
|
|
if (!isDirection(dir))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
|
|
|
if (!PNODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vector2D focalPoint;
|
|
|
|
|
|
|
|
switch (dir[0]) {
|
|
|
|
case 't':
|
|
|
|
case 'u': focalPoint = pWindow->m_vPosition + Vector2D{pWindow->m_vSize.x / 2.f, -1}; break;
|
|
|
|
case 'd':
|
|
|
|
case 'b': focalPoint = pWindow->m_vPosition + Vector2D{pWindow->m_vSize.x / 2.f, pWindow->m_vSize.y + 1}; break;
|
|
|
|
case 'l': focalPoint = pWindow->m_vPosition + Vector2D{-1, pWindow->m_vSize.y / 2.f}; break;
|
|
|
|
case 'r': focalPoint = pWindow->m_vPosition + Vector2D{pWindow->m_vSize.x + 1, pWindow->m_vSize.y / 2.f}; break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
onWindowRemovedTiling(pWindow);
|
|
|
|
|
|
|
|
m_vOverrideFocalPoint = focalPoint;
|
|
|
|
|
|
|
|
const auto PMONITORFOCAL = g_pCompositor->getMonitorFromVector(focalPoint);
|
|
|
|
|
2023-09-14 16:37:41 +02:00
|
|
|
if (PMONITORFOCAL->ID != pWindow->m_iMonitorID) {
|
|
|
|
pWindow->moveToWorkspace(PMONITORFOCAL->activeWorkspace);
|
|
|
|
pWindow->m_iMonitorID = PMONITORFOCAL->ID;
|
|
|
|
}
|
2023-09-04 15:34:07 +02:00
|
|
|
|
|
|
|
onWindowCreatedTiling(pWindow);
|
|
|
|
|
|
|
|
m_vOverrideFocalPoint.reset();
|
|
|
|
}
|
|
|
|
|
2022-04-20 16:18:58 +02:00
|
|
|
void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) {
|
|
|
|
// windows should be valid, insallah
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
auto PNODE = getNodeFromWindow(pWindow);
|
2022-09-20 19:04:39 +02:00
|
|
|
auto PNODE2 = getNodeFromWindow(pWindow2);
|
2022-04-20 16:18:58 +02:00
|
|
|
|
2022-09-20 19:04:39 +02:00
|
|
|
if (!PNODE2 || !PNODE) {
|
2022-12-16 18:17:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-04-20 16:18:58 +02:00
|
|
|
|
2022-09-20 19:04:39 +02:00
|
|
|
SDwindleNodeData* ACTIVE1 = nullptr;
|
2022-12-16 18:17:31 +01:00
|
|
|
SDwindleNodeData* ACTIVE2 = nullptr;
|
2022-06-23 20:51:01 +02:00
|
|
|
|
2023-02-19 22:07:32 +01:00
|
|
|
// swap the windows and recalc
|
|
|
|
PNODE2->pWindow = pWindow;
|
|
|
|
PNODE->pWindow = pWindow2;
|
2022-12-16 18:17:31 +01:00
|
|
|
|
|
|
|
if (PNODE->workspaceID != PNODE2->workspaceID) {
|
|
|
|
std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID);
|
|
|
|
std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// recalc the workspace
|
2022-04-20 16:18:58 +02:00
|
|
|
getMasterNodeOnWorkspace(PNODE->workspaceID)->recalcSizePosRecursive();
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-09-20 19:04:39 +02:00
|
|
|
if (PNODE2->workspaceID != PNODE->workspaceID) {
|
2022-09-14 17:30:16 +02:00
|
|
|
getMasterNodeOnWorkspace(PNODE2->workspaceID)->recalcSizePosRecursive();
|
2022-09-20 19:04:39 +02:00
|
|
|
}
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
if (ACTIVE1) {
|
2023-11-04 22:45:34 +01:00
|
|
|
ACTIVE1->box = PNODE->box;
|
|
|
|
ACTIVE1->pWindow->m_vPosition = ACTIVE1->box.pos();
|
|
|
|
ACTIVE1->pWindow->m_vSize = ACTIVE1->box.size();
|
2022-12-16 18:17:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ACTIVE2) {
|
2023-11-04 22:45:34 +01:00
|
|
|
ACTIVE2->box = PNODE2->box;
|
|
|
|
ACTIVE2->pWindow->m_vPosition = ACTIVE2->box.pos();
|
|
|
|
ACTIVE2->pWindow->m_vSize = ACTIVE2->box.size();
|
2022-12-16 18:17:31 +01:00
|
|
|
}
|
2022-11-25 20:52:23 +01:00
|
|
|
|
|
|
|
g_pHyprRenderer->damageWindow(pWindow);
|
|
|
|
g_pHyprRenderer->damageWindow(pWindow2);
|
2022-04-20 16:53:41 +02:00
|
|
|
}
|
|
|
|
|
2022-12-17 23:37:44 +01:00
|
|
|
void CHyprDwindleLayout::alterSplitRatio(CWindow* pWindow, float ratio, bool exact) {
|
2022-04-20 16:53:41 +02:00
|
|
|
// window should be valid, insallah
|
|
|
|
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
2023-02-19 22:07:32 +01:00
|
|
|
if (!PNODE || !PNODE->pParent)
|
2022-04-20 16:53:41 +02:00
|
|
|
return;
|
|
|
|
|
2022-12-31 16:23:56 +01:00
|
|
|
float newRatio = exact ? ratio : PNODE->pParent->splitRatio + ratio;
|
2022-12-17 23:37:44 +01:00
|
|
|
PNODE->pParent->splitRatio = std::clamp(newRatio, 0.1f, 1.9f);
|
2022-04-20 16:53:41 +02:00
|
|
|
|
2022-05-16 17:37:46 +02:00
|
|
|
PNODE->pParent->recalcSizePosRecursive();
|
|
|
|
}
|
|
|
|
|
2022-05-28 20:46:20 +02:00
|
|
|
std::any CHyprDwindleLayout::layoutMessage(SLayoutMessageHeader header, std::string message) {
|
2023-05-06 02:02:18 +02:00
|
|
|
const auto ARGS = CVarList(message, 0, ' ');
|
|
|
|
if (ARGS[0] == "togglesplit") {
|
2022-05-16 17:37:46 +02:00
|
|
|
toggleSplit(header.pWindow);
|
2024-02-14 18:58:28 +01:00
|
|
|
} else if (ARGS[0] == "swapsplit") {
|
|
|
|
swapSplit(header.pWindow);
|
2023-05-06 02:02:18 +02:00
|
|
|
} else if (ARGS[0] == "preselect") {
|
|
|
|
std::string direction = ARGS[1];
|
|
|
|
|
|
|
|
if (direction.empty()) {
|
|
|
|
Debug::log(ERR, "Expected direction for preselect");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (direction.front()) {
|
|
|
|
case 'u':
|
|
|
|
case 't': {
|
2023-09-13 12:13:29 +02:00
|
|
|
overrideDirection = DIRECTION_UP;
|
2023-05-06 02:02:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'd':
|
|
|
|
case 'b': {
|
2023-09-13 12:13:29 +02:00
|
|
|
overrideDirection = DIRECTION_DOWN;
|
2023-05-06 02:02:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'r': {
|
2023-09-13 12:13:29 +02:00
|
|
|
overrideDirection = DIRECTION_RIGHT;
|
2023-05-06 02:02:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'l': {
|
2023-09-13 12:13:29 +02:00
|
|
|
overrideDirection = DIRECTION_LEFT;
|
2023-05-06 02:02:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// any other character resets the focus direction
|
|
|
|
// needed for the persistent mode
|
2023-09-13 12:13:29 +02:00
|
|
|
overrideDirection = DIRECTION_DEFAULT;
|
2023-05-06 02:02:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-05-28 20:46:20 +02:00
|
|
|
return "";
|
2022-05-16 17:37:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprDwindleLayout::toggleSplit(CWindow* pWindow) {
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
|
|
|
if (!PNODE || !PNODE->pParent)
|
|
|
|
return;
|
|
|
|
|
2023-08-10 22:01:16 +02:00
|
|
|
if (pWindow->m_bIsFullscreen)
|
|
|
|
return;
|
|
|
|
|
2022-05-16 17:37:46 +02:00
|
|
|
PNODE->pParent->splitTop = !PNODE->pParent->splitTop;
|
|
|
|
|
2022-04-20 16:53:41 +02:00
|
|
|
PNODE->pParent->recalcSizePosRecursive();
|
2022-05-28 20:46:20 +02:00
|
|
|
}
|
|
|
|
|
2024-02-14 18:58:28 +01:00
|
|
|
void CHyprDwindleLayout::swapSplit(CWindow* pWindow) {
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
|
|
|
if (!PNODE || !PNODE->pParent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pWindow->m_bIsFullscreen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::swap(PNODE->pParent->children[0], PNODE->pParent->children[1]);
|
|
|
|
|
|
|
|
PNODE->pParent->recalcSizePosRecursive();
|
|
|
|
}
|
|
|
|
|
2023-02-19 22:07:32 +01:00
|
|
|
void CHyprDwindleLayout::replaceWindowDataWith(CWindow* from, CWindow* to) {
|
|
|
|
const auto PNODE = getNodeFromWindow(from);
|
|
|
|
|
|
|
|
if (!PNODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PNODE->pWindow = to;
|
|
|
|
|
|
|
|
applyNodeDataToWindow(PNODE, true);
|
|
|
|
}
|
|
|
|
|
2022-05-28 20:46:20 +02:00
|
|
|
std::string CHyprDwindleLayout::getLayoutName() {
|
|
|
|
return "dwindle";
|
2022-06-20 15:37:27 +02:00
|
|
|
}
|
2022-07-16 15:57:31 +02:00
|
|
|
|
|
|
|
void CHyprDwindleLayout::onEnable() {
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2023-12-17 21:00:18 +01:00
|
|
|
if (w->m_bIsFloating || !w->m_bIsMapped || w->isHidden())
|
2022-07-16 15:57:31 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
onWindowCreatedTiling(w.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprDwindleLayout::onDisable() {
|
|
|
|
m_lDwindleNodesData.clear();
|
2022-08-20 17:59:15 +02:00
|
|
|
}
|
2024-02-28 12:45:43 +01:00
|
|
|
|
|
|
|
Vector2D CHyprDwindleLayout::predictSizeForNewWindow() {
|
|
|
|
if (!g_pCompositor->m_pLastMonitor)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
// get window candidate
|
|
|
|
CWindow* candidate = g_pCompositor->m_pLastWindow;
|
|
|
|
|
|
|
|
if (!candidate)
|
|
|
|
candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace);
|
|
|
|
|
|
|
|
// create a fake node
|
|
|
|
SDwindleNodeData node;
|
|
|
|
|
|
|
|
if (!candidate)
|
|
|
|
return g_pCompositor->m_pLastMonitor->vecSize;
|
|
|
|
else {
|
|
|
|
const auto PNODE = getNodeFromWindow(candidate);
|
|
|
|
|
|
|
|
if (!PNODE)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
node = *PNODE;
|
|
|
|
node.pWindow = nullptr;
|
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
CBox box = PNODE->box;
|
2024-02-28 12:45:43 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
static auto PFLMULT = CConfigValue<Hyprlang::FLOAT>("dwindle:split_width_multiplier");
|
2024-02-28 12:45:43 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
bool splitTop = box.h * *PFLMULT > box.w;
|
2024-02-28 12:45:43 +01:00
|
|
|
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto SPLITSIDE = !splitTop;
|
2024-02-28 12:45:43 +01:00
|
|
|
|
|
|
|
if (SPLITSIDE)
|
|
|
|
node.box = {{}, {box.w / 2.0, box.h}};
|
|
|
|
else
|
|
|
|
node.box = {{}, {box.w, box.h / 2.0}};
|
|
|
|
|
|
|
|
// TODO: make this better and more accurate
|
|
|
|
|
|
|
|
return node.box.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|