From: Andrew Burgess Date: Tue, 1 Feb 2022 14:59:11 +0000 (+0000) Subject: gdb/tui: fair split of delta after a resize X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=357c158f3a1921538a45b72bb635f15cc1abd31a;p=binutils-gdb.git gdb/tui: fair split of delta after a resize Currently, in master gdb, when a tui window is changed in size, the screen delta is mostly just added to the next available window. We do take care to respect the min/max size, but in most cases, these limits are just "the terminal size", and so, we end up placing the whole delta on the next window. Consider these steps in an 80 column, 24 line terminal: (gdb) tui enable (gdb) layout src (gdb) layout split (gdb) info win Name Lines Columns Focus src 8 80 (has focus) asm 8 80 status 1 80 cmd 8 80 (gdb) winheight cmd +2 (gdb) info win Name Lines Columns Focus src 6 80 (has focus) asm 8 80 status 1 80 cmd 10 80 Notice that initially, the windows were balanced, 8 lines each for the major windows. Then, when the cmd window was adjusted, the extra two lines were given to the asm window. I think it would be nicer if the delta was spread more evenly over the available windows. In the example above, after the adjustment the layout now looks like: (gdb) info win Name Lines Columns Focus src 7 80 (has focus) asm 7 80 status 1 80 cmd 10 80 This is achieved within tui_layout_split::set_size, by just handing out the delta in increments of 1 to each window (except for the window the user adjusted), until there's no more delta left. Of course, we continue to respect the min/max window sizes. --- diff --git a/gdb/testsuite/gdb.tui/winheight.exp b/gdb/testsuite/gdb.tui/winheight.exp index b541c21b825..8296dd79513 100644 --- a/gdb/testsuite/gdb.tui/winheight.exp +++ b/gdb/testsuite/gdb.tui/winheight.exp @@ -43,11 +43,42 @@ Term::check_box "smaller source box again" 0 0 80 10 Term::command "winheight src +5" Term::check_box "larger source box again" 0 0 80 15 +# Check that attempting a window to be too large gives an error. +Term::command "winheight src 100" +Term::check_box "source box has not changed" 0 0 80 15 +Term::check_region_contents "check error message about src size 100" 0 16 80 8 \ + [multi_line "$gdb_prompt winheight src 100\\s+" \ + "warning: Invalid window height specified\\s+" \ + "$gdb_prompt"] + +# Check that incrementing to a size that is "too big" will trigger an +# error, and that the window doesn't resize. +Term::command "winheight src 20" +Term::check_box "source box is at its max size" 0 0 80 20 +Term::command "winheight src +1" +Term::check_box "source box is still at its max size" 0 0 80 20 +Term::check_region_contents "check error message about src +1" 0 21 80 3 \ + [multi_line "$gdb_prompt winheight src \\+1\\s+" \ + "warning: Invalid window height specified\\s+" \ + "$gdb_prompt"] + +# Reset the cmd window to a sane size. +Term::command "winheight cmd 8" + +Term::command "layout regs" +Term::check_box "register window" 0 0 80 8 +Term::check_box "source window" 0 7 80 8 + +Term::command "winheight cmd 10" +Term::check_box "register window after resize" 0 0 80 7 +Term::check_box "source window after resize" 0 6 80 7 + # At one point we had a bug where adjusting the winheight would result # in GDB keeping hold of duplicate window pointers, which it might # then try to delete when the layout was changed. Running this test # under valgrind would expose that bug. Term::command "layout asm" +Term::command "winheight cmd 8" Term::check_box "check for asm window" 0 0 80 15 diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index d326c05ef01..09887d3d594 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -691,12 +691,21 @@ tui_layout_split::set_size (const char *name, int new_size, bool set_width_p) tui_debug_printf ("before delta (%d) distribution, weights: %s", delta, tui_debug_weights_to_string ().c_str ()); - /* Distribute the "delta" over the next window; but if the next - window cannot hold it all, keep going until we either find a - window that does, or until we loop all the way around. */ - for (int i = 0; delta != 0 && i < m_splits.size () - 1; ++i) + /* Distribute the "delta" over all other windows, while respecting their + min/max sizes. We grow each window by 1 line at a time continually + looping over all the windows. However, skip the window that the user + just resized, obviously we don't want to readjust that window. */ + bool found_window_that_can_grow_p = true; + for (int i = 0; delta != 0; i = (i + 1) % m_splits.size ()) { int index = (found_index + 1 + i) % m_splits.size (); + if (index == found_index) + { + if (!found_window_that_can_grow_p) + break; + found_window_that_can_grow_p = false; + continue; + } int new_min, new_max; m_splits[index].layout->get_sizes (m_vertical, &new_min, &new_max); @@ -705,19 +714,23 @@ tui_layout_split::set_size (const char *name, int new_size, bool set_width_p) { /* The primary window grew, so we are trying to shrink other windows. */ - int available = m_splits[index].weight - new_min; - int shrink_by = std::min (available, -delta); - m_splits[index].weight -= shrink_by; - delta += shrink_by; + if (m_splits[index].weight > new_min) + { + m_splits[index].weight -= 1; + delta += 1; + found_window_that_can_grow_p = true; + } } else { /* The primary window shrank, so we are trying to grow other windows. */ - int available = new_max - m_splits[index].weight; - int grow_by = std::min (available, delta); - m_splits[index].weight += grow_by; - delta -= grow_by; + if (m_splits[index].weight < new_max) + { + m_splits[index].weight += 1; + delta -= 1; + found_window_that_can_grow_p = true; + } } tui_debug_printf ("index = %d, weight now: %d",