From 418e2d96aef0b52d1f93eb3dfe7d08906c7c719c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 20 Apr 2022 16:18:58 +0200 Subject: Added the movewindow dispatcher --- src/layout/DwindleLayout.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ src/layout/DwindleLayout.hpp | 1 + src/layout/IHyprLayout.hpp | 6 +++++ 3 files changed, 59 insertions(+) (limited to 'src/layout') diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 2af7a2e2..5b7ee165 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -726,4 +726,56 @@ SWindowRenderLayoutHints CHyprDwindleLayout::requestRenderHints(CWindow* pWindow } return hints; +} + +void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { + // windows should be valid, insallah + + const auto PNODE = getNodeFromWindow(pWindow); + const auto PNODE2 = getNodeFromWindow(pWindow2); + + if (!PNODE2 || !PNODE) + return; + + // we will not delete the nodes, just fix the tree + if (PNODE2->pParent == PNODE->pParent) { + const auto PPARENT = PNODE->pParent; + + if (PPARENT->children[0] == PNODE) { + PPARENT->children[0] = PNODE2; + PPARENT->children[1] = PNODE; + } else { + PPARENT->children[0] = PNODE; + PPARENT->children[1] = PNODE2; + } + } else { + if (PNODE->pParent) { + const auto PPARENT = PNODE->pParent; + + if (PPARENT->children[0] == PNODE) { + PPARENT->children[0] = PNODE2; + } else { + PPARENT->children[1] = PNODE2; + } + } + + if (PNODE2->pParent) { + const auto PPARENT = PNODE2->pParent; + + if (PPARENT->children[0] == PNODE2) { + PPARENT->children[0] = PNODE; + } else { + PPARENT->children[1] = PNODE; + } + } + } + + const auto PPARENTNODE2 = PNODE2->pParent; + PNODE2->pParent = PNODE->pParent; + PNODE->pParent = PPARENTNODE2; + + // these are window nodes, so no children. + + // recalc the workspace + getMasterNodeOnWorkspace(PNODE->workspaceID)->recalcSizePosRecursive(); } \ No newline at end of file diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index 47da6cd3..68496723 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -51,6 +51,7 @@ public: virtual void toggleWindowGroup(CWindow*); virtual void switchGroupWindow(CWindow*); virtual SWindowRenderLayoutHints requestRenderHints(CWindow*); + virtual void switchWindows(CWindow*, CWindow*); private: diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index 16414895..341d5fbb 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -84,4 +84,10 @@ public: a specific window, e.g. border color for groups. */ virtual SWindowRenderLayoutHints requestRenderHints(CWindow*) = 0; + + /* + Called when the user requests two windows to be swapped places. + The layout is free to ignore. + */ + virtual void switchWindows(CWindow*, CWindow*) = 0; }; \ No newline at end of file -- cgit v1.2.3