From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E7821385841A for ; Sun, 6 Feb 2022 14:13:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7821385841A Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-D-LhqaTBPGyF0iNtl1qxdw-1; Sun, 06 Feb 2022 09:13:29 -0500 X-MC-Unique: D-LhqaTBPGyF0iNtl1qxdw-1 Received: by mail-ed1-f70.google.com with SMTP id n7-20020a05640205c700b0040b7be76147so6127660edx.10 for ; Sun, 06 Feb 2022 06:13:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SsGTB1hwSi6MYMNWgJuZGfrDeBVyesOyVr/qm8cKgNs=; b=zJeW0xUO2k7uMjyZTNKz4zk6rio5HR8ImMEaGEk7HAsohuq7b6H8RuNtYJJBCAMAsN fkw7krcamyd3XZgDL8vWPIdwdwHqGDcerlVNLWdOQQZsY+LU5uytNBdxmLfNQXzSSKGR dx66727dSzyVLUEsj0YwuCFYGP9YyZgSKXf5kCyHf+lDAGdSB7Tw0OJLtn8oAvRYiV5g 03CHRfjrHiiOjLyT7vAUwYTRdVA9ou80X45IYVeVOPEJXE0ZBmk5MYvlh40tkxOgXHeM GpyQ6i1wWSHMENrKt/9iRIa1OPvRBP6BaaBXlMuYnAK7CdudUEcUCPZT8hRH5qf+iVK7 fXMQ== X-Gm-Message-State: AOAM531ckrLUp034+1f5v2+sOdHuLR7qONAqliep539yhu3s+jKg2YA/ cCgAI8ZPNyIkvhMZZh1zuKYd+/koi0tXZRX8VKXEf4P6beUIek34TG05r7SZPA39th2dBjDkpcQ eJtCByTXJXlHRd0yjU3uDCFCr/sFC2kTiiISyGNUD5eRauFo6bgsgE4m4O/VM+pqzd5/WTI4kJg == X-Received: by 2002:a05:6402:34cd:: with SMTP id w13mr9240332edc.383.1644156807870; Sun, 06 Feb 2022 06:13:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0lyfUTXuciWTAMhKnI9gBmuaGdQmtKqqXx2Nf8JiPc2ALNerOVaB7K4H0ZtZ5sbhD0MdVvg== X-Received: by 2002:a05:6402:34cd:: with SMTP id w13mr9240312edc.383.1644156807603; Sun, 06 Feb 2022 06:13:27 -0800 (PST) Received: from localhost (92.40.178.36.threembb.co.uk. [92.40.178.36]) by smtp.gmail.com with ESMTPSA id z8sm2598054ejc.197.2022.02.06.06.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 06:13:27 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 15/15] gdb/tui: fair split of delta after a resize Date: Sun, 6 Feb 2022 14:12:53 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_FILL_THIS_FORM_SHORT, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Feb 2022 14:13:32 -0000 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. --- gdb/testsuite/gdb.tui/winheight.exp | 31 +++++++++++++++++++++++++++++ gdb/tui/tui-layout.c | 30 +++++++++++++++++++--------- 2 files changed, 52 insertions(+), 9 deletions(-) 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 ac03e88acbe..ef98aaeef9d 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -727,9 +727,17 @@ tui_layout_split::set_size (const char *name, int 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 window that does, or until we loop all the way around. */ - for (int i = 0; delta != 0 && i < m_splits.size () - 1; ++i) + 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); @@ -738,19 +746,23 @@ tui_layout_split::set_size (const char *name, int new_size) { /* 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", -- 2.25.4