From cfa15c9ef6a01486c5983b38de5aa24cb2c32bd7 Mon Sep 17 00:00:00 2001 From: Pete Appleton Date: Mon, 29 Jan 2024 20:28:36 +0000 Subject: [PATCH] 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) --- src/Hy3Layout.cpp | 67 +++++++++++++++++++++++++---------------------- src/Hy3Node.cpp | 6 +++-- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index c62b306..96b4459 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -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 diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp index 6c2c415..d666d48 100644 --- a/src/Hy3Node.cpp +++ b/src/Hy3Node.cpp @@ -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); } }