aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-tui.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-09-25 08:27:51 -0600
committerTom Tromey <tromey@adacore.com>2024-11-01 11:06:47 -0600
commit76367d23146136b457b1494285b807437a9fec60 (patch)
tree29cec25266e8d522ba7a135659699542885af03d /gdb/python/py-tui.c
parent893e4fd6231922495175b701a6c44b665e91cd7e (diff)
downloadgdb-76367d23146136b457b1494285b807437a9fec60.zip
gdb-76367d23146136b457b1494285b807437a9fec60.tar.gz
gdb-76367d23146136b457b1494285b807437a9fec60.tar.bz2
Add gdb.events.tui_enabled
This adds a new event source so that Python scripts can track whether or not the TUI is presently enabled. v2 of the patch renames "status" -> "enabled". Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32162 Reviewed-By: Eli Zaretskii <eliz@gnu.org> Reviewed-by: Keith Seitz <keiths@redhat.com>
Diffstat (limited to 'gdb/python/py-tui.c')
-rw-r--r--gdb/python/py-tui.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index afa6f36..09f0a60 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -36,6 +36,9 @@
#include "tui/tui-layout.h"
#include "tui/tui-wingeneral.h"
#include "tui/tui-winsource.h"
+#include "observable.h"
+#include "py-events.h"
+#include "py-event.h"
class tui_py_window;
@@ -616,6 +619,29 @@ PyTypeObject gdbpy_tui_window_object_type =
0, /* tp_alloc */
};
+/* Called when TUI is enabled or disabled. */
+
+static void
+gdbpy_tui_enabled (bool state)
+{
+ gdbpy_enter enter_py;
+
+ if (evregpy_no_listeners_p (gdb_py_events.tui_enabled))
+ return;
+
+ gdbpy_ref<> event_obj = create_event_object (&tui_enabled_event_object_type);
+ if (event_obj == nullptr)
+ {
+ gdbpy_print_stack ();
+ return;
+ }
+
+ gdbpy_ref<> code (PyBool_FromLong (state));
+ if (evpy_add_attribute (event_obj.get (), "enabled", code.get ()) < 0
+ || evpy_emit_event (event_obj.get (), gdb_py_events.tui_enabled) < 0)
+ gdbpy_print_stack ();
+}
+
#endif /* TUI */
/* Initialize this module. */
@@ -627,6 +653,8 @@ gdbpy_initialize_tui ()
gdbpy_tui_window_object_type.tp_new = PyType_GenericNew;
if (gdbpy_type_ready (&gdbpy_tui_window_object_type) < 0)
return -1;
+
+ gdb::observers::tui_enabled.attach (gdbpy_tui_enabled, "py-tui");
#endif /* TUI */
return 0;