2022-03-19 15:59:53 +01:00
|
|
|
#include "DwindleLayout.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
void SDwindleNodeData::recalcSizePosRecursive() {
|
|
|
|
if (children[0]) {
|
|
|
|
|
2022-04-10 19:31:36 +02:00
|
|
|
const auto REVERSESPLITRATIO = 2.f - splitRatio;
|
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
if (size.x > size.y) {
|
|
|
|
// split sidey
|
|
|
|
children[0]->position = position;
|
2022-04-10 19:31:36 +02:00
|
|
|
children[0]->size = Vector2D(size.x / 2.f * splitRatio, size.y);
|
|
|
|
children[1]->position = Vector2D(position.x + size.x / 2.f * splitRatio, position.y);
|
|
|
|
children[1]->size = Vector2D(size.x / 2.f * REVERSESPLITRATIO, size.y);
|
2022-03-19 20:30:21 +01:00
|
|
|
} else {
|
|
|
|
// split toppy bottomy
|
|
|
|
children[0]->position = position;
|
2022-04-10 19:31:36 +02:00
|
|
|
children[0]->size = Vector2D(size.x, size.y / 2.f * splitRatio);
|
|
|
|
children[1]->position = Vector2D(position.x, position.y + size.y / 2.f * splitRatio);
|
|
|
|
children[1]->size = Vector2D(size.x, size.y / 2.f * REVERSESPLITRATIO);
|
2022-03-19 20:30:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (children[0]->isNode)
|
|
|
|
children[0]->recalcSizePosRecursive();
|
|
|
|
else
|
|
|
|
layout->applyNodeDataToWindow(children[0]);
|
|
|
|
if (children[1]->isNode)
|
|
|
|
children[1]->recalcSizePosRecursive();
|
|
|
|
else
|
|
|
|
layout->applyNodeDataToWindow(children[1]);
|
|
|
|
} else {
|
|
|
|
layout->applyNodeDataToWindow(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-03-20 16:06:17 +01:00
|
|
|
if (n.workspaceID == id)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-19 15:59:53 +01:00
|
|
|
void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode) {
|
2022-04-11 19:51:37 +02:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(g_pCompositor->getWorkspaceByID(pNode->workspaceID)->m_iMonitorID);
|
2022-03-19 15:59:53 +01:00
|
|
|
|
|
|
|
if (!PMONITOR){
|
2022-03-20 16:06:17 +01:00
|
|
|
Debug::log(ERR, "Orphaned Node %x (workspace ID: %i)!!", pNode, pNode->workspaceID);
|
2022-03-19 15:59:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't set nodes, only windows.
|
|
|
|
if (pNode->isNode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// for gaps outer
|
|
|
|
const bool DISPLAYLEFT = STICKS(pNode->position.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
|
|
|
|
const bool DISPLAYRIGHT = STICKS(pNode->position.x + pNode->size.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
|
|
|
|
const bool DISPLAYTOP = STICKS(pNode->position.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
|
|
|
|
const bool DISPLAYBOTTOM = STICKS(pNode->position.y + pNode->size.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
|
|
|
|
|
|
|
|
const auto BORDERSIZE = g_pConfigManager->getInt("general:border_size");
|
|
|
|
const auto GAPSIN = g_pConfigManager->getInt("general:gaps_in");
|
|
|
|
const auto GAPSOUT = g_pConfigManager->getInt("general:gaps_out");
|
|
|
|
|
|
|
|
const auto PWINDOW = pNode->pWindow;
|
|
|
|
|
|
|
|
if (!g_pCompositor->windowValidMapped(PWINDOW)) {
|
|
|
|
Debug::log(ERR, "Node %x holding invalid window %x!!", pNode, PWINDOW);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PWINDOW->m_vSize = pNode->size;
|
|
|
|
PWINDOW->m_vPosition = pNode->position;
|
|
|
|
|
|
|
|
PWINDOW->m_vEffectivePosition = PWINDOW->m_vPosition + Vector2D(BORDERSIZE, BORDERSIZE);
|
|
|
|
PWINDOW->m_vEffectiveSize = PWINDOW->m_vSize - Vector2D(2 * BORDERSIZE, 2 * BORDERSIZE);
|
|
|
|
|
|
|
|
const auto OFFSETTOPLEFT = Vector2D(DISPLAYLEFT ? GAPSOUT : GAPSIN,
|
|
|
|
DISPLAYTOP ? GAPSOUT : GAPSIN);
|
|
|
|
|
|
|
|
const auto OFFSETBOTTOMRIGHT = Vector2D(DISPLAYRIGHT ? GAPSOUT : GAPSIN,
|
|
|
|
DISPLAYBOTTOM ? GAPSOUT : GAPSIN);
|
|
|
|
|
|
|
|
PWINDOW->m_vEffectivePosition = PWINDOW->m_vEffectivePosition + OFFSETTOPLEFT;
|
|
|
|
PWINDOW->m_vEffectiveSize = PWINDOW->m_vEffectiveSize - OFFSETTOPLEFT - OFFSETBOTTOMRIGHT;
|
|
|
|
|
2022-04-02 20:04:32 +02:00
|
|
|
if (PWINDOW->m_bIsPseudotiled) {
|
|
|
|
// Calculate pseudo
|
|
|
|
float scale = 1;
|
|
|
|
|
|
|
|
// adjust if doesnt fit
|
|
|
|
if (PWINDOW->m_vPseudoSize.x > PWINDOW->m_vEffectiveSize.x || PWINDOW->m_vPseudoSize.y > PWINDOW->m_vEffectiveSize.y) {
|
|
|
|
if (PWINDOW->m_vPseudoSize.x > PWINDOW->m_vEffectiveSize.x) {
|
|
|
|
scale = PWINDOW->m_vEffectiveSize.x / PWINDOW->m_vPseudoSize.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PWINDOW->m_vPseudoSize.y * scale > PWINDOW->m_vEffectiveSize.y) {
|
|
|
|
scale = PWINDOW->m_vEffectiveSize.y / PWINDOW->m_vPseudoSize.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto DELTA = PWINDOW->m_vEffectiveSize - PWINDOW->m_vPseudoSize * scale;
|
|
|
|
PWINDOW->m_vEffectiveSize = PWINDOW->m_vPseudoSize * scale;
|
|
|
|
PWINDOW->m_vEffectivePosition = PWINDOW->m_vEffectivePosition + DELTA / 2.f; // center
|
|
|
|
} else {
|
|
|
|
auto DELTA = PWINDOW->m_vEffectiveSize - PWINDOW->m_vPseudoSize;
|
|
|
|
PWINDOW->m_vEffectivePosition = PWINDOW->m_vEffectivePosition + DELTA / 2.f; // center
|
|
|
|
PWINDOW->m_vEffectiveSize = PWINDOW->m_vPseudoSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 22:01:59 +01:00
|
|
|
g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vEffectiveSize);
|
2022-03-19 15:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) {
|
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());
|
|
|
|
const auto PNODE = &m_lDwindleNodesData.back();
|
|
|
|
|
2022-03-20 16:06:17 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
// Populate the node with our window's data
|
2022-03-20 16:06:17 +01:00
|
|
|
PNODE->workspaceID = PMONITOR->activeWorkspace;
|
2022-03-19 15:59:53 +01:00
|
|
|
PNODE->pWindow = pWindow;
|
|
|
|
PNODE->isNode = false;
|
2022-03-19 20:30:21 +01:00
|
|
|
PNODE->layout = this;
|
2022-03-19 15:59:53 +01:00
|
|
|
|
2022-03-23 16:51:48 +01:00
|
|
|
SDwindleNodeData* OPENINGON;
|
|
|
|
const auto MONFROMCURSOR = g_pCompositor->getMonitorFromCursor();
|
|
|
|
|
2022-03-24 19:05:25 +01:00
|
|
|
if (PMONITOR->ID == MONFROMCURSOR->ID)
|
2022-03-23 16:51:48 +01:00
|
|
|
OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal()));
|
|
|
|
else
|
2022-03-24 19:05:25 +01:00
|
|
|
OPENINGON = getFirstNodeOnWorkspace(PMONITOR->activeWorkspace);
|
|
|
|
|
|
|
|
Debug::log(LOG, "OPENINGON: %x, Workspace: %i, Monitor: %i", OPENINGON, PNODE->workspaceID, PMONITOR->ID);
|
2022-03-22 22:04:35 +01:00
|
|
|
|
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) {
|
2022-03-19 15:59:53 +01:00
|
|
|
PNODE->position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
|
|
|
|
PNODE->size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight;
|
|
|
|
|
|
|
|
applyNodeDataToWindow(PNODE);
|
|
|
|
|
2022-03-23 22:01:59 +01:00
|
|
|
pWindow->m_vRealPosition = PNODE->position + PNODE->size / 2.f;
|
|
|
|
pWindow->m_vRealSize = Vector2D(5, 5);
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-03-22 22:04:35 +01: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
|
|
|
|
NEWPARENT->children[0] = OPENINGON;
|
|
|
|
NEWPARENT->children[1] = PNODE;
|
|
|
|
NEWPARENT->position = OPENINGON->position;
|
|
|
|
NEWPARENT->size = OPENINGON->size;
|
2022-03-20 16:06:17 +01:00
|
|
|
NEWPARENT->workspaceID = OPENINGON->workspaceID;
|
2022-03-19 20:30:21 +01:00
|
|
|
NEWPARENT->pParent = OPENINGON->pParent;
|
2022-03-19 15:59:53 +01:00
|
|
|
NEWPARENT->isNode = true; // it is a node
|
|
|
|
|
|
|
|
// 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
|
|
|
|
if (NEWPARENT->size.x > NEWPARENT->size.y) {
|
|
|
|
// split sidey
|
|
|
|
OPENINGON->position = NEWPARENT->position;
|
|
|
|
OPENINGON->size = Vector2D(NEWPARENT->size.x / 2.f, NEWPARENT->size.y);
|
|
|
|
PNODE->position = Vector2D(NEWPARENT->position.x + NEWPARENT->size.x / 2.f, NEWPARENT->position.y);
|
|
|
|
PNODE->size = Vector2D(NEWPARENT->size.x / 2.f, NEWPARENT->size.y);
|
|
|
|
} else {
|
|
|
|
// split toppy bottomy
|
|
|
|
OPENINGON->position = NEWPARENT->position;
|
|
|
|
OPENINGON->size = Vector2D(NEWPARENT->size.x, NEWPARENT->size.y / 2.f);
|
|
|
|
PNODE->position = Vector2D(NEWPARENT->position.x, NEWPARENT->position.y + NEWPARENT->size.y / 2.f);
|
|
|
|
PNODE->size = Vector2D(NEWPARENT->size.x, NEWPARENT->size.y / 2.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
OPENINGON->pParent = NEWPARENT;
|
|
|
|
PNODE->pParent = NEWPARENT;
|
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
NEWPARENT->recalcSizePosRecursive();
|
2022-03-21 19:28:43 +01:00
|
|
|
|
|
|
|
applyNodeDataToWindow(PNODE);
|
|
|
|
applyNodeDataToWindow(OPENINGON);
|
2022-03-23 22:01:59 +01:00
|
|
|
|
|
|
|
pWindow->m_vRealPosition = PNODE->position + PNODE->size / 2.f;
|
|
|
|
pWindow->m_vRealSize = Vector2D(5,5);
|
2022-03-19 15:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprDwindleLayout::onWindowRemoved(CWindow* pWindow) {
|
|
|
|
|
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
|
|
|
if (!PNODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto PPARENT = PNODE->pParent;
|
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
if (!PPARENT) {
|
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];
|
|
|
|
|
|
|
|
PSIBLING->position = PPARENT->position;
|
|
|
|
PSIBLING->size = PPARENT->size;
|
|
|
|
PSIBLING->pParent = PPARENT->pParent;
|
|
|
|
|
|
|
|
if (PPARENT->pParent != nullptr) {
|
|
|
|
if (PPARENT->pParent->children[0] == PPARENT) {
|
|
|
|
PPARENT->pParent->children[0] = PSIBLING;
|
|
|
|
} else {
|
|
|
|
PPARENT->pParent->children[1] = PSIBLING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
if (PSIBLING->pParent)
|
|
|
|
PSIBLING->pParent->recalcSizePosRecursive();
|
|
|
|
else
|
|
|
|
PSIBLING->recalcSizePosRecursive();
|
|
|
|
|
2022-03-19 15:59:53 +01:00
|
|
|
m_lDwindleNodesData.remove(*PPARENT);
|
|
|
|
m_lDwindleNodesData.remove(*PNODE);
|
2022-04-05 19:28:10 +02:00
|
|
|
|
|
|
|
// jump back like it jumps in
|
2022-04-05 20:49:15 +02:00
|
|
|
//pWindow->m_vEffectivePosition = pWindow->m_vEffectivePosition + ((pWindow->m_vEffectiveSize - Vector2D(5, 5)) * 0.5f);
|
|
|
|
// pWindow->m_vEffectiveSize = Vector2D(5, 5);
|
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-03-21 19:18:33 +01:00
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
|
|
|
|
|
|
|
|
// Ignore any recalc events if we have a fullscreen window.
|
2022-04-11 19:51:37 +02:00
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow)
|
2022-03-21 19:18:33 +01:00
|
|
|
return;
|
|
|
|
|
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) {
|
|
|
|
TOPNODE->position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft;
|
|
|
|
TOPNODE->size = 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
|
|
|
|
|
|
|
void CHyprDwindleLayout::changeWindowFloatingMode(CWindow* pWindow) {
|
2022-03-21 19:18:33 +01:00
|
|
|
|
|
|
|
if (pWindow->m_bIsFullscreen) {
|
|
|
|
Debug::log(LOG, "Rejecting a change float order because window is fullscreen.");
|
|
|
|
|
|
|
|
// restore its' floating mode
|
|
|
|
pWindow->m_bIsFloating = !pWindow->m_bIsFloating;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
const auto PNODE = getNodeFromWindow(pWindow);
|
|
|
|
|
|
|
|
if (!PNODE) {
|
2022-03-27 20:06:44 +02:00
|
|
|
// save real pos cuz the func applies the default 5,5 mid
|
|
|
|
const auto PSAVEDPOS = pWindow->m_vRealPosition;
|
|
|
|
const auto PSAVEDSIZE = pWindow->m_vRealSize;
|
|
|
|
|
2022-04-02 20:04:32 +02:00
|
|
|
// if the window is pseudo, update its size
|
|
|
|
pWindow->m_vPseudoSize = pWindow->m_vRealSize;
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
onWindowCreated(pWindow);
|
2022-03-27 20:06:44 +02:00
|
|
|
|
|
|
|
pWindow->m_vRealPosition = PSAVEDPOS;
|
|
|
|
pWindow->m_vRealSize = PSAVEDSIZE;
|
2022-03-20 11:14:24 +01:00
|
|
|
} else {
|
|
|
|
onWindowRemoved(pWindow);
|
2022-04-04 16:25:30 +02:00
|
|
|
|
|
|
|
g_pCompositor->moveWindowToTop(pWindow);
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprDwindleLayout::onBeginDragWindow() {
|
2022-03-21 19:18:33 +01:00
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow;
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
m_vBeginDragSizeXY = Vector2D();
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
// Window will be floating. Let's check if it's valid. It should be, but I don't like crashing.
|
|
|
|
if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW)) {
|
|
|
|
Debug::log(ERR, "Dragging attempted on an invalid window!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-22 17:31:19 +01:00
|
|
|
if (DRAGGINGWINDOW->m_bIsFullscreen) {
|
|
|
|
Debug::log(LOG, "Rejecting drag on a fullscreen window.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-10 19:31:36 +02:00
|
|
|
DRAGGINGWINDOW->m_bDraggingTiled = false;
|
|
|
|
|
2022-04-03 13:49:21 +02:00
|
|
|
if (!DRAGGINGWINDOW->m_bIsFloating) {
|
2022-04-10 19:31:36 +02:00
|
|
|
if (g_pInputManager->dragButton == BTN_LEFT) {
|
|
|
|
changeWindowFloatingMode(DRAGGINGWINDOW);
|
|
|
|
DRAGGINGWINDOW->m_bIsFloating = true;
|
2022-04-10 20:02:36 +02:00
|
|
|
DRAGGINGWINDOW->m_bDraggingTiled = true;
|
2022-04-10 19:31:36 +02:00
|
|
|
}
|
2022-04-03 13:49:21 +02:00
|
|
|
}
|
2022-03-22 17:31:19 +01:00
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
m_vBeginDragXY = g_pInputManager->getMouseCoordsInternal();
|
|
|
|
m_vBeginDragPositionXY = DRAGGINGWINDOW->m_vRealPosition;
|
|
|
|
m_vBeginDragSizeXY = DRAGGINGWINDOW->m_vRealSize;
|
2022-04-10 19:31:36 +02:00
|
|
|
m_vLastDragXY = m_vBeginDragXY;
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
|
|
|
|
2022-04-03 13:49:21 +02:00
|
|
|
void CHyprDwindleLayout::onEndDragWindow() {
|
|
|
|
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow;
|
|
|
|
|
2022-04-04 16:25:30 +02:00
|
|
|
if (DRAGGINGWINDOW->m_bDraggingTiled) {
|
|
|
|
DRAGGINGWINDOW->m_bIsFloating = false;
|
2022-04-03 13:49:21 +02:00
|
|
|
changeWindowFloatingMode(DRAGGINGWINDOW);
|
2022-04-04 16:25:30 +02:00
|
|
|
}
|
|
|
|
|
2022-04-03 13:49:21 +02:00
|
|
|
}
|
|
|
|
|
2022-03-20 11:14:24 +01:00
|
|
|
void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) {
|
|
|
|
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow;
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
// Window invalid or drag begin size 0,0 meaning we rejected it.
|
|
|
|
if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW) || m_vBeginDragSizeXY == Vector2D())
|
2022-03-20 11:14:24 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
const auto DELTA = Vector2D(mousePos.x - m_vBeginDragXY.x, mousePos.y - m_vBeginDragXY.y);
|
2022-04-10 19:31:36 +02:00
|
|
|
const auto TICKDELTA = Vector2D(mousePos.x - m_vLastDragXY.x, mousePos.y - m_vLastDragXY.y);
|
|
|
|
m_vLastDragXY = mousePos;
|
2022-03-20 11:14:24 +01:00
|
|
|
|
|
|
|
if (g_pInputManager->dragButton == BTN_LEFT) {
|
|
|
|
DRAGGINGWINDOW->m_vRealPosition = m_vBeginDragPositionXY + DELTA;
|
2022-03-24 16:05:06 +01:00
|
|
|
DRAGGINGWINDOW->m_vEffectivePosition = DRAGGINGWINDOW->m_vRealPosition;
|
2022-03-20 11:14:24 +01:00
|
|
|
} else {
|
2022-04-10 19:31:36 +02:00
|
|
|
if (DRAGGINGWINDOW->m_bIsFloating) {
|
|
|
|
DRAGGINGWINDOW->m_vRealSize = m_vBeginDragSizeXY + DELTA;
|
|
|
|
DRAGGINGWINDOW->m_vRealSize = Vector2D(std::clamp(DRAGGINGWINDOW->m_vRealSize.x, (double)20, (double)999999), std::clamp(DRAGGINGWINDOW->m_vRealSize.y, (double)20, (double)999999));
|
2022-03-20 11:14:24 +01:00
|
|
|
|
2022-04-10 19:31:36 +02:00
|
|
|
DRAGGINGWINDOW->m_vEffectiveSize = DRAGGINGWINDOW->m_vRealSize;
|
2022-03-24 16:05:06 +01:00
|
|
|
|
2022-04-10 19:31:36 +02:00
|
|
|
g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize);
|
|
|
|
} else {
|
|
|
|
// we need to adjust the splitratio
|
|
|
|
|
|
|
|
// get some data about our window
|
|
|
|
const auto PNODE = getNodeFromWindow(DRAGGINGWINDOW);
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(DRAGGINGWINDOW->m_iMonitorID);
|
|
|
|
const bool DISPLAYLEFT = STICKS(DRAGGINGWINDOW->m_vPosition.x, PMONITOR->vecPosition.x);
|
|
|
|
const bool DISPLAYRIGHT = STICKS(DRAGGINGWINDOW->m_vPosition.x + DRAGGINGWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x);
|
|
|
|
const bool DISPLAYTOP = STICKS(DRAGGINGWINDOW->m_vPosition.y, PMONITOR->vecPosition.y);
|
|
|
|
const bool DISPLAYBOTTOM = STICKS(DRAGGINGWINDOW->m_vPosition.y + DRAGGINGWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y);
|
|
|
|
|
|
|
|
// construct allowed movement
|
|
|
|
Vector2D allowedMovement = TICKDELTA;
|
|
|
|
if (DISPLAYLEFT && DISPLAYRIGHT)
|
|
|
|
allowedMovement.x = 0;
|
|
|
|
|
|
|
|
if (DISPLAYBOTTOM && DISPLAYTOP)
|
|
|
|
allowedMovement.y = 0;
|
|
|
|
|
|
|
|
// get the correct containers to apply splitratio to
|
|
|
|
const auto PPARENT = PNODE->pParent;
|
|
|
|
|
|
|
|
if (!PPARENT)
|
|
|
|
return; // the only window on a workspace, ignore
|
|
|
|
|
|
|
|
const bool PARENTSIDEBYSIDE = PPARENT->size.x / PPARENT->size.y > 1.f;
|
|
|
|
|
|
|
|
// Get the parent's parent
|
|
|
|
const auto PPARENT2 = PPARENT->pParent;
|
|
|
|
|
|
|
|
// No parent means we have only 2 windows, and thus one axis of freedom
|
|
|
|
if (!PPARENT2) {
|
|
|
|
if (PARENTSIDEBYSIDE) {
|
|
|
|
allowedMovement.x *= 2.f / PPARENT->size.x;
|
|
|
|
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f);
|
|
|
|
PPARENT->recalcSizePosRecursive();
|
|
|
|
} else {
|
|
|
|
allowedMovement.y *= 2.f / PPARENT->size.y;
|
|
|
|
PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f);
|
|
|
|
PPARENT->recalcSizePosRecursive();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a parent 2, we have 2 axes of freedom
|
|
|
|
const auto SIDECONTAINER = PARENTSIDEBYSIDE ? PPARENT : PPARENT2;
|
|
|
|
const auto TOPCONTAINER = PARENTSIDEBYSIDE ? PPARENT2 : PPARENT;
|
|
|
|
|
|
|
|
allowedMovement.x *= 2.f / SIDECONTAINER->size.x;
|
|
|
|
allowedMovement.y *= 2.f / TOPCONTAINER->size.y;
|
|
|
|
|
|
|
|
SIDECONTAINER->splitRatio = std::clamp(SIDECONTAINER->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f);
|
|
|
|
TOPCONTAINER->splitRatio = std::clamp(TOPCONTAINER->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f);
|
|
|
|
SIDECONTAINER->recalcSizePosRecursive();
|
|
|
|
TOPCONTAINER->recalcSizePosRecursive();
|
|
|
|
}
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
2022-03-20 11:22:55 +01:00
|
|
|
|
|
|
|
// get middle point
|
|
|
|
Vector2D middle = DRAGGINGWINDOW->m_vRealPosition + DRAGGINGWINDOW->m_vRealSize / 2.f;
|
|
|
|
|
|
|
|
// and check its monitor
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromVector(middle);
|
|
|
|
|
2022-03-20 15:55:47 +01:00
|
|
|
if (PMONITOR) {
|
2022-03-20 11:22:55 +01:00
|
|
|
DRAGGINGWINDOW->m_iMonitorID = PMONITOR->ID;
|
2022-03-20 15:55:47 +01:00
|
|
|
DRAGGINGWINDOW->m_iWorkspaceID = PMONITOR->activeWorkspace;
|
|
|
|
}
|
2022-03-20 13:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprDwindleLayout::onWindowCreatedFloating(CWindow* pWindow) {
|
2022-03-21 17:24:41 +01:00
|
|
|
wlr_box desiredGeometry = {0};
|
|
|
|
g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry);
|
2022-03-20 13:37:07 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
|
|
|
|
2022-03-30 17:43:31 +02:00
|
|
|
if (!PMONITOR){
|
|
|
|
Debug::log(ERR, "Window %x (%s) has an invalid monitor in onWindowCreatedFloating!!!", pWindow, pWindow->m_szTitle.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:24:41 +01:00
|
|
|
if (desiredGeometry.width <= 0 || desiredGeometry.height <= 0) {
|
|
|
|
const auto PWINDOWSURFACE = g_pXWaylandManager->getWindowSurface(pWindow);
|
2022-03-24 16:05:06 +01:00
|
|
|
pWindow->m_vEffectiveSize = Vector2D(PWINDOWSURFACE->current.width, PWINDOWSURFACE->current.height);
|
|
|
|
pWindow->m_vEffectivePosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.x) / 2.f, PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.y) / 2.f);
|
2022-03-21 17:24:41 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// we respect the size.
|
2022-03-24 16:05:06 +01:00
|
|
|
pWindow->m_vEffectiveSize = Vector2D(desiredGeometry.width, desiredGeometry.height);
|
2022-03-21 17:24:41 +01:00
|
|
|
|
|
|
|
// check if it's on the correct monitor!
|
|
|
|
Vector2D middlePoint = Vector2D(desiredGeometry.x, desiredGeometry.y) + Vector2D(desiredGeometry.width, desiredGeometry.height) / 2.f;
|
|
|
|
|
2022-03-22 21:28:57 +01:00
|
|
|
// TODO: detect a popup in a more consistent way.
|
2022-03-30 20:16:23 +02:00
|
|
|
if ((g_pCompositor->getMonitorFromVector(middlePoint) && g_pCompositor->getMonitorFromVector(middlePoint)->ID != pWindow->m_iMonitorID) || (desiredGeometry.x == 0 && desiredGeometry.y == 0)) {
|
2022-03-21 17:24:41 +01:00
|
|
|
// if it's not, fall back to the center placement
|
2022-03-24 16:05:06 +01:00
|
|
|
pWindow->m_vEffectivePosition = PMONITOR->vecPosition + Vector2D((PMONITOR->vecSize.x - desiredGeometry.width) / 2.f, (PMONITOR->vecSize.y - desiredGeometry.height) / 2.f);
|
2022-03-21 17:24:41 +01:00
|
|
|
} else {
|
|
|
|
// if it is, we respect where it wants to put itself.
|
|
|
|
// most of these are popups
|
2022-03-24 16:05:06 +01:00
|
|
|
pWindow->m_vEffectivePosition = Vector2D(desiredGeometry.x, desiredGeometry.y);
|
2022-03-21 17:24:41 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 20:04:39 +01:00
|
|
|
|
2022-03-24 18:22:01 +01:00
|
|
|
if (!pWindow->m_bX11DoesntWantBorders) {
|
|
|
|
pWindow->m_vRealPosition = pWindow->m_vEffectivePosition + pWindow->m_vEffectiveSize / 2.f;
|
|
|
|
pWindow->m_vRealSize = Vector2D(5, 5);
|
|
|
|
} else {
|
|
|
|
pWindow->m_vRealPosition = pWindow->m_vEffectivePosition;
|
|
|
|
pWindow->m_vRealSize = pWindow->m_vEffectiveSize;
|
|
|
|
}
|
2022-03-24 16:05:06 +01:00
|
|
|
|
2022-03-22 20:04:39 +01:00
|
|
|
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize);
|
|
|
|
g_pCompositor->fixXWaylandWindowsOnWorkspace(PMONITOR->activeWorkspace);
|
2022-04-04 16:25:30 +02:00
|
|
|
|
|
|
|
g_pCompositor->moveWindowToTop(pWindow);
|
2022-03-21 19:18:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow) {
|
|
|
|
if (!g_pCompositor->windowValidMapped(pWindow))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID);
|
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
if (PWORKSPACE->m_bHasFullscreenWindow && !pWindow->m_bIsFullscreen) {
|
2022-03-21 19:18:33 +01:00
|
|
|
// if the window wants to be fullscreen but there already is one,
|
|
|
|
// ignore the request.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, accept it.
|
|
|
|
pWindow->m_bIsFullscreen = !pWindow->m_bIsFullscreen;
|
2022-04-11 19:51:37 +02:00
|
|
|
PWORKSPACE->m_bHasFullscreenWindow = !PWORKSPACE->m_bHasFullscreenWindow;
|
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
|
|
|
|
pWindow->m_vEffectivePosition = pWindow->m_vPosition;
|
|
|
|
pWindow->m_vEffectiveSize = pWindow->m_vSize;
|
|
|
|
|
|
|
|
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if it now got fullscreen, make it fullscreen
|
|
|
|
|
|
|
|
// save position and size if floating
|
|
|
|
if (pWindow->m_bIsFloating) {
|
|
|
|
pWindow->m_vPosition = pWindow->m_vRealPosition;
|
|
|
|
pWindow->m_vSize = pWindow->m_vRealSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply new pos and size being monitors' box
|
|
|
|
pWindow->m_vEffectivePosition = PMONITOR->vecPosition;
|
|
|
|
pWindow->m_vEffectiveSize = PMONITOR->vecSize;
|
|
|
|
|
|
|
|
g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize);
|
|
|
|
}
|
|
|
|
|
2022-04-04 16:25:30 +02:00
|
|
|
g_pCompositor->moveWindowToTop(pWindow);
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
// we need to fix XWayland windows by sending them to NARNIA
|
|
|
|
// because otherwise they'd still be recieving mouse events
|
|
|
|
g_pCompositor->fixXWaylandWindowsOnWorkspace(PMONITOR->activeWorkspace);
|
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();
|
|
|
|
}
|