aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorMatthew "strager" Glazar <strager.nds@gmail.com>2023-01-27 16:19:45 -0800
committerPedro Alves <pedro@palves.net>2023-09-20 16:35:36 +0100
commit0f6a69947891fc448c37e944d6c3e266621d35a8 (patch)
tree24fabc6ae9aeb340b42ae5d6a9c495111d7a71a6 /gdb/tui
parent973db6fae304c2bcafff5f169610f663adc9e817 (diff)
downloadgdb-0f6a69947891fc448c37e944d6c3e266621d35a8.zip
gdb-0f6a69947891fc448c37e944d6c3e266621d35a8.tar.gz
gdb-0f6a69947891fc448c37e944d6c3e266621d35a8.tar.bz2
gdb/tui: add 'set tui mouse-events off' to restore mouse selection
Rationale: I use the mouse with my terminal to select and copy text. In gdb, I use the mouse to select a function name to set a breakpoint, or a variable name to print, for example. When gdb is compiled with ncurses mouse support, gdb's TUI mode intercepts mouse events. Left-clicking and dragging, which would normally select text, seems to do nothing. This means I cannot select text using my mouse anymore. This makes it harder to set breakpoints, print variables, etc. Solution: I tried to fix this issue by editing the 'mousemask' call to only enable buttons 4 and 5. However, this still caused my terminal (gnome-terminal) to not allow text to be selected. The only way I could make it work is by calling 'mousemask (0, NULL);'. But doing so disables the mouse code entirely, which other people might want. I therefore decided to make a setting in gdb called 'tui mouse-events'. If enabled (the default), the behavior is as it is now: terminal mouse events are given to gdb, disabling the terminal's default behavior. If disabled (opt-in), the behavior is as it was before the year 2020: terminal mouse events are not given to gdb, therefore the mouse can be used to select and copy text. Notes: I am not attached to the setting name or its description. Feel free to suggest better wording. Testing: I tested this change in gnome-terminal by performing the following steps manually: 1. Run: gdb --args ./myprogram 2. Enable TUI: press ctrl-x ctrl-a 3. Click and drag text with the mouse. Observe no selection. 4. Input: set tui mouse-events off 5. Click and drag text with the mouse. Observe that selection works now. 6. Input: set tui mouse-events on. 7. Click and drag text with the mouse. Observe no selection.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-io.c3
-rw-r--r--gdb/tui/tui-win.c22
-rw-r--r--gdb/tui/tui-win.h3
3 files changed, 27 insertions, 1 deletions
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 8cb68d1..b8954af 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -657,7 +657,8 @@ static void
tui_prep_terminal (int notused1)
{
#ifdef NCURSES_MOUSE_VERSION
- mousemask (ALL_MOUSE_EVENTS, NULL);
+ if (tui_enable_mouse)
+ mousemask (ALL_MOUSE_EVENTS, NULL);
#endif
}
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 93cf45e..a0a1233 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -872,6 +872,17 @@ tui_show_compact_source (struct ui_file *file, int from_tty,
gdb_printf (file, _("TUI source window compactness is %s.\n"), value);
}
+bool tui_enable_mouse = true;
+
+/* Implement 'show tui mouse-events'. */
+
+static void
+show_tui_mouse_events (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ gdb_printf (file, _("TUI mouse events are %s.\n"), value);
+}
+
/* Set the tab width of the specified window. */
static void
tui_set_tab_width_command (const char *arg, int from_tty)
@@ -1254,6 +1265,17 @@ in a compact form. The compact form uses less horizontal space."),
tui_set_compact_source, tui_show_compact_source,
&tui_setlist, &tui_showlist);
+ add_setshow_boolean_cmd ("mouse-events", class_tui,
+ &tui_enable_mouse, _("\
+Set whether TUI mode handles mouse clicks."), _("\
+Show whether TUI mode handles mouse clicks."), _("\
+When on (default), mouse clicks control the TUI and can be accessed by Python\n\
+extensions. When off, mouse clicks are handled by the terminal, enabling\n\
+terminal-native text selection."),
+ nullptr,
+ show_tui_mouse_events,
+ &tui_setlist, &tui_showlist);
+
add_setshow_boolean_cmd ("tui-current-position", class_maintenance,
&style_tui_current_position, _("\
Set whether to style text highlighted by the TUI's current position indicator."),
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index 3d35f1d..c0a7732 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -51,6 +51,9 @@ struct cmd_list_element **tui_get_cmd_list (void);
/* Whether compact source display should be used. */
extern bool compact_source;
+/* Whether the TUI should intercept terminal mouse events. */
+extern bool tui_enable_mouse;
+
/* Whether to style the source and assembly code highlighted by the TUI's
current position indicator. */
extern bool style_tui_current_position;