d5828c58780716d2d5e4b597e585f52dec576310

Author
outfoxxed <outfoxxed@outfoxxed.me>
Committer
outfoxxed <outfoxxed@outfoxxed.me>
Date

Message

Fix single group nested in a group bug

Diff

 1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
 2index 048e7d0ad9ac51d8635045f7c88f63af668c850c..6a3f4dd1234e2414f8e0a4c285e2cf09cea34a4a 100644
 3--- a/src/Hy3Layout.cpp
 4+++ b/src/Hy3Layout.cpp
 5@@ -197,6 +197,18 @@ void Hy3Node::recalcSizePosRecursive(bool force) {
 6 	}
 7 }
 8 
 9+bool swallowGroup(Hy3Node* into) {
10+	if (into == nullptr || into->data.type != Hy3NodeData::Group) return false;
11+	if (into->data.as_group.children.size() != 1) return false;
12+	auto* child = into->data.as_group.children.front();
13+
14+	Debug::log(LOG, "Swallowing %p into %p", child, into);
15+	swapNodeData(*into, *child);
16+	into->layout->nodes.remove(*child);
17+
18+	return true;
19+}
20+
21 bool Hy3GroupData::hasChild(Hy3Node* node) {
22 	Debug::log(LOG, "Searching for child %p of %p", this, node);
23 	for (auto child: this->children) {
24@@ -1093,7 +1105,6 @@ Hy3Node* shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, bool shift) {
25 		// must happen AFTER `insert` is used
26 		old_group->children.remove(&node);
27 
28-
29 		auto splitmod = old_group->children.empty() ? 0.0 : (1.0 - node.size_ratio) / old_group->children.size();
30 		for (auto child: old_group->children) {
31 			child->size_ratio -= splitmod;
32@@ -1135,6 +1146,14 @@ Hy3Node* shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, bool shift) {
33 
34 		old_parent->recalcSizePosRecursive();
35 		target_group->recalcSizePosRecursive();
36+
37+		auto* target_parent = target_group->parent;
38+		while (target_parent != nullptr && swallowGroup(target_parent)) {
39+			target_parent = target_parent->parent;
40+		}
41+
42+		if (target_parent != target_group && target_parent != nullptr)
43+			target_parent->recalcSizePosRecursive();
44 	}
45 
46 	return nullptr;
47diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
48index ec6523e3f0b352aa325287eade5766be3fadc43d..0220c6037759e6bc56f4504e8ea104ee1129096f 100644
49--- a/src/Hy3Layout.hpp
50+++ b/src/Hy3Layout.hpp
51@@ -79,6 +79,10 @@ struct Hy3Node {
52 	bool operator==(const Hy3Node&) const;
53 };
54 
55+// Attempt to swallow a group. returns true if swallowed
56+Hy3Node* swallowGroups(Hy3Node*);
57+
58+
59 class Hy3Layout: public IHyprLayout {
60 public:
61 	virtual void onWindowCreatedTiling(CWindow*);