fe98ccaf9a585304b9439ce2c6577fb20f98ff7d

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

Message

Fix miscalculated gaps

Diff

This diff is truncated to protect this page.

  1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
  2index 02f1e33dc1c435db573141e58dc6cc4379563f37..7088498c0ed3bf1fd84407015c4c1eeca887801f 100644
  3--- a/src/Hy3Layout.cpp
  4+++ b/src/Hy3Layout.cpp
  5@@ -219,10 +219,22 @@ void Hy3Layout::recalculateMonitor(const int& monitor_id) {
  6 		} else {
  7 			// Vaxry's hack from below, but again
  8 
  9+			// clang-format off
 10+			static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue;
 11+			static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue;
 12+			// clang-format on
 13+
 14+			int outer_gaps = -(*gaps_in - *gaps_out);
 15+			auto gap_pos_offset = Vector2D(outer_gaps, outer_gaps);
 16+			auto gap_size_offset = Vector2D(outer_gaps * 2, outer_gaps * 2);
 17+			Debug::log(LOG, "FS gaps: %d", outer_gaps);
 18+
 19 			Hy3Node fakeNode = {
 20 			    .data = window,
 21 			    .position = monitor->vecPosition + monitor->vecReservedTopLeft,
 22 			    .size = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight,
 23+			    .gap_pos_offset = gap_pos_offset,
 24+			    .gap_size_offset = gap_size_offset,
 25 			    .workspace_id = window->m_iWorkspaceID,
 26 			};
 27 
 28@@ -528,10 +540,22 @@ void Hy3Layout::fullscreenRequestForWindow(
 29 			Debug::log(LOG, "vaxry hack");
 30 			// Copy of vaxry's massive hack
 31 
 32+			// clang-format off
 33+			static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue;
 34+			static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue;
 35+			// clang-format on
 36+
 37+			int outer_gaps = -(*gaps_in - *gaps_out);
 38+			auto gap_pos_offset = Vector2D(outer_gaps, outer_gaps);
 39+			auto gap_size_offset = Vector2D(outer_gaps * 2, outer_gaps * 2);
 40+			Debug::log(LOG, "FS gaps: %d", outer_gaps);
 41+
 42 			Hy3Node fakeNode = {
 43 			    .data = window,
 44 			    .position = monitor->vecPosition + monitor->vecReservedTopLeft,
 45 			    .size = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight,
 46+			    .gap_pos_offset = gap_pos_offset,
 47+			    .gap_size_offset = gap_size_offset,
 48 			    .workspace_id = window->m_iWorkspaceID,
 49 			};
 50 
 51@@ -790,7 +814,7 @@ Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) {
 52 		if (node.data.as_group.layout == Hy3GroupLayout::Tabbed
 53 		    && node.data.as_group.tab_bar != nullptr)
 54 		{
 55-			if (pos.y < node.position.y + inset) {
 56+			if (pos.y < node.position.y + node.gap_pos_offset.y + inset) {
 57 				auto& children = node.data.as_group.children;
 58 				auto& tab_bar = *node.data.as_group.tab_bar;
 59 
 60diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp
 61index 046677aa83ec19554a0c2460f4f5961bf87c2bd7..de8e83cd9d39099c745607f6e9053f8f79ef052b 100644
 62--- a/src/Hy3Node.cpp
 63+++ b/src/Hy3Node.cpp
 64@@ -228,7 +228,7 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
 65 	Vector2D gap_pos_offset;
 66 	Vector2D gap_size_offset;
 67 	if (this->parent == nullptr) {
 68-		outer_gaps = *gaps_out - *gaps_in;
 69+		outer_gaps = -(*gaps_in - *gaps_out);
 70 
 71 		gap_pos_offset = Vector2D(outer_gaps, outer_gaps);
 72 		gap_size_offset = Vector2D(outer_gaps * 2, outer_gaps * 2);
 73@@ -250,45 +250,6 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
 74 
 75 	auto* group = &this->data.as_group;
 76 
 77-	if (group->children.size() == 1 && this->parent != nullptr) {
 78-		auto child = group->children.front();
 79-
 80-		if (child == this) {
 81-			Debug::log(ERR, "a group (%p) has become its own child", this);
 82-			errorNotif();
 83-		}
 84-
 85-		switch (group->layout) {
 86-		case Hy3GroupLayout::SplitH:
 87-			child->position.x = tpos.x;
 88-			child->size.x = tsize.x - *group_inset;
 89-			child->position.y = tpos.y;
 90-			child->size.y = tsize.y;
 91-			break;
 92-		case Hy3GroupLayout::SplitV:
 93-			child->position.y = tpos.y;
 94-			child->size.y = tsize.y - *group_inset;
 95-			child->position.x = tpos.x;
 96-			child->size.x = tsize.x;
 97-			break;
 98-		case Hy3GroupLayout::Tabbed:
 99-			child->position.y = tpos.y + tab_height_offset;
100-			child->size.y = tsize.y - tab_height_offset;
101-			child->position.x = tpos.x;
102-			child->size.x = tsize.x;
103-			break;
104-		}
105-
106-		child->gap_pos_offset = gap_pos_offset;
107-		child->gap_size_offset = gap_size_offset;
108-
109-		child->setHidden(this->hidden);
110-
111-		child->recalcSizePosRecursive(no_animation);
112-		this->updateTabBar(no_animation);
113-		return;
114-	}
115-
116 	int constraint;
117 	switch (group->layout) {
118 	case Hy3GroupLayout::SplitH: constraint = tsize.x; break;
119@@ -296,6 +257,12 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
120 	case Hy3GroupLayout::Tabbed: break;
121 	}
122 
123+	switch (group->layout) {
124+	case Hy3GroupLayout::SplitH: constraint -= gap_size_offset.x; break;
125+	case Hy3GroupLayout::SplitV: constraint -= gap_size_offset.y; break;
126+	case Hy3GroupLayout::Tabbed: break;
127+	}
128+
129 	double ratio_mul = group->layout != Hy3GroupLayout::Tabbed
130 	                     ? group->children.empty() ? 0 : constraint / group->children.size()
131 	                     : 0;
132@@ -320,6 +287,25 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
133 			child->position.y = tpos.y;
134 			child->size.y = tsize.y;
135 			child->setHidden(this->hidden);
136+
137+			if (group->children.size() == 1) {
138+				child->gap_pos_offset = gap_pos_offset;
139+				child->gap_size_offset = gap_size_offset;
140+				if (this->parent != nullptr) child->gap_size_offset.x += *group_inset;
141+				child->size.x += gap_size_offset.x;
142+			} else if (child == group->children.front()) {
143+				child->gap_pos_offset = gap_pos_offset;
144+				child->gap_size_offset = Vector2D(0, gap_size_offset.y);
145+				offset += gap_pos_offset.x;
146+			} else if (child == group->children.back()) {
147+				child->gap_pos_offset = Vector2D(0, gap_pos_offset.y);
148+				child->gap_size_offset = gap_size_offset;
149+				child->size.x += gap_size_offset.x;
150+			} else {
151+				child->gap_pos_offset = Vector2D(0, gap_pos_offset.y);
152+				child->gap_size_offset = Vector2D(0, gap_size_offset.y);
153+			}
154+
155 			child->recalcSizePosRecursive(no_animation);
156 			break;
157 		case Hy3GroupLayout::SplitV:
158@@ -329,21 +315,39 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) {
159 			child->position.x = tpos.x;
160 			child->size.x = tsize.x;
161 			child->setHidden(this->hidden);
162+
163+			if (group->children.size() == 1) {