From patchwork Sat Jan 4 18:33:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37176 Received: (qmail 130506 invoked by alias); 4 Jan 2020 18:34:18 -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 130380 invoked by uid 89); 4 Jan 2020 18:34:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=2846, Switch, focused X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.49.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 Jan 2020 18:34:15 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 32FBC5AD7 for ; Sat, 4 Jan 2020 12:34:14 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id noFaiCiL83Qi0noFai0thb; Sat, 04 Jan 2020 12:34:14 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wWrSyUueodWjSX8I4klyxwwjDhRsld9ZChQPOMWOWas=; b=WMHvvOn5lyl/2mYIIqXaSH4LU3 xy6oCt5ZnpoiY5yrj3DDlzG63iC35jNPpsaOmnoMJtOfjQwQBQuEGJLf7IazuqiyXt6CNDttLkJ06 ACSm7tTIab0Sh+2+RHqKufizD; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:48942 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1inoFa-0026Lh-0m; Sat, 04 Jan 2020 11:34:14 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 05/24] Reimplement TUI "C-x 1" binding Date: Sat, 4 Jan 2020 11:33:51 -0700 Message-Id: <20200104183410.17114-6-tom@tromey.com> In-Reply-To: <20200104183410.17114-1-tom@tromey.com> References: <20200104183410.17114-1-tom@tromey.com> The TUI "C-x 1" key binding removes TUI windows, based on the current layout. With user-defined layouts, this is no longer easy to do. This patch changes "C-x 1" to simply delete windows, leaving just the focus window, the locator, and the command window. gdb/ChangeLog 2020-01-04 Tom Tromey * tui/tui.c (tui_rl_delete_other_windows): Call tui_remove_some_windows. * tui/tui-layout.h (class tui_layout_base) : Declare method. (class tui_layout_window) : New method. (class tui_layout_split) : Declare. (tui_remove_some_windows): Declare. * tui/tui-layout.c (tui_remove_some_windows): New function. (tui_layout_split::remove_windows): New method. Change-Id: If186f9c3f263913e963b965204481d1b4385c6d4 --- gdb/ChangeLog | 12 ++++++++++++ gdb/tui/tui-layout.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ gdb/tui/tui-layout.h | 15 +++++++++++++++ gdb/tui/tui.c | 22 +--------------------- 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 016cab649d4..86b496d273e 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -284,6 +284,28 @@ tui_next_layout () tui_layout_command ("next", 0); } +/* See tui-layout.h. */ + +void +tui_remove_some_windows () +{ + tui_win_info *focus = tui_win_with_focus (); + + if (strcmp (focus->name (), "cmd") == 0) + { + /* Try leaving the source or disassembly window. If neither + exists, just do nothing. */ + focus = TUI_SRC_WIN; + if (focus == nullptr) + focus = TUI_DISASM_WIN; + if (focus == nullptr) + return; + } + + applied_layout->remove_windows (focus->name ()); + tui_apply_current_layout (); +} + static void extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) { @@ -749,6 +771,29 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_) m_applied = true; } +/* See tui-layout.h. */ + +void +tui_layout_split::remove_windows (const char *name) +{ + for (int i = 0; i < m_splits.size (); ++i) + { + const char *this_name = m_splits[i].layout->get_name (); + if (this_name == nullptr) + m_splits[i].layout->remove_windows (name); + else + { + if (strcmp (this_name, name) == 0 + || strcmp (this_name, "cmd") == 0) + { + /* Keep. */ + } + m_splits.erase (m_splits.begin () + i); + --i; + } + } +} + static void initialize_layouts () { diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h index 7e4b7b7a816..f711b004b84 100644 --- a/gdb/tui/tui-layout.h +++ b/gdb/tui/tui-layout.h @@ -64,6 +64,10 @@ public: the sizes of the other windows around it. */ virtual bool adjust_size (const char *name, int new_height) = 0; + /* Remove some windows from the layout, leaving the command window + and the window being passed in here. */ + virtual void remove_windows (const char *name) = 0; + /* The most recent space allocation. */ int x = 0; int y = 0; @@ -106,6 +110,10 @@ public: bool bottom_boxed_p () const override; + void remove_windows (const char *name) override + { + } + protected: void get_sizes (int *min_height, int *max_height) override; @@ -149,6 +157,8 @@ public: bool bottom_boxed_p () const override; + void remove_windows (const char *name) override; + protected: void get_sizes (int *min_height, int *max_height) override; @@ -184,6 +194,11 @@ extern void tui_set_layout (enum tui_layout_type); /* Switch to the next layout. */ extern void tui_next_layout (); +/* Remove some windows from the layout, leaving only the focused + window and the command window; if no window has the focus, then + some other window is chosen to remain. */ +extern void tui_remove_some_windows (); + /* Apply the current layout. */ extern void tui_apply_current_layout (); diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 780d3bae9c0..b93f9f79b38 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -161,28 +161,8 @@ tui_rl_delete_other_windows (int notused1, int notused2) tui_rl_switch_mode (0 /* notused */, 0 /* notused */); if (tui_active) - { - enum tui_layout_type new_layout; - - new_layout = tui_current_layout (); + tui_remove_some_windows (); - /* Kill one window. */ - switch (new_layout) - { - case SRC_COMMAND: - case SRC_DATA_COMMAND: - case SRC_DISASSEM_COMMAND: - default: - new_layout = SRC_COMMAND; - break; - - case DISASSEM_COMMAND: - case DISASSEM_DATA_COMMAND: - new_layout = DISASSEM_COMMAND; - break; - } - tui_set_layout (new_layout); - } return 0; }