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 C9A9B385783B for ; Mon, 7 Mar 2022 22:14:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C9A9B385783B Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-219-Q2Zk3_sLOr2_6qOneOdoyQ-1; Mon, 07 Mar 2022 17:14:14 -0500 X-MC-Unique: Q2Zk3_sLOr2_6qOneOdoyQ-1 Received: by mail-wm1-f70.google.com with SMTP id r133-20020a1c448b000000b00385c3f3defaso5244803wma.3 for ; Mon, 07 Mar 2022 14:14:14 -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=GvLa++V5WrSYBc6nCcwZmDtAcxht/L/GXcTEgHuJ2zg=; b=Snvih7+1peA8neqFyhzZPKFvOVUwU9PAPnON4B2xjzQcVXryuyjXgK6sKLoTw67ou6 senXRmfxz0xknOhjp3eoYfEmu2Hg7CzjFY6pfQz8V9bi0+XMDU+1fCLKcxj3BpmpQOUe oCpYBbfP4foJOAgnDJqa1upZI5UzJPPWsh8B6Ywm9oUWWbCmgUpqEcPhoUJmgLBVohO8 KqodiG9w/ra8ejUfsOX5TCyw72/KNxgh/7Nqtm8kEKKbXDeiGHu4np/mqGW/Ui2Oo538 pRafHXkwNyqwSsmtGMCSWZrXecK9kSPzmqzIvBkPg6PX7wJR41rUGhcIS233bdnCz9d5 GCcg== X-Gm-Message-State: AOAM530LvlSLNT08E+j2qMBPfORq2CaRoY49D1oJkvV/ZZC6uTsuYSgl kPtRJ2ULNj8P6sm4kgBfX3lP473hvKmyCeEgUU1coiajS5ZfTBW/uL6YdUVSy0kIZDwCTkO+wB0 l/APaPypPdJYuvaJIL9ktYWXPlQbDLlC99n0a7e3HrEUOm3ACkSWcpRUf74XcrN5W1xNHzc3yHA == X-Received: by 2002:adf:f9c6:0:b0:1ef:832d:58fa with SMTP id w6-20020adff9c6000000b001ef832d58famr9941889wrr.378.1646691252829; Mon, 07 Mar 2022 14:14:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCmSKOeTsnq+9/ylRknPYpiM1wi+5705Wriw52w/8Mwp3w5RMJMag+waOsXZreiajOgBIEEA== X-Received: by 2002:adf:f9c6:0:b0:1ef:832d:58fa with SMTP id w6-20020adff9c6000000b001ef832d58famr9941870wrr.378.1646691252473; Mon, 07 Mar 2022 14:14:12 -0800 (PST) Received: from localhost (host86-134-151-205.range86-134.btcentralplus.com. [86.134.151.205]) by smtp.gmail.com with ESMTPSA id l16-20020a05600c1d1000b003816edb5711sm428680wms.26.2022.03.07.14.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 14:14:11 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 15/15] gdb/tui: fair split of delta after a resize Date: Mon, 7 Mar 2022 22:13:47 +0000 Message-Id: <7909d441aebb9f3ba2626d50b5b12d7e1e7e987d.1646691034.git.aburgess@redhat.com> 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=-11.8 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_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Mon, 07 Mar 2022 22:14:17 -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 | 37 +++++++++++++++++++---------- 2 files changed, 56 insertions(+), 12 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 481a67827f9..a40d2181968 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", -- 2.25.4