+2020-09-24  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  Hannes Domani  <ssbssa@yahoo.de>
 
        * nat/windows-nat.c (handle_exception): Handle 64bit breakpoints
 
+2020-09-24  Tom Tromey  <tromey@adacore.com>
+
+       PR tui/26638:
+       * gdb.tui/list.exp: Check output of "focus next".
+
 2020-09-23  Tom Tromey  <tom@tromey.com>
 
        * gdb.dwarf2/intbits.exp: New file.
 
 # The following 'focus next' must be immediately after 'list main' to
 # ensure that GDB has a valid idea of what is currently focused.
 Term::command "focus next"
+Term::check_contents "focus next" "Focus set to cmd window"
 
   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;
 }
 
 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;
 }
 
 
     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 ()
   {