Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org, Tom Tromey <tromey@adacore.com>
Subject: Re: [PATCH] Don't let TUI focus on locator
Date: Wed, 23 Sep 2020 13:50:28 -0600	[thread overview]
Message-ID: <877dskp917.fsf@tromey.com> (raw)
In-Reply-To: <1b3329ea-97c0-c379-d343-e891a337244b@simark.ca> (Simon Marchi's message of "Wed, 23 Sep 2020 15:10:04 -0400")

Simon> Instead of hard-coding here which windows can receive focus, how about
Simon> having a tui_win_info virtual method "is_focusable", where the default
Simon> implementation returns true, and tui_locator_window's implementation
Simon> returns false?  The code in tui_next_win / tui_prev_win would return the
Simon> next / prev focusable window.

Let me know what you think of this.

Tom

commit adac0583ca49653e98630757599eee20faca4b33
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Sep 23 12:57:19 2020 -0600

    Don't let TUI focus on locator
    
    PR tui/26638 notes that the C-x o binding can put the focus on the
    locator window.  However, this is not useful and did not happen
    historically.  This patch changes the TUI to skip this window when
    switching focus.
    
    gdb/ChangeLog
    2020-09-23  Tom Tromey  <tromey@adacore.com>
    
            PR tui/26638:
            * tui/tui-stack.h (struct tui_locator_window) <can_focus>: New
            method.
            * tui/tui-data.h (struct tui_win_info) <can_focus>: New method.
            * tui/tui-data.c (tui_next_win): Exclude non-focusable windows.
            (tui_prev_win): Rewrite.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 241f3e70271..96fddbcd6e7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2020-09-23  Tom Tromey  <tromey@adacore.com>
+
+	PR tui/26638:
+	* tui/tui-stack.h (struct tui_locator_window) <can_focus>: New
+	method.
+	* tui/tui-data.h (struct tui_win_info) <can_focus>: New method.
+	* tui/tui-data.c (tui_next_win): Exclude non-focusable windows.
+	(tui_prev_win): Rewrite.
+
 2020-09-23  Tom Tromey  <tom@tromey.com>
 
 	PR symtab/25470:
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 8f7d257e945..d475d031065 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -113,9 +113,18 @@ tui_next_win (struct tui_win_info *cur_win)
   auto iter = std::find (tui_windows.begin (), tui_windows.end (), cur_win);
   gdb_assert (iter != tui_windows.end ());
 
-  ++iter;
-  if (iter == tui_windows.end ())
-    return tui_windows[0];
+  gdb_assert (cur_win->can_focus ());
+  /* This won't loop forever since we can't have just an un-focusable
+     window.  */
+  while (true)
+    {
+      ++iter;
+      if (iter == tui_windows.end ())
+	iter = tui_windows.begin ();
+      if ((*iter)->can_focus ())
+	break;
+    }
+
   return *iter;
 }
 
@@ -125,12 +134,21 @@ tui_next_win (struct tui_win_info *cur_win)
 struct tui_win_info *
 tui_prev_win (struct tui_win_info *cur_win)
 {
-  auto iter = std::find (tui_windows.begin (), tui_windows.end (), cur_win);
-  gdb_assert (iter != tui_windows.end ());
+  auto iter = std::find (tui_windows.rbegin (), tui_windows.rend (), cur_win);
+  gdb_assert (iter != tui_windows.rend ());
+
+  gdb_assert (cur_win->can_focus ());
+  /* This won't loop forever since we can't have just an un-focusable
+     window.  */
+  while (true)
+    {
+      ++iter;
+      if (iter == tui_windows.rend ())
+	iter = tui_windows.rbegin ();
+      if ((*iter)->can_focus ())
+	break;
+    }
 
-  if (iter == tui_windows.begin ())
-    return tui_windows.back ();
-  --iter;
   return *iter;
 }
 
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 5e7a12293c9..d61bfc7dff8 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -99,6 +99,12 @@ struct tui_win_info
     return handle != nullptr;
   }
 
+  /* Return true if this window can accept the focus.  */
+  virtual bool can_focus () const
+  {
+    return true;
+  }
+
   /* Disable output until the next call to doupdate.  */
   void no_refresh ()
   {
diff --git a/gdb/tui/tui-stack.h b/gdb/tui/tui-stack.h
index 9ff57b1ba73..0e5916f0ce3 100644
--- a/gdb/tui/tui-stack.h
+++ b/gdb/tui/tui-stack.h
@@ -52,6 +52,11 @@ struct tui_locator_window : public tui_win_info
     return false;
   }
 
+  bool can_focus () const override
+  {
+    return false;
+  }
+
   void rerender () override;
 
   /* Update the locator, with the provided arguments.

  reply	other threads:[~2020-09-23 19:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 18:59 Tom Tromey
2020-09-23 19:10 ` Simon Marchi
2020-09-23 19:50   ` Tom Tromey [this message]
2020-09-23 19:57     ` Simon Marchi
2020-09-24 18:27       ` Tom Tromey
2020-09-24 18:33         ` Simon Marchi
2020-09-24 19:02           ` 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=877dskp917.fsf@tromey.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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