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)
This commit is contained in:
Pete Appleton 2024-01-29 20:28:36 +00:00
parent dad1589d21
commit cfa15c9ef6
2 changed files with 39 additions and 34 deletions

View file

@ -429,44 +429,47 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW
if (display_left && display_right) resize_delta.x = 0;
if (display_top && display_bottom) resize_delta.y = 0;
ShiftDirection target_edge_x;
ShiftDirection target_edge_y;
// Don't execute the logic unless there's something to do
if(resize_delta.x != 0 || resize_delta.y != 0) {
ShiftDirection target_edge_x;
ShiftDirection target_edge_y;
// Determine the direction in which we're going to look for the neighbor node
// that will be resized
if(corner == CORNER_NONE) { // It's probably a keyboard event.
target_edge_x = display_right ? ShiftDirection::Left : ShiftDirection::Right;
target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down;
// Determine the direction in which we're going to look for the neighbor node
// that will be resized
if(corner == CORNER_NONE) { // It's probably a keyboard event.
target_edge_x = display_right ? ShiftDirection::Left : ShiftDirection::Right;
target_edge_y = display_bottom ? ShiftDirection::Up : ShiftDirection::Down;
// If the anchor is not at the top/left then reverse the delta
if(target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x;
if(target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y;
} else { // It's probably a mouse event
// Resize against the edges corresponding to the selected corner
target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT
? ShiftDirection::Left : ShiftDirection::Right;
target_edge_y = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT
? ShiftDirection::Up : ShiftDirection::Down;
}
// If the anchor is not at the top/left then reverse the delta
if(target_edge_x == ShiftDirection::Left) resize_delta.x = -resize_delta.x;
if(target_edge_y == ShiftDirection::Up) resize_delta.y = -resize_delta.y;
} else { // It's probably a mouse event
// Resize against the edges corresponding to the selected corner
target_edge_x = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT
? ShiftDirection::Left : ShiftDirection::Right;
target_edge_y = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT
? ShiftDirection::Up : ShiftDirection::Down;
}
// Find the neighboring node in each axis, which will be either above or at the
// same level as the initiating node in the layout hierarchy. These are the nodes
// which must get resized (rather than the initiator) because they are the
// highest point in the hierarchy
auto horizontal_neighbor = node->findNeighbor(target_edge_x);
auto vertical_neighbor = node->findNeighbor(target_edge_y);
// Find the neighboring node in each axis, which will be either above or at the
// same level as the initiating node in the layout hierarchy. These are the nodes
// which must get resized (rather than the initiator) because they are the
// highest point in the hierarchy
auto horizontal_neighbor = node->findNeighbor(target_edge_x);
auto vertical_neighbor = node->findNeighbor(target_edge_y);
const auto animate =
&g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue;
const auto animate =
&g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue;
// Note that the resize direction is reversed, because from the neighbor's perspective
// the edge to be moved is the opposite way round. However, the delta is still the same.
if(horizontal_neighbor) {
horizontal_neighbor->resize(reverse(target_edge_x), resize_delta.x, *animate == 0);
}
// Note that the resize direction is reversed, because from the neighbor's perspective
// the edge to be moved is the opposite way round. However, the delta is still the same.
if(horizontal_neighbor) {
horizontal_neighbor->resize(reverse(target_edge_x), resize_delta.x, *animate == 0);
}
if(vertical_neighbor) {
vertical_neighbor->resize(reverse(target_edge_y), resize_delta.y, *animate == 0);
if(vertical_neighbor) {
vertical_neighbor->resize(reverse(target_edge_y), resize_delta.y, *animate == 0);
}
}
} else if(window->m_bIsFloating) {
// No parent node - is this a floating window? If so, use the same logic as the `main` layout

View file

@ -7,7 +7,7 @@
#include "Hy3Node.hpp"
#include "globals.hpp"
const float MIN_WINDOW_SIZE = 20;
const float MIN_RATIO = 0.0f;
// Hy3GroupData //
@ -945,9 +945,11 @@ void Hy3Node::resize(
auto requested_size_ratio = this->size_ratio + ratio_mod;
auto requested_neighbor_size_ratio = neighbor->size_ratio -ratio_mod;
if(requested_size_ratio * parent_size >= MIN_WINDOW_SIZE) {
if(requested_size_ratio >= MIN_RATIO
&& requested_neighbor_size_ratio >= MIN_RATIO) {
this->size_ratio = requested_size_ratio;
neighbor->size_ratio = requested_neighbor_size_ratio;
parent_node->recalcSizePosRecursive(no_animation);
}
}