[3/3,gdb/tui] Add set tui default-focus first/cmd

Message ID 20230527182809.20569-4-tdevries@suse.de
State New
Headers
Series Add setting for default focus window |

Commit Message

Tom de Vries May 27, 2023, 6:28 p.m. UTC
  Add a new command "set tui default-focus first/cmd" that set the default focus
window.

If set to first, it's the first window in the window list.

If set to cmd, it's the command window.

The default value is first, so the default behaviour is unchanged.

Tested on x86_64-linux.

PR tui/24137
https://sourceware.org/bugzilla/show_bug.cgi?id=24137

Reported-By: Martin Liška <marxin.liska@gmail.com>
---
 gdb/doc/gdb.texinfo  |  6 ++++++
 gdb/tui/tui-layout.c | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)
  

Comments

Eli Zaretskii May 28, 2023, 5:15 a.m. UTC | #1
> Cc: Tom Tromey <tom@tromey.com>
> Date: Sat, 27 May 2023 20:28:09 +0200
> From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
> 
> Add a new command "set tui default-focus first/cmd" that set the default focus
> window.
> 
> If set to first, it's the first window in the window list.
> 
> If set to cmd, it's the command window.
> 
> The default value is first, so the default behaviour is unchanged.
> 
> Tested on x86_64-linux.
> 
> PR tui/24137
> https://sourceware.org/bugzilla/show_bug.cgi?id=24137
> 
> Reported-By: Martin Liška <marxin.liska@gmail.com>
> ---
>  gdb/doc/gdb.texinfo  |  6 ++++++
>  gdb/tui/tui-layout.c | 31 ++++++++++++++++++++++++++++++-
>  2 files changed, 36 insertions(+), 1 deletion(-)

Thanks.

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index d1059e0cb7f..de8b42e99c7 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -30318,6 +30318,12 @@ The default display uses more space for line numbers; the compact
>  display uses only as much space as is needed for the line numbers in
>  the current file.
>  
> +@item set tui default-focus @r{[}first@r{|}cmd@r{]}
> +@kindex set tui default-focus
> +The default TUI window to focus on.  If set to first, it's the first
> +window in the window list.  If set to cmd, it's the command window.
> +The default value is first.

"first" and "cmd" should have the @code or @samp markup.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  
Alexandra Petlanova Hajkova May 30, 2023, 1:42 p.m. UTC | #2
On Sat, May 27, 2023 at 8:28 PM Tom de Vries via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> Add a new command "set tui default-focus first/cmd" that set the default
> focus
> window.
>
> If set to first, it's the first window in the window list.
>
> If set to cmd, it's the command window.
>
> The default value is first, so the default behaviour is unchanged.
>
> Tested on x86_64-linux.
>
> PR tui/24137
> https://sourceware.org/bugzilla/show_bug.cgi?id=24137
>
> Reported-By: Martin Liška <marxin.liska@gmail.com>
> ---
>
I can confirm the patch causes no regressions on ppc64le with Fedora
Rawhide.

>
>
  

Patch

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index d1059e0cb7f..de8b42e99c7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30318,6 +30318,12 @@  The default display uses more space for line numbers; the compact
 display uses only as much space as is needed for the line numbers in
 the current file.
 
+@item set tui default-focus @r{[}first@r{|}cmd@r{]}
+@kindex set tui default-focus
+The default TUI window to focus on.  If set to first, it's the first
+window in the window list.  If set to cmd, it's the command window.
+The default value is first.
+
 @kindex set debug tui
 @item set debug tui @r{[}on|off@r{]}
 Turn on or off display of @value{GDBN} internal debug messages relating
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index ea8b4378d1e..92609e63190 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -46,6 +46,7 @@ 
 #include "gdbsupport/gdb-safe-ctype.h"
 
 static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
+static tui_win_info *tui_get_window_by_name (const std::string &name);
 
 /* The layouts.  */
 static std::vector<std::unique_ptr<tui_layout_split>> layouts;
@@ -64,12 +65,28 @@  static tui_layout_split *asm_regs_layout;
 /* See tui-data.h.  */
 std::vector<tui_win_info *> tui_windows;
 
+/* Choices for "tui default-focus".  */
+static const char *const tui_default_focus_enums[] = {
+  "first",
+  "cmd",
+  NULL
+};
+
+/* Value of "tui default-focus".  */
+static const char *tui_default_focus = "first";
+
 /* See tui-layout.h.  */
 
 struct tui_win_info *
 tui_default_focus_window ()
 {
-  return tui_windows[0];
+  if (strcmp (tui_default_focus, "first") == 0)
+    return tui_windows[0];
+
+  if (strcmp (tui_default_focus, "cmd") == 0)
+    return tui_get_window_by_name ("cmd");
+
+  gdb_assert_not_reached ("");
 }
 
 /* See tui-layout.h.  */
@@ -1347,6 +1364,18 @@  Each WEIGHT is an integer, which holds the relative size\n\
 to be allocated to the window."),
 	   tui_get_cmd_list ());
 
+
+  add_setshow_enum_cmd ("default-focus", no_class, tui_default_focus_enums,
+			&tui_default_focus, _("\
+Set the default focus window"), _("\
+Show the default focus window"), _("\
+This variable controls which TUI window is focused by default:\n\
+   first           first window in the window list\n\
+   cmd             command window"),
+			nullptr,
+			nullptr,
+			tui_get_cmd_set_list (), tui_get_cmd_show_list ());
+
   initialize_layouts ();
   initialize_known_windows ();
 }