[1/3,gdb/tui] Add tui_default_focus_window

Message ID 20230527182809.20569-2-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
  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(-)
  

Comments

Alexandra Hájková May 30, 2023, 1:39 p.m. UTC | #1
On Sat, May 27, 2023 at 8:28 PM Tom de Vries via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> 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.
> ---
>
> I can confirm the patch causes no regressions on ppc64le with Fedora
Rawhide.
  

Patch

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_win_info *> 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<tui_win_info *> new_tui_windows;
   applied_layout->get_windows (&new_tui_windows);
 
+  /* Replace the global list of active windows.  */
+  std::vector<tui_win_info *> 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;