aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2022-02-01 10:28:18 +0000
committerAndrew Burgess <aburgess@redhat.com>2022-04-03 15:31:47 +0100
commitb0fcf3e344438a4d115afdfaa7468bf90cc8c880 (patch)
tree0fb6d17444f09f11cbc316f10a5e4dbfc7147ffe /gdb/tui
parent47b8e12ffd0ecf924836aed55eb63b9e5d9e8ea1 (diff)
downloadgdb-b0fcf3e344438a4d115afdfaa7468bf90cc8c880.zip
gdb-b0fcf3e344438a4d115afdfaa7468bf90cc8c880.tar.gz
gdb-b0fcf3e344438a4d115afdfaa7468bf90cc8c880.tar.bz2
gdb/tui: fairer distribution of excess space during apply
When applying layouts gdb computes the size of each window (or rather, each sub-layout within a layout) using integer arithmetic. As this rounds down the results, then, when all sub-layouts are sized, there is the possibility that we have some space left over. Currently, this space is just assigned to an arbitrary sub-layout. This can result in some unbalanced results. Consider this set of steps with current master: (gdb) tui enable (gdb) layout regs (gdb) info win Name Lines Columns Focus regs 7 80 src 9 80 (has focus) status 1 80 cmd 8 80 Notice the weird split between the src and regs windows, the original layout specification has these windows given equal weight. The problem is that, with rounding, both the regs and src windows are initially sized to 7, the extra 2 lines are then arbitrarily added to the src window. In this commit, rather than add all the extra space to one single window, I instead hand out the extra space 1 line at a time, looping over all the sub-layouts. We take care to respect the min/max sizes, and so, we now get this result: (gdb) tui enable (gdb) layout regs (gdb) info win Name Lines Columns Focus regs 8 80 src 8 80 (has focus) status 1 80 cmd 8 80 This looks more natural to me. This is obviously a change in behaviour, and so, lots of the existing tests need to be updated to take this into account. None of the changes are huge, it's just a line or two (or column for width) moved between windows.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-layout.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 52105cc..30beefd 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -810,11 +810,11 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_)
info[i].size = info[i].max_size;
if (info[i].size < info[i].min_size)
info[i].size = info[i].min_size;
- /* If there is any leftover size, just redistribute it to the
- last resizeable window, by dropping it from the allocated
- size. We could try to be fancier here perhaps, by
- redistributing this size among all windows, not just the
- last window. */
+ /* Keep a total of all the size we've used so far (we gain some
+ size back if this window can share a border with a preceding
+ window). Any unused space will be distributed between all of
+ the other windows (while respecting min/max sizes) later in
+ this function. */
used_size += info[i].size;
if (info[i].share_box)
--used_size;
@@ -834,9 +834,33 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_)
}
/* Allocate any leftover size. */
- if (available_size >= used_size && last_index != -1)
+ if (available_size > used_size && last_index != -1)
{
- info[last_index].size += available_size - used_size;
+ /* Loop over all windows until all available space is used up. */
+ bool found_window_that_can_grow_p = true;
+ for (int idx = last_index;
+ available_size > used_size;
+ idx = (idx + 1) % m_splits.size ())
+ {
+ /* Once we have visited all of the windows, check that we did
+ manage to allocate some more space. This prevents us getting
+ stuck in the loop forever if we can't allocate anything
+ more. */
+ if (idx == last_index)
+ {
+ if (!found_window_that_can_grow_p)
+ break;
+ found_window_that_can_grow_p = false;
+ }
+
+ if (available_size > used_size
+ && info[idx].size < info[idx].max_size)
+ {
+ found_window_that_can_grow_p = true;
+ info[idx].size += 1;
+ used_size += 1;
+ }
+ }
if (debug_tui)
{