[3/3] Add setting to enable/disable TUI mouse handling

Message ID 20210607163003.621-3-ssbssa@yahoo.de
State New
Headers show
Series
  • [1/3] Refactor keypad calls to tui_set_win_focus_to
Related show

Commit Message

Simon Marchi via Gdb-patches June 7, 2021, 4:30 p.m.
Useful if the mouse events don't work correctly on a system, or the user just
doesn't need them.

gdb/ChangeLog:

2021-06-07  Hannes Domani  <ssbssa@yahoo.de>

	* tui/tui-data.c (tui_set_win_focus_to): Handle mouse setting.
	* tui/tui-io.c (tui_prep_terminal): Likewise.
	* tui/tui-win.c (tui_mouse): New global.
	(tui_set_mouse, tui_show_mouse_function): New functions.
	(_initialize_tui_win): Add mouse setting.
	* tui/tui-win.h (tui_mouse): Declare.

gdb/doc/ChangeLog:

2021-06-07  Hannes Domani  <ssbssa@yahoo.de>

	* gdb.texinfo (TUI Configuration): Document mouse setting.
---
 gdb/doc/gdb.texinfo |  4 ++++
 gdb/tui/tui-data.c  |  3 ++-
 gdb/tui/tui-io.c    |  2 +-
 gdb/tui/tui-win.c   | 36 ++++++++++++++++++++++++++++++++++++
 gdb/tui/tui-win.h   |  3 +++
 5 files changed, 46 insertions(+), 2 deletions(-)

-- 
2.31.1

Comments

Simon Marchi via Gdb-patches June 7, 2021, 4:49 p.m. | #1
> Date: Mon,  7 Jun 2021 18:30:03 +0200

> From: Hannes Domani via Gdb-patches <gdb-patches@sourceware.org>

> 

> Useful if the mouse events don't work correctly on a system, or the user just

> doesn't need them.

> 

> gdb/ChangeLog:

> 

> 2021-06-07  Hannes Domani  <ssbssa@yahoo.de>

> 

> 	* tui/tui-data.c (tui_set_win_focus_to): Handle mouse setting.

> 	* tui/tui-io.c (tui_prep_terminal): Likewise.

> 	* tui/tui-win.c (tui_mouse): New global.

> 	(tui_set_mouse, tui_show_mouse_function): New functions.

> 	(_initialize_tui_win): Add mouse setting.

> 	* tui/tui-win.h (tui_mouse): Declare.

> 

> gdb/doc/ChangeLog:

> 

> 2021-06-07  Hannes Domani  <ssbssa@yahoo.de>

> 

> 	* gdb.texinfo (TUI Configuration): Document mouse setting.


OK for the documentation part.

Patch

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 90d827a50e7..76d6bc8d321 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -28909,6 +28909,10 @@  The default display uses more space for line numbers and starts the
 source text at the next tab stop; the compact display uses only as
 much space as is needed for the line numbers in the current file, and
 only a single space to separate the line numbers from the source.
+
+@item set tui mouse @r{[}on@r{|}off@r{]}
+@kindex set tui mouse
+Set whether the TUI handles mouse events.
 @end table
 
 Note that the colors of the TUI borders can be controlled using the
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index e6452386628..43538766857 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -78,7 +78,8 @@  tui_set_win_focus_to (struct tui_win_info *win_info)
 #ifdef NCURSES_MOUSE_VERSION
       /* The mouse events only work with enabled keypad, so enable them
 	 accordingly.  */
-      mousemask (win_info != TUI_CMD_WIN ? ALL_MOUSE_EVENTS : 0, NULL);
+      mousemask ((tui_mouse && win_info != TUI_CMD_WIN
+		  ? ALL_MOUSE_EVENTS : 0), NULL);
 #endif
     }
 }
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 4570e55231b..075b4fa58c8 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -640,7 +640,7 @@  static void
 tui_prep_terminal (int notused1)
 {
 #ifdef NCURSES_MOUSE_VERSION
-  if (tui_win_with_focus () != TUI_CMD_WIN)
+  if (tui_mouse && tui_win_with_focus () != TUI_CMD_WIN)
     mousemask (ALL_MOUSE_EVENTS, NULL);
 #endif
 }
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 094b503eae8..2211f987fc4 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -822,6 +822,34 @@  tui_show_compact_source (struct ui_file *file, int from_tty,
   printf_filtered (_("TUI source window compactness is %s.\n"), value);
 }
 
+/* See tui-win.h.  */
+
+bool tui_mouse = false;
+
+/* Callback for "set tui mouse".  */
+
+static void
+tui_set_mouse (const char *ignore, int from_tty,
+	       struct cmd_list_element *c)
+{
+#ifndef NCURSES_MOUSE_VERSION
+  if (tui_mouse)
+    {
+      tui_mouse = false;
+      error (_("The curses library does not provide mouse events."));
+    }
+#endif
+}
+
+/* Callback for "show tui mouse".  */
+
+static void
+tui_show_mouse_function (struct ui_file *file, int from_tty,
+			 struct cmd_list_element *c, const char *value)
+{
+  printf_filtered (_("Handling of mouse events in TUI is %s.\n"), value);
+}
+
 /* Set the tab width of the specified window.  */
 static void
 tui_set_tab_width_command (const char *arg, int from_tty)
@@ -1119,6 +1147,14 @@  the line numbers and uses less horizontal space."),
 			   tui_set_compact_source, tui_show_compact_source,
 			   &tui_setlist, &tui_showlist);
 
+  add_setshow_boolean_cmd ("mouse", class_tui,
+			   &tui_mouse, _("\
+Set whether the TUI handles mouse events."), _("\
+Show whether the TUI handles mouse events."),
+			   nullptr,
+			   tui_set_mouse, tui_show_mouse_function,
+			   &tui_setlist, &tui_showlist);
+
   tui_border_style.changed.attach (tui_rehighlight_all, "tui-win");
   tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win");
 }
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index e9da9b98477..f771ec87400 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -51,4 +51,7 @@  struct cmd_list_element **tui_get_cmd_list (void);
 /* Whether compact source display should be used.  */
 extern bool compact_source;
 
+/* Whether the TUI handles mouse events.  */
+extern bool tui_mouse;
+
 #endif /* TUI_TUI_WIN_H */