diff options
author | Andrew Burgess <aburgess@redhat.com> | 2022-01-24 22:02:59 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-04-03 15:15:09 +0100 |
commit | 160444ec7fd7c6df81826b8e06aa32a2ac1df856 (patch) | |
tree | 203f32b2a5e84359ef9756ce50e1b5f64553eb6d /gdb/tui/tui-layout.c | |
parent | ef466e0f0827555fcae21a905b3a2b9a6c0a5712 (diff) | |
download | gdb-160444ec7fd7c6df81826b8e06aa32a2ac1df856.zip gdb-160444ec7fd7c6df81826b8e06aa32a2ac1df856.tar.gz gdb-160444ec7fd7c6df81826b8e06aa32a2ac1df856.tar.bz2 |
gdb/tui: add new 'tui window width' command and 'winwidth' alias
This commit adds a new command 'tui window width', and an alias
'winwidth'. This command is equivalent to the old 'winheight'
command (which was recently renamed 'tui window height').
Even though I recently moved the old tui commands under the tui
namespace, and I would strongly encourage all new tui commands to be
added as 'tui ....' only (users can create their own top-level aliases
if they want), I'm breaking that suggestion here, and adding a
'winwidth' alias.
Given that we already have 'winheight' and have done for years, it
just didn't seem right to no have the matching 'winwidth'.
You might notice in the test that the window resizing doesn't quite
work right. I setup a horizontal layout, then grow and shrink the
windows. At the end of the test the windows should be back to their
original size...
... they are not. This isn't my fault, honest! GDB's window resizing
is a little ... temperamental, and is prone to getting things slightly
wrong during resizes, off by 1 type things. This is true for height
resizing, as well as the new width resizing.
Later patches in this series will rework the resizing algorithm, which
should improve things in this area. For now, I'm happy that the width
resizing is as good as the height resizing, given the existing quirks.
For the docs side I include a paragraph that explains how multiple
windows are required before the width can be adjusted. For
completeness, I've added the same paragraph to the winheight
description. With the predefined layouts this extra paragraph is not
really needed for winheight, as there are always multiple windows on
the screen. However, with custom layouts, this might not be true, so
adding the paragraph seems like a good idea.
As for the changes in gdb itself, I've mostly just taken the existing
height adjustment code, changed the name to make it generic 'size'
adjustment, and added a boolean flag to indicate if we are adjusting
the width or the height.
Diffstat (limited to 'gdb/tui/tui-layout.c')
-rw-r--r-- | gdb/tui/tui-layout.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 62fb54c..239c966 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -121,6 +121,14 @@ tui_adjust_window_height (struct tui_win_info *win, int new_height) applied_layout->set_height (win->name (), new_height); } +/* See tui-layout. */ + +void +tui_adjust_window_width (struct tui_win_info *win, int new_width) +{ + applied_layout->set_width (win->name (), new_width); +} + /* Set the current layout to LAYOUT. */ static void @@ -571,7 +579,7 @@ tui_layout_split::set_weights_from_sizes () /* See tui-layout.h. */ tui_adjust_result -tui_layout_split::set_height (const char *name, int new_height) +tui_layout_split::set_size (const char *name, int new_size, bool set_width_p) { /* Look through the children. If one is a layout holding the named window, we're done; or if one actually is the named window, @@ -579,13 +587,16 @@ tui_layout_split::set_height (const char *name, int new_height) int found_index = -1; for (int i = 0; i < m_splits.size (); ++i) { - tui_adjust_result adjusted - = m_splits[i].layout->set_height (name, new_height); + tui_adjust_result adjusted; + if (set_width_p) + adjusted = m_splits[i].layout->set_width (name, new_size); + else + adjusted = m_splits[i].layout->set_height (name, new_size); if (adjusted == HANDLED) return HANDLED; if (adjusted == FOUND) { - if (!m_vertical) + if (set_width_p ? m_vertical : !m_vertical) return FOUND; found_index = i; break; @@ -594,12 +605,15 @@ tui_layout_split::set_height (const char *name, int new_height) if (found_index == -1) return NOT_FOUND; - if (m_splits[found_index].layout->height == new_height) + int curr_size = (set_width_p + ? m_splits[found_index].layout->width + : m_splits[found_index].layout->height); + if (curr_size == new_size) return HANDLED; set_weights_from_sizes (); - int delta = m_splits[found_index].weight - new_height; - m_splits[found_index].weight = new_height; + int delta = m_splits[found_index].weight - new_size; + m_splits[found_index].weight = new_size; /* Distribute the "delta" over the next window; but if the next window cannot hold it all, keep going until we either find a @@ -633,7 +647,10 @@ tui_layout_split::set_height (const char *name, int new_height) if (delta != 0) { - warning (_("Invalid window height specified")); + if (set_width_p) + warning (_("Invalid window width specified")); + else + warning (_("Invalid window height specified")); /* Effectively undo any modifications made here. */ set_weights_from_sizes (); } |