public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Update TUI window title when changed
@ 2023-06-29 17:32 Tom Tromey
  2023-07-10 14:56 ` Andrew Burgess
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2023-06-29 17:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I wrote a TUI window in Python, and I noticed that setting its title
did not result in a refresh, so the new title did not appear.  This
patch corrects this problem.
---
 gdb/python/py-tui.c                     |  2 +-
 gdb/testsuite/gdb.python/tui-window.exp |  4 ++++
 gdb/testsuite/gdb.python/tui-window.py  |  5 +++++
 gdb/tui/tui-data.c                      | 11 +++++++++++
 gdb/tui/tui-data.h                      |  4 ++++
 5 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index 84a435ead68..c52b04f9a51 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -531,7 +531,7 @@ gdbpy_tui_set_title (PyObject *self, PyObject *newvalue, void *closure)
   if (value == nullptr)
     return -1;
 
-  win->window->title = value.get ();
+  win->window->set_title (value.get ());
   return 0;
 }
 
diff --git a/gdb/testsuite/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp
index 9b5d17c35d4..defc8c68b25 100644
--- a/gdb/testsuite/gdb.python/tui-window.exp
+++ b/gdb/testsuite/gdb.python/tui-window.exp
@@ -54,6 +54,10 @@ Term::check_contents "error message after trying to delete title" \
 Term::check_contents "title is unchanged" \
     "This Is The Title"
 
+Term::command "python change_window_title ()"
+Term::check_contents "test new title" \
+    "New Title"
+
 Term::resize 51 51
 # Remember that a resize request actually does two resizes...
 Term::check_contents "Window was updated" "Test: 2"
diff --git a/gdb/testsuite/gdb.python/tui-window.py b/gdb/testsuite/gdb.python/tui-window.py
index 401cb5197ff..dc72cc4c0f7 100644
--- a/gdb/testsuite/gdb.python/tui-window.py
+++ b/gdb/testsuite/gdb.python/tui-window.py
@@ -53,4 +53,9 @@ def failwin(win):
     raise RuntimeError("Whoops")
 
 
+# Change the title of the window.
+def change_window_title():
+    the_window.win.title = "New Title"
+
+
 gdb.register_window_type("fail", failwin)
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index 0daed32b6e6..abd2ec2b5fd 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -152,6 +152,17 @@ tui_prev_win (struct tui_win_info *cur_win)
   return *iter;
 }
 
+/* See tui-data.h.  */
+
+void
+tui_win_info::set_title (const char *new_title)
+{
+  if (title != new_title)
+    {
+      title = new_title;
+      check_and_display_highlight_if_needed ();
+    }
+}
 
 void
 tui_win_info::rerender ()
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index c92e85c9da1..030ce2a5438 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -146,6 +146,10 @@ struct tui_win_info
 
   void check_and_display_highlight_if_needed ();
 
+  /* A helper function to change the title and then redraw the
+     surrounding box, if needed.  */
+  void set_title (const char *new_title);
+
   /* Window handle.  */
   std::unique_ptr<WINDOW, curses_deleter> handle;
   /* Window width.  */
-- 
2.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-15 10:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-29 17:32 [PATCH] Update TUI window title when changed Tom Tromey
2023-07-10 14:56 ` Andrew Burgess
2023-07-10 19:28   ` Tom Tromey
2023-07-15 10:41     ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).