Skip to content

Commit

Permalink
fixed the entire master layout + added splitratio (only master-children)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Mar 10, 2022
1 parent b0deddd commit 82eeba5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/events/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating, int forcemonitor) {
// For master layout, add the index
PWINDOWINARR->setMasterChildIndex(g_pWindowManager->getWindowsOnWorkspace(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]) - 1);
// and set master if needed
if (g_pWindowManager->getWindowsOnWorkspace(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]) == 0)
if (g_pWindowManager->getWindowsOnWorkspace(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]) == 1) // 1 because the current window is already in the arr
PWINDOWINARR->setMaster(true);


Expand Down
26 changes: 19 additions & 7 deletions src/windowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,25 +1062,37 @@ void CWindowManager::recalcEntireWorkspace(const int& workspace) {
// first, calc the size
CWindow* pMaster = nullptr;
for (auto& w : windows) {
if (w.getWorkspaceID() == workspace && w.getMaster() && !w.getDead()) {
if (w.getWorkspaceID() == workspace && w.getMaster() && !w.getDead() && !w.getIsFloating() && !w.getDock()) {
pMaster = &w;
break;
}
}

CWindow* pMasterContainer = nullptr;
for (auto& w : windows) {
if (w.getWorkspaceID() == workspace && w.getParentNodeID() == 0 && !w.getIsFloating() && !w.getDock()) {
pMasterContainer = &w;
break;
}
}

if (!pMaster) {
Debug::log(ERR, "No master found on workspace???");
return;
}

// set the xy for master
float splitRatio = 1;
if (pMasterContainer)
splitRatio = pMasterContainer->getSplitRatio();

pMaster->setPosition(Vector2D(0, 0) + PMONITOR->vecPosition);
pMaster->setSize(Vector2D(PMONITOR->vecSize.x / 2, PMONITOR->vecSize.y));
pMaster->setSize(Vector2D(PMONITOR->vecSize.x / 2 * splitRatio, PMONITOR->vecSize.y));

// get children sorted
std::vector<CWindow*> children;
for (auto& w : windows) {
if (w.getWorkspaceID() == workspace && !w.getMaster() && w.getDrawable() > 0 && !w.getDead())
if (w.getWorkspaceID() == workspace && !w.getMaster() && w.getDrawable() > 0 && !w.getDead() && !w.getDock())
children.push_back(&w);
}
std::sort(children.begin(), children.end(), [](CWindow*& a, CWindow*& b) {
Expand All @@ -1096,8 +1108,8 @@ void CWindowManager::recalcEntireWorkspace(const int& workspace) {
// Children sorted, set xy
int yoff = 0;
for (const auto& child : children) {
child->setPosition(Vector2D(PMONITOR->vecSize.x / 2, yoff) + PMONITOR->vecPosition);
child->setSize(Vector2D(PMONITOR->vecSize.x / 2, PMONITOR->vecSize.y / children.size()));
child->setPosition(Vector2D(PMONITOR->vecSize.x / 2 * splitRatio, yoff) + PMONITOR->vecPosition);
child->setSize(Vector2D(PMONITOR->vecSize.x / 2 * (2 - splitRatio), PMONITOR->vecSize.y / children.size()));

yoff += PMONITOR->vecSize.y / children.size();
}
Expand Down Expand Up @@ -1296,7 +1308,7 @@ CWindow* CWindowManager::getMasterForWorkspace(const int& work) {
if (!pMaster) {
Debug::log(ERR, "No master found on workspace? Setting automatically");
for (auto& w : windows) {
if (w.getWorkspaceID() == work) {
if (w.getWorkspaceID() == work && !w.getDock() && !w.getIsFloating()) {
pMaster = &w;
w.setMaster(true);
break;
Expand All @@ -1314,7 +1326,7 @@ void CWindowManager::fixMasterWorkspaceOnClosed(CWindow* pWindow) {
// get children sorted
std::vector<CWindow*> children;
for (auto& w : windows) {
if (w.getWorkspaceID() == pWindow->getWorkspaceID() && !w.getMaster() && w.getDrawable() > 0 && w.getDrawable() != pWindow->getDrawable())
if (w.getWorkspaceID() == pWindow->getWorkspaceID() && !w.getMaster() && w.getDrawable() > 0 && w.getDrawable() != pWindow->getDrawable() && !w.getDock())
children.push_back(&w);
}
std::sort(children.begin(), children.end(), [](CWindow*& a, CWindow*& b) {
Expand Down

0 comments on commit 82eeba5

Please sign in to comment.