summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-12 16:44:18 +0200
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-04-12 16:44:18 +0200
commitb6a93b2f0383fc8f084c7757f0f67b8c0ebeccc7 (patch)
tree9da15dc91a16ddbbb9c32161eda96c2be4073131 /src/layout
parent8197fded02f34e76527c0bc17cc69e4fea3cdda4 (diff)
Added window grouping for dwindle
furthermore, added LayoutRenderHints.
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/DwindleLayout.cpp167
-rw-r--r--src/layout/DwindleLayout.hpp10
-rw-r--r--src/layout/IHyprLayout.hpp23
3 files changed, 189 insertions, 11 deletions
diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp
index b497388a..b007ae8e 100644
--- a/src/layout/DwindleLayout.cpp
+++ b/src/layout/DwindleLayout.cpp
@@ -2,6 +2,23 @@
#include "../Compositor.hpp"
void SDwindleNodeData::recalcSizePosRecursive() {
+
+ // check the group, if we are in one and not active, ignore.
+ if (pGroupParent && pGroupParent->groupMembers[pGroupParent->groupMemberActive] != this) {
+ if (pWindow)
+ pWindow->m_bHidden = true;
+ return;
+ } else {
+ if (pWindow)
+ pWindow->m_bHidden = false;
+ }
+
+ if (pGroupParent) {
+ // means we are in a group and focused. let's just act like the full window in this
+ size = pGroupParent->size;
+ position = pGroupParent->position;
+ }
+
if (children[0]) {
const auto REVERSESPLITRATIO = 2.f - splitRatio;
@@ -20,19 +37,22 @@ void SDwindleNodeData::recalcSizePosRecursive() {
children[1]->size = Vector2D(size.x, size.y / 2.f * REVERSESPLITRATIO);
}
- if (children[0]->isNode)
- children[0]->recalcSizePosRecursive();
- else
- layout->applyNodeDataToWindow(children[0]);
- if (children[1]->isNode)
- children[1]->recalcSizePosRecursive();
- else
- layout->applyNodeDataToWindow(children[1]);
+ children[0]->recalcSizePosRecursive();
+ children[1]->recalcSizePosRecursive();
} else {
layout->applyNodeDataToWindow(this);
}
}
+void SDwindleNodeData::getAllChildrenRecursive(std::deque<SDwindleNodeData*>* pDeque) {
+ if (children[0]) {
+ children[0]->getAllChildrenRecursive(pDeque);
+ children[1]->getAllChildrenRecursive(pDeque);
+ } else {
+ pDeque->push_back(this);
+ }
+}
+
int CHyprDwindleLayout::getNodesOnWorkspace(const int& id) {
int no = 0;
for (auto& n : m_lDwindleNodesData) {
@@ -217,10 +237,19 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) {
OPENINGON->pParent = NEWPARENT;
PNODE->pParent = NEWPARENT;
- NEWPARENT->recalcSizePosRecursive();
+ if (OPENINGON->pGroupParent) {
+ // means we opened on a group
+ PNODE->pGroupParent = OPENINGON->pGroupParent;
+ PNODE->pGroupParent->groupMembers.push_back(PNODE);
+ PNODE->pGroupParent->groupMemberActive = PNODE->pGroupParent->groupMembers.size() - 1;
- applyNodeDataToWindow(PNODE);
- applyNodeDataToWindow(OPENINGON);
+ PNODE->pGroupParent->recalcSizePosRecursive();
+ } else {
+ NEWPARENT->recalcSizePosRecursive();
+
+ applyNodeDataToWindow(PNODE);
+ applyNodeDataToWindow(OPENINGON);
+ }
pWindow->m_vRealPosition = PNODE->position + PNODE->size / 2.f;
pWindow->m_vRealSize = Vector2D(5,5);
@@ -259,6 +288,30 @@ void CHyprDwindleLayout::onWindowRemoved(CWindow* pWindow) {
else
PSIBLING->recalcSizePosRecursive();
+ // check if it was grouped
+ if (PNODE->pGroupParent) {
+ const auto MEMBERSCOPY = PNODE->pGroupParent->groupMembers;
+ PNODE->pGroupParent->groupMembers.clear();
+ for (auto& c : MEMBERSCOPY) {
+ if (c != PNODE) {
+ PNODE->pGroupParent->groupMembers.push_back(c);
+ }
+ }
+
+ if ((long unsigned int)PNODE->pGroupParent->groupMemberActive >= PNODE->pGroupParent->groupMembers.size())
+ PNODE->pGroupParent->groupMemberActive = 0;
+
+ if (PNODE->pGroupParent->groupMembers.size() <= 1) {
+ PNODE->pGroupParent->isGroup = false;
+ PSIBLING->pGroupParent = nullptr;
+ PNODE->pGroupParent->groupMembers.clear();
+
+ PSIBLING->recalcSizePosRecursive();
+ } else {
+ PNODE->pGroupParent->recalcSizePosRecursive();
+ }
+ }
+
m_lDwindleNodesData.remove(*PPARENT);
m_lDwindleNodesData.remove(*PNODE);
@@ -557,4 +610,96 @@ void CHyprDwindleLayout::recalculateWindow(CWindow* pWindow) {
return;
PNODE->recalcSizePosRecursive();
+}
+
+void CHyprDwindleLayout::toggleWindowGroup(CWindow* pWindow) {
+ if (!g_pCompositor->windowValidMapped(pWindow))
+ return;
+
+ // get the node
+ const auto PNODE = getNodeFromWindow(pWindow);
+
+ if (!PNODE)
+ return; // reject
+
+ const auto PGROUPPARENT = PNODE->pGroupParent;
+
+ if (PGROUPPARENT) {
+ // if there is a parent, release it
+ for (auto& node : PGROUPPARENT->groupMembers)
+ node->pGroupParent = nullptr;
+
+ PGROUPPARENT->groupMembers.clear();
+
+ PGROUPPARENT->isGroup = false;
+
+ PGROUPPARENT->recalcSizePosRecursive();
+ } else {
+ // if there is no parent, let's make one
+
+ const auto PPARENT = PNODE->pParent;
+
+ if (!PPARENT)
+ return; // reject making group on single window
+
+
+ PPARENT->isGroup = true;
+
+ // recursively get all members
+ std::deque<SDwindleNodeData*> allChildren;
+ PPARENT->getAllChildrenRecursive(&allChildren);
+
+ PPARENT->groupMembers = allChildren;
+
+ for (auto& c : PPARENT->groupMembers)
+ c->pGroupParent = PPARENT;
+
+ PPARENT->groupMemberActive = 0;
+
+ PPARENT->recalcSizePosRecursive();
+ }
+}
+
+void CHyprDwindleLayout::switchGroupWindow(CWindow* pWindow) {
+ if (!g_pCompositor->windowValidMapped(pWindow))
+ return; // reject
+
+ const auto PNODE = getNodeFromWindow(pWindow);
+
+ if (!PNODE)
+ return; // reject
+
+ if (!PNODE->pGroupParent)
+ return; // reject
+
+ PNODE->pGroupParent->groupMemberActive++;
+
+ if ((long unsigned int)PNODE->pGroupParent->groupMemberActive >= PNODE->pGroupParent->groupMembers.size())
+ PNODE->pGroupParent->groupMemberActive = 0;
+
+ PNODE->pGroupParent->recalcSizePosRecursive();
+
+ // focus
+ g_pCompositor->focusWindow(PNODE->pGroupParent->groupMembers[PNODE->pGroupParent->groupMemberActive]->pWindow);
+}
+
+SWindowRenderLayoutHints CHyprDwindleLayout::requestRenderHints(CWindow* pWindow) {
+ // window should be valid, insallah
+
+ SWindowRenderLayoutHints hints;
+
+ const auto PNODE = getNodeFromWindow(pWindow);
+ if (!PNODE)
+ return hints; // left for the future, maybe floating funkiness
+
+ if (PNODE->pGroupParent) {
+ hints.isBorderColor = true;
+
+ if (pWindow == g_pCompositor->m_pLastWindow)
+ hints.borderColor = CColor(g_pConfigManager->getInt("dwindle:col.group_border_active"));
+ else
+ hints.borderColor = CColor(g_pConfigManager->getInt("dwindle:col.group_border"));
+ }
+
+ return hints;
} \ No newline at end of file
diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp
index 8d849bcf..47da6cd3 100644
--- a/src/layout/DwindleLayout.hpp
+++ b/src/layout/DwindleLayout.hpp
@@ -2,6 +2,7 @@
#include "IHyprLayout.hpp"
#include <list>
+#include <deque>
class CHyprDwindleLayout;
@@ -13,6 +14,11 @@ struct SDwindleNodeData {
std::array<SDwindleNodeData*, 2> children = { nullptr, nullptr };
+ bool isGroup = false;
+ int groupMemberActive = 0;
+ std::deque<SDwindleNodeData*> groupMembers;
+ SDwindleNodeData* pGroupParent = nullptr;
+
Vector2D position;
Vector2D size;
@@ -26,6 +32,7 @@ struct SDwindleNodeData {
}
void recalcSizePosRecursive();
+ void getAllChildrenRecursive(std::deque<SDwindleNodeData*>*);
CHyprDwindleLayout* layout = nullptr;
};
@@ -41,6 +48,9 @@ public:
virtual void onMouseMove(const Vector2D&);
virtual void onWindowCreatedFloating(CWindow*);
virtual void fullscreenRequestForWindow(CWindow*);
+ virtual void toggleWindowGroup(CWindow*);
+ virtual void switchGroupWindow(CWindow*);
+ virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);
private:
diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp
index 3e85cc24..16414895 100644
--- a/src/layout/IHyprLayout.hpp
+++ b/src/layout/IHyprLayout.hpp
@@ -3,6 +3,11 @@
#include "../defines.hpp"
#include "../Window.hpp"
+struct SWindowRenderLayoutHints {
+ bool isBorderColor = false;
+ CColor borderColor;
+};
+
interface IHyprLayout {
public:
@@ -61,4 +66,22 @@ public:
*/
virtual void fullscreenRequestForWindow(CWindow*) = 0;
+ /*
+ Called when the user requests a window to be made into a group,
+ or when they want the group to be released.
+ Everything else is free to interpret by the layout.
+ */
+ virtual void toggleWindowGroup(CWindow*) = 0;
+
+ /*
+ Called when the user requests a group window switch
+ */
+ virtual void switchGroupWindow(CWindow*) = 0;
+
+ /*
+ Required to be handled, but may return just SWindowRenderLayoutHints()
+ Called when the renderer requests any special draw flags for
+ a specific window, e.g. border color for groups.
+ */
+ virtual SWindowRenderLayoutHints requestRenderHints(CWindow*) = 0;
}; \ No newline at end of file