From patchwork Sat May 27 18:28:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 70185 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DB723856961 for ; Sat, 27 May 2023 18:28:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DB723856961 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685212104; bh=HMb4MmbgcAPgIwb/cM5Uc3j8fhZH/MZwSJJSOKmXf1s=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=XshHav6kSKtWgnopaSgRVA/U8Brl83VBBi0BHkKtFZC8UT/jxTwyT2ueibjPj82DE x08eCQt5Lq4I6aF1t3MFI/Y/qC0ZunhiFE7vDvnhp7KM4ypXGWNJl7YUMyCzdY41ba k0WXuVtzFnjNRjIwpQjF9DKHa+eJzWUghUpaAtAs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 427843858C53 for ; Sat, 27 May 2023 18:27:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 427843858C53 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AE00A21AED; Sat, 27 May 2023 18:27:55 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 9480D136AA; Sat, 27 May 2023 18:27:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id kL4uI6tLcmSeCwAAGKfGzw (envelope-from ); Sat, 27 May 2023 18:27:55 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] [gdb/tui] Add tui_default_focus_window Date: Sat, 27 May 2023 20:28:07 +0200 Message-Id: <20230527182809.20569-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230527182809.20569-1-tdevries@suse.de> References: <20230527182809.20569-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" There are two moments when TUI makes an in principle arbitrary choice about what window will get the focus: - when entering TUI, and - when changing into another layout removes the focused window. In the latter case, it picks the first window in the window list. In the former case, it picks the src window, which at that point also happens to be the first window in the window list. Introduce a new function tui_default_focus_window that formalizes this way of picking a window to focus on, and use it in both cases. To keep the function interface simple, tui_default_focus_window picks the first in the tui_windows list, which requires a minor rewrite in tui_apply_current_layout to ensure that tui_windows is updated before we call tui_default_focus_window. No functional changes. Tested on x86_64-linux. --- gdb/tui/tui-layout.c | 19 ++++++++++++++----- gdb/tui/tui-layout.h | 4 ++++ gdb/tui/tui.c | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 50c568fb7d7..ea8b4378d1e 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -66,6 +66,14 @@ std::vector tui_windows; /* See tui-layout.h. */ +struct tui_win_info * +tui_default_focus_window () +{ + return tui_windows[0]; +} + +/* See tui-layout.h. */ + void tui_apply_current_layout (bool preserve_cmd_win_size_p) { @@ -94,21 +102,22 @@ tui_apply_current_layout (bool preserve_cmd_win_size_p) std::vector new_tui_windows; applied_layout->get_windows (&new_tui_windows); + /* Replace the global list of active windows. */ + std::vector old_tui_windows = std::move (tui_windows); + tui_windows = std::move (new_tui_windows); + /* Now delete any window that was not re-applied. */ tui_win_info *focus = tui_win_with_focus (); - for (tui_win_info *win_info : tui_windows) + for (tui_win_info *win_info : old_tui_windows) { if (!win_info->is_visible ()) { if (focus == win_info) - tui_set_win_focus_to (new_tui_windows[0]); + tui_set_win_focus_to (tui_default_focus_window ()); delete win_info; } } - /* Replace the global list of active windows. */ - tui_windows = std::move (new_tui_windows); - if (gdbarch == nullptr && TUI_DISASM_WIN != nullptr) tui_get_begin_asm_address (&gdbarch, &addr); tui_update_source_windows_with_addr (gdbarch, addr); diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h index ff354fb7c2f..29f21437118 100644 --- a/gdb/tui/tui-layout.h +++ b/gdb/tui/tui-layout.h @@ -413,4 +413,8 @@ using known_window_names_range extern known_window_names_range all_known_window_names (); +/* Return the window to set the focus to, in case that requires a choice. */ + +extern struct tui_win_info *tui_default_focus_window (); + #endif /* TUI_TUI_LAYOUT_H */ diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 10cf811a41e..f2e4c717193 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -458,7 +458,7 @@ tui_enable (void) tui_show_frame_info (0); tui_set_initial_layout (); - tui_set_win_focus_to (TUI_SRC_WIN); + tui_set_win_focus_to (tui_default_focus_window ()); keypad (TUI_CMD_WIN->handle.get (), TRUE); wrefresh (TUI_CMD_WIN->handle.get ()); tui_finish_init = false;