From 0f6a69947891fc448c37e944d6c3e266621d35a8 Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Fri, 27 Jan 2023 16:19:45 -0800 Subject: 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. --- gdb/tui/tui-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gdb/tui/tui-io.c') 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 } -- cgit v1.1