aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-10-26 16:37:32 -0600
committerTom Tromey <tom@tromey.com>2019-12-11 15:49:03 -0700
commitd4eeccfe6b3395e12fcc03bdcc20439ccc399e2b (patch)
treee5fa11e0988ec21da67163b834142dce19fa8b1f /gdb/tui
parent3d97994549706f8f65fe9726b1fec1f0d643f822 (diff)
downloadgdb-d4eeccfe6b3395e12fcc03bdcc20439ccc399e2b.zip
gdb-d4eeccfe6b3395e12fcc03bdcc20439ccc399e2b.tar.gz
gdb-d4eeccfe6b3395e12fcc03bdcc20439ccc399e2b.tar.bz2
Change "winheight" resizing to use new layout code
The "winheight" command resizes a specified window, resizing the other windows in the layout to adapt. In the current code, this is done by examining each possible layout separately. The new layout code has a more general approach to handling this, and this patch simply removes the old code in favor of a call into the new layout engine. gdb/ChangeLog 2019-12-11 Tom Tromey <tom@tromey.com> * tui/tui-win.c (tui_set_win_height_command): Call tui_adjust_window_height. (tui_adjust_win_heights, new_height_ok): Remove. * tui/tui-layout.h (tui_adjust_window_height): Declare. * tui/tui-layout.c (tui_adjust_window_height): New function. Change-Id: I6bb681375a46adc8d29fd06f581deed4e078e78a
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-layout.c8
-rw-r--r--gdb/tui/tui-layout.h4
-rw-r--r--gdb/tui/tui-win.c281
3 files changed, 14 insertions, 279 deletions
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 1884c2a..9ab89a8 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -70,6 +70,14 @@ tui_apply_current_layout ()
applied_layout->apply (0, 0, tui_term_width (), tui_term_height ());
}
+/* See tui-layout. */
+
+void
+tui_adjust_window_height (struct tui_win_info *win, int new_height)
+{
+ applied_layout->adjust_size (win->name (), new_height);
+}
+
/* Show the screen layout defined. */
static void
show_layout (enum tui_layout_type layout)
diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h
index a9346ef..691d4ad 100644
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -177,4 +177,8 @@ extern void tui_set_layout (enum tui_layout_type);
/* Apply the current layout. */
extern void tui_apply_current_layout ();
+/* Adjust the window height of WIN to NEW_HEIGHT. */
+extern void tui_adjust_window_height (struct tui_win_info *win,
+ int new_height);
+
#endif /* TUI_TUI_LAYOUT_H */
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 199f3ba..ac3690a 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -56,9 +56,6 @@
#include <signal.h>
-static enum tui_status tui_adjust_win_heights (struct tui_win_info *,
- int);
-static int new_height_ok (struct tui_win_info *, int);
static void tui_set_tab_width_command (const char *, int);
static void tui_refresh_all_command (const char *, int);
static void tui_all_windows_info (const char *, int);
@@ -932,12 +929,8 @@ tui_set_win_height_command (const char *arg, int from_tty)
/* Now change the window's height, and adjust
all other windows around it. */
- if (tui_adjust_win_heights (win_info,
- new_height) == TUI_FAILURE)
- warning (_("Invalid window height specified.\n%s"),
- WIN_HEIGHT_USAGE);
- else
- tui_update_gdb_sizes ();
+ tui_adjust_window_height (win_info, new_height);
+ tui_update_gdb_sizes ();
}
else
warning (_("Invalid window height specified.\n%s"),
@@ -951,170 +944,6 @@ tui_set_win_height_command (const char *arg, int from_tty)
printf_filtered (WIN_HEIGHT_USAGE);
}
-/* Function to adjust all window heights around the primary. */
-static enum tui_status
-tui_adjust_win_heights (struct tui_win_info *primary_win_info,
- int new_height)
-{
- enum tui_status status = TUI_FAILURE;
-
- if (new_height_ok (primary_win_info, new_height))
- {
- status = TUI_SUCCESS;
- if (new_height != primary_win_info->height)
- {
- int diff;
- struct tui_win_info *win_info;
- struct tui_locator_window *locator = tui_locator_win_info_ptr ();
- enum tui_layout_type cur_layout = tui_current_layout ();
- int width = tui_term_width ();
-
- diff = (new_height - primary_win_info->height) * (-1);
- if (cur_layout == SRC_COMMAND
- || cur_layout == DISASSEM_COMMAND)
- {
- struct tui_win_info *src_win_info;
-
- primary_win_info->resize (new_height, width,
- 0, primary_win_info->y);
- if (primary_win_info->type == CMD_WIN)
- {
- win_info = *(tui_source_windows ().begin ());
- src_win_info = win_info;
- }
- else
- {
- win_info = tui_win_list[CMD_WIN];
- src_win_info = primary_win_info;
- }
- win_info->resize (win_info->height + diff, width,
- 0, win_info->y);
- TUI_CMD_WIN->y = locator->y + 1;
- if ((src_win_info->type == SRC_WIN
- || src_win_info->type == DISASSEM_WIN))
- {
- tui_source_window_base *src_base
- = (tui_source_window_base *) src_win_info;
- if (src_base->content.empty ())
- src_base->erase_source_content ();
- }
- }
- else
- {
- struct tui_win_info *first_win;
- struct tui_source_window_base *second_win;
- tui_source_window_base *src1;
-
- if (cur_layout == SRC_DISASSEM_COMMAND)
- {
- src1 = TUI_SRC_WIN;
- first_win = src1;
- second_win = TUI_DISASM_WIN;
- }
- else
- {
- src1 = nullptr;
- first_win = TUI_DATA_WIN;
- second_win = *(tui_source_windows ().begin ());
- }
- if (primary_win_info == TUI_CMD_WIN)
- { /* Split the change in height across the 1st & 2nd
- windows, adjusting them as well. */
- /* Subtract the locator. */
- int first_split_diff = diff / 2;
- int second_split_diff = first_split_diff;
-
- if (diff % 2)
- {
- if (first_win->height >
- second_win->height)
- if (diff < 0)
- first_split_diff--;
- else
- first_split_diff++;
- else
- {
- if (diff < 0)
- second_split_diff--;
- else
- second_split_diff++;
- }
- }
- /* Make sure that the minimum heights are
- honored. */
- while ((first_win->height + first_split_diff) < 3)
- {
- first_split_diff++;
- second_split_diff--;
- }
- while ((second_win->height + second_split_diff) < 3)
- {
- second_split_diff++;
- first_split_diff--;
- }
- first_win->resize (first_win->height + first_split_diff,
- width,
- 0, first_win->y);
- second_win->resize (second_win->height + second_split_diff,
- width,
- 0, first_win->height - 1);
- locator->resize (1, width,
- 0, (second_win->y
- + second_win->height + 1));
-
- TUI_CMD_WIN->resize (new_height, width,
- 0, locator->y + 1);
- }
- else
- {
- if ((TUI_CMD_WIN->height + diff) < 1)
- { /* If there is no way to increase the command
- window take real estate from the 1st or 2nd
- window. */
- if ((TUI_CMD_WIN->height + diff) < 1)
- {
- int i;
-
- for (i = TUI_CMD_WIN->height + diff;
- (i < 1); i++)
- if (primary_win_info == first_win)
- second_win->height--;
- else
- first_win->height--;
- }
- }
- if (primary_win_info == first_win)
- first_win->resize (new_height, width, 0, 0);
- else
- first_win->resize (first_win->height, width, 0, 0);
- second_win->y = first_win->height - 1;
- if (primary_win_info == second_win)
- second_win->resize (new_height, width,
- 0, first_win->height - 1);
- else
- second_win->resize (second_win->height, width,
- 0, first_win->height - 1);
- locator->resize (1, width,
- 0, (second_win->y
- + second_win->height + 1));
- TUI_CMD_WIN->y = locator->y + 1;
- if ((TUI_CMD_WIN->height + diff) < 1)
- TUI_CMD_WIN->resize (1, width, 0, locator->y + 1);
- else
- TUI_CMD_WIN->resize (TUI_CMD_WIN->height + diff, width,
- 0, locator->y + 1);
- }
- if (src1 != nullptr && src1->content.empty ())
- src1->erase_source_content ();
- if (second_win->content.empty ())
- second_win->erase_source_content ();
- }
- }
- }
-
- return status;
-}
-
/* See tui-data.h. */
int
@@ -1123,112 +952,6 @@ tui_win_info::max_height () const
return tui_term_height () - 2;
}
-static int
-new_height_ok (struct tui_win_info *primary_win_info,
- int new_height)
-{
- int ok = (new_height < tui_term_height ());
-
- if (ok)
- {
- int diff;
- enum tui_layout_type cur_layout = tui_current_layout ();
-
- diff = (new_height - primary_win_info->height) * (-1);
- if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
- {
- ok = (new_height <= primary_win_info->max_height ()
- && new_height >= MIN_CMD_WIN_HEIGHT);
- if (ok)
- { /* Check the total height. */
- struct tui_win_info *win_info;
-
- if (primary_win_info == TUI_CMD_WIN)
- win_info = *(tui_source_windows ().begin ());
- else
- win_info = TUI_CMD_WIN;
- ok = ((new_height +
- (win_info->height + diff)) <= tui_term_height ());
- }
- }
- else
- {
- int cur_total_height, total_height, min_height = 0;
- struct tui_win_info *first_win;
- struct tui_win_info *second_win;
-
- if (cur_layout == SRC_DISASSEM_COMMAND)
- {
- first_win = TUI_SRC_WIN;
- second_win = TUI_DISASM_WIN;
- }
- else
- {
- first_win = TUI_DATA_WIN;
- second_win = *(tui_source_windows ().begin ());
- }
- /* We could simply add all the heights to obtain the same
- result but below is more explicit since we subtract 1 for
- the line that the first and second windows share, and add
- one for the locator. */
- total_height = cur_total_height =
- (first_win->height + second_win->height - 1)
- + TUI_CMD_WIN->height + 1; /* Locator. */
- if (primary_win_info == TUI_CMD_WIN)
- {
- /* Locator included since first & second win share a line. */
- ok = ((first_win->height +
- second_win->height + diff) >=
- (MIN_WIN_HEIGHT * 2)
- && new_height >= MIN_CMD_WIN_HEIGHT);
- if (ok)
- {
- total_height = new_height +
- (first_win->height +
- second_win->height + diff);
- min_height = MIN_CMD_WIN_HEIGHT;
- }
- }
- else
- {
- min_height = MIN_WIN_HEIGHT;
-
- /* First see if we can increase/decrease the command
- window. And make sure that the command window is at
- least 1 line. */
- ok = ((TUI_CMD_WIN->height + diff) > 0);
- if (!ok)
- { /* Looks like we have to increase/decrease one of
- the other windows. */
- if (primary_win_info == first_win)
- ok = (second_win->height + diff) >= min_height;
- else
- ok = (first_win->height + diff) >= min_height;
- }
- if (ok)
- {
- if (primary_win_info == first_win)
- total_height = new_height +
- second_win->height +
- TUI_CMD_WIN->height + diff;
- else
- total_height = new_height +
- first_win->height +
- TUI_CMD_WIN->height + diff;
- }
- }
- /* Now make sure that the proposed total height doesn't
- exceed the old total height. */
- if (ok)
- ok = (new_height >= min_height
- && total_height <= cur_total_height);
- }
- }
-
- return ok;
-}
-
-
static void
parse_scrolling_args (const char *arg,
struct tui_win_info **win_to_scroll,