cfa15c9ef6a01486c5983b38de5aa24cb2c32bd7

Author
Pete Appleton <pete+git@catcity.me.uk>
Committer
Pete Appleton <pete+git@catcity.me.uk>
Date

Message

Use MIN_RATIO to cap node sizes

A minimum Vector2D would be ideal, but hard to calculate - it would require
either a tree walk for every single resize operation (very expensive),
or storing after a `recalcSizePosRecursive` operation (significant work)

Diff

  1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
  2index c62b306d17505f3a58d9396541a4c85dfce9f231..96b44593bcdf199967555148624b0cc05417679f 100644
  3--- a/src/Hy3Layout.cpp
  4+++ b/src/Hy3Layout.cpp
  5@@ -429,44 +429,47 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW
  6 		if (display_left && display_right) resize_delta.x = 0;
  7 		if (display_top && display_bottom) resize_delta.y = 0;
  8 
  9-		ShiftDirection target_edge_x;
 10-		ShiftDirection target_edge_y;
 11-
 12-		// Determine the direction in which we're going to look for the neighbor node
 13-		// that will be resized
 14-		if(corner == CORNER_NONE) {			// It's probably a keyboard event.
 15-			target_edge_x = display_right ? ShiftDirection::Left : ShiftDirection::Right;
 16-			target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down;
 17-
 18-			// If the anchor is not at the top/left then reverse the delta
 19-			if(target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x;
 20-			if(target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y;
 21-		} else {							// It's probably a mouse event
 22-			// Resize against the edges corresponding to the selected corner
 23-			target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT
 24-				? ShiftDirection::Left : ShiftDirection::Right;
 25-			target_edge_y = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT
 26-				? ShiftDirection::Up : ShiftDirection::Down;
 27-		}
 28+		// Don't execute the logic unless there's something to do
 29+		if(resize_delta.x != 0 || resize_delta.y != 0) {
 30+			ShiftDirection target_edge_x;
 31+			ShiftDirection target_edge_y;
 32+
 33+			// Determine the direction in which we're going to look for the neighbor node
 34+			// that will be resized
 35+			if(corner == CORNER_NONE) {			// It's probably a keyboard event.
 36+				target_edge_x = display_right ? ShiftDirection::Left : ShiftDirection::Right;
 37+				target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down;
 38+
 39+				// If the anchor is not at the top/left then reverse the delta
 40+				if(target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x;
 41+				if(target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y;
 42+			} else {							// It's probably a mouse event
 43+				// Resize against the edges corresponding to the selected corner
 44+				target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT
 45+					? ShiftDirection::Left : ShiftDirection::Right;
 46+				target_edge_y = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT
 47+					? ShiftDirection::Up : ShiftDirection::Down;
 48+			}
 49 
 50-		// Find the neighboring node in each axis, which will be either above or at the
 51-		// same level as the initiating node in the layout hierarchy.  These are the nodes
 52-		// which must get resized (rather than the initiator) because they are the
 53-		// highest point in the hierarchy
 54-		auto horizontal_neighbor = node->findNeighbor(target_edge_x);
 55-		auto vertical_neighbor = node->findNeighbor(target_edge_y);
 56+			// Find the neighboring node in each axis, which will be either above or at the
 57+			// same level as the initiating node in the layout hierarchy.  These are the nodes
 58+			// which must get resized (rather than the initiator) because they are the
 59+			// highest point in the hierarchy
 60+			auto horizontal_neighbor = node->findNeighbor(target_edge_x);
 61+			auto vertical_neighbor = node->findNeighbor(target_edge_y);
 62 
 63-		const auto animate =
 64-			&g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue;
 65+			const auto animate =
 66+				&g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue;
 67 
 68-		// Note that the resize direction is reversed, because from the neighbor's perspective
 69-		// the edge to be moved is the opposite way round.  However, the delta is still the same.
 70-		if(horizontal_neighbor) {
 71-			horizontal_neighbor->resize(reverse(target_edge_x), resize_delta.x, *animate == 0);
 72-		}
 73+			// Note that the resize direction is reversed, because from the neighbor's perspective
 74+			// the edge to be moved is the opposite way round.  However, the delta is still the same.
 75+			if(horizontal_neighbor) {
 76+				horizontal_neighbor->resize(reverse(target_edge_x), resize_delta.x, *animate == 0);
 77+			}
 78 
 79-		if(vertical_neighbor) {
 80-			vertical_neighbor->resize(reverse(target_edge_y), resize_delta.y, *animate == 0);
 81+			if(vertical_neighbor) {
 82+				vertical_neighbor->resize(reverse(target_edge_y), resize_delta.y, *animate == 0);
 83+			}
 84 		}
 85 	} else if(window->m_bIsFloating) {
 86 		// No parent node - is this a floating window?  If so, use the same logic as the `main` layout
 87diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp
 88index 6c2c415f05878dd83bdbdd94927d161ca19f2ee2..d666d4897760811792342dbaa649a222fdf67ff3 100644
 89--- a/src/Hy3Node.cpp
 90+++ b/src/Hy3Node.cpp
 91@@ -7,7 +7,7 @@
 92 #include "Hy3Node.hpp"
 93 #include "globals.hpp"
 94 
 95-const float MIN_WINDOW_SIZE = 20;
 96+const float MIN_RATIO = 0.0f;
 97 
 98 // Hy3GroupData //
 99 
100@@ -945,9 +945,11 @@ void Hy3Node::resize(
101 				auto requested_size_ratio = this->size_ratio + ratio_mod;
102 				auto requested_neighbor_size_ratio = neighbor->size_ratio -ratio_mod;
103 
104-				if(requested_size_ratio * parent_size >= MIN_WINDOW_SIZE) {
105+				if(requested_size_ratio  >= MIN_RATIO
106+					&& requested_neighbor_size_ratio >= MIN_RATIO) {
107 					this->size_ratio = requested_size_ratio;
108 					neighbor->size_ratio = requested_neighbor_size_ratio;
109+
110 					parent_node->recalcSizePosRecursive(no_animation);
111 				}
112 			}