From patchwork Wed Dec 11 23:21:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36749 Received: (qmail 15029 invoked by alias); 11 Dec 2019 23:21:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 14827 invoked by uid 89); 11 Dec 2019 23:21:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Dec 2019 23:21:38 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id E24EE20300; Wed, 11 Dec 2019 18:21:36 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 077A520C17; Wed, 11 Dec 2019 18:21:10 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id E97DB20AF6; Wed, 11 Dec 2019 18:21:09 -0500 (EST) X-Gerrit-PatchSet: 5 Date: Wed, 11 Dec 2019 18:21:06 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Tom Tromey , Andrew Burgess , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [pushed] Change "winheight" resizing to use new layout code X-Gerrit-Change-Id: I6bb681375a46adc8d29fd06f581deed4e078e78a X-Gerrit-Change-Number: 370 X-Gerrit-ChangeURL: X-Gerrit-Commit: d4eeccfe6b3395e12fcc03bdcc20439ccc399e2b In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, andrew.burgess@embecosm.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191211232109.E97DB20AF6@gnutoolchain-gerrit.osci.io> The original change was created by Tom Tromey. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/370 ...................................................................... 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 * 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 --- M gdb/ChangeLog M gdb/tui/tui-layout.c M gdb/tui/tui-layout.h M gdb/tui/tui-win.c 4 files changed, 22 insertions(+), 279 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 22cebfb..c80c540 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2019-12-11 Tom Tromey + * 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. + +2019-12-11 Tom Tromey + * tui/tui-win.c (tui_resize_all): Remove code, call tui_apply_current_layout. 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 @@ 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 @@ /* 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 -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 @@ /* 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 @@ 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 @@ 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,