Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 05/24] Reimplement TUI "C-x 1" binding
Date: Sat, 04 Jan 2020 18:34:00 -0000	[thread overview]
Message-ID: <20200104183410.17114-6-tom@tromey.com> (raw)
In-Reply-To: <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  <tom@tromey.com>

	* tui/tui.c (tui_rl_delete_other_windows): Call
	tui_remove_some_windows.
	* tui/tui-layout.h (class tui_layout_base) <remove_windows>:
	Declare method.
	(class tui_layout_window) <remove_windows>: New method.
	(class tui_layout_split) <remove_windows>: 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;
 }
 
-- 
2.17.2


  parent reply	other threads:[~2020-01-04 18:34 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-04 18:34 [PATCH 00/24] Horizontal TUI layout + windows in Python Tom Tromey
2020-01-04 18:34 ` [PATCH 16/24] TUI windows do not need to store their type Tom Tromey
2020-01-04 18:34 ` [PATCH 03/24] Fix latent display bug in tui_data_window Tom Tromey
2020-01-04 18:34 ` Tom Tromey [this message]
2020-01-04 18:34 ` [PATCH 13/24] Reimplement tui_next_win and tui_prev_win Tom Tromey
2020-01-04 18:34 ` [PATCH 24/24] Fix cast in TUI_DISASM_WIN Tom Tromey
2020-01-04 18:34 ` [PATCH 18/24] Remove tui_set_win_focus_to Tom Tromey
2020-01-04 18:34 ` [PATCH 22/24] Use error_no_arg in TUI Tom Tromey
2020-01-04 18:34 ` [PATCH 08/24] Add the "tui new-layout" command Tom Tromey
2020-01-04 18:44   ` Eli Zaretskii
2020-01-04 18:34 ` [PATCH 14/24] Handle ambiguity in tui_partial_win_by_name Tom Tromey
2020-01-04 18:34 ` [PATCH 23/24] Add "usage" text to all TUI command help Tom Tromey
2020-01-04 18:34 ` [PATCH 07/24] Remove hard-coded TUI layouts Tom Tromey
2020-01-04 18:34 ` [PATCH 01/24] Use TUI_DISASM_WIN instead of tui_win_list array Tom Tromey
2020-01-04 18:34 ` [PATCH 21/24] Make some tui_source_window_base members "protected" Tom Tromey
2020-01-04 18:34 ` [PATCH 09/24] Allow TUI sub-layouts in "new-layout" command Tom Tromey
2020-01-04 18:34 ` [PATCH 02/24] Simplify tui_add_win_to_layout Tom Tromey
2020-01-04 18:34 ` [PATCH 15/24] Remove tui_delete_invisible_windows and tui_make_all_invisible Tom Tromey
2020-01-04 18:34 ` [PATCH 19/24] Remove the TUI annotation hack Tom Tromey
2020-01-04 18:34 ` [PATCH 12/24] Change TUI window iteration Tom Tromey
2020-01-04 18:34 ` [PATCH 11/24] Add horizontal splitting to TUI layout Tom Tromey
2020-01-04 18:47   ` Eli Zaretskii
2020-01-04 18:34 ` [PATCH 06/24] Reimplement "tui reg" command Tom Tromey
2020-01-04 18:34 ` [PATCH 04/24] Simplify TUI C-x 2 binding Tom Tromey
2020-01-04 18:34 ` [PATCH 10/24] Change return type of tui_layout_base::adjust_size Tom Tromey
2020-01-04 18:34 ` [PATCH 20/24] Allow TUI windows in Python Tom Tromey
2020-01-04 18:57   ` Eli Zaretskii
2020-02-22 19:57     ` Tom Tromey
2020-02-22 20:18       ` Eli Zaretskii
2020-03-10 22:23   ` Simon Marchi
2020-03-11  0:23     ` Tom Tromey
2020-03-11  4:47       ` Simon Marchi
2020-03-11  5:07         ` Simon Marchi
2020-03-11 18:05         ` Tom Tromey
2020-01-04 18:54 ` [PATCH 17/24] Change how TUI windows are instantiated Tom Tromey
2020-02-22 20:22 ` [PATCH 00/24] Horizontal TUI layout + windows in Python Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200104183410.17114-6-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox