public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCHv2 1/2] Initial TUI mouse support
       [not found] <20210529142636.11432-1-ssbssa.ref@yahoo.de>
@ 2021-05-29 14:26 ` Hannes Domani
  2021-05-29 14:26   ` [PATCHv2 2/2] Forward mouse click to python TUI window Hannes Domani
  2021-06-02 18:48   ` [PATCHv2 1/2] Initial TUI mouse support Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Hannes Domani @ 2021-05-29 14:26 UTC (permalink / raw)
  To: gdb-patches

Implements an overridable tui_win_info::click method whose arguments
are the mouse coordinates inside the specific window, and the mouse
button clicked.

And if the curses implementation supports 5 buttons, the 4th and 5th
buttons are used for scrolling.

2021-05-29  Hannes Domani  <ssbssa@yahoo.de>

	* ser-mingw.c (console_select_thread): Handle MOUSE_EVENT.
	* tui/tui-data.h (struct tui_win_info): Add click function.
	* tui/tui-io.c (tui_prep_terminal): Enable mouse events.
	(tui_deprep_terminal): Disable mouse events.
	(tui_dispatch_ctrl_char): Handle KEY_MOUSE.
	* tui/tui.c (tui_disable): Disable mouse events.
---
Should there be a configure option for this at build time?
I don't know if the mousemask/getmouse functions are available for
all curses variants, so I would imagine an option --enable-mouse:
- yes -> error if getmouse can't be linked
- no -> just disable
- auto -> enable if getmouse can be linked

v2:
- Added ChangeLog.
---
 gdb/ser-mingw.c    |  5 +++++
 gdb/tui/tui-data.h |  5 +++++
 gdb/tui/tui-io.c   | 32 ++++++++++++++++++++++++++++++++
 gdb/tui/tui.c      |  2 ++
 4 files changed, 44 insertions(+)

diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index 043bb50b577..2bad51310f6 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -599,6 +599,11 @@ console_select_thread (void *arg)
 		  break;
 		}
 	    }
+	  else if (record.EventType == MOUSE_EVENT)
+	    {
+	      SetEvent (state->read_event);
+	      break;
+	    }
 
 	  /* Otherwise discard it and wait again.  */
 	  ReadConsoleInput (h, &record, 1, &n_records);
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index b4d788dd0a4..74a8b78395b 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -137,6 +137,11 @@ struct tui_win_info
     return true;
   }
 
+  /* Called for each mouse click inside this window.  */
+  virtual void click (int mouse_x, int mouse_y, int mouse_button)
+  {
+  }
+
   void check_and_display_highlight_if_needed ();
 
   /* Window handle.  */
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index a2be4d4353e..7787789f0c7 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -33,6 +33,7 @@
 #include "tui/tui-wingeneral.h"
 #include "tui/tui-file.h"
 #include "tui/tui-out.h"
+#include "tui/tui-source.h"
 #include "ui-out.h"
 #include "cli-out.h"
 #include <fcntl.h>
@@ -639,6 +640,7 @@ tui_redisplay_readline (void)
 static void
 tui_prep_terminal (int notused1)
 {
+  mousemask (ALL_MOUSE_EVENTS, NULL);
 }
 
 /* Readline callback to restore the terminal.  It is called once each
@@ -646,6 +648,7 @@ tui_prep_terminal (int notused1)
 static void
 tui_deprep_terminal (void)
 {
+  mousemask (0, NULL);
 }
 
 #ifdef TUI_USE_PIPE_FOR_READLINE
@@ -978,6 +981,35 @@ tui_dispatch_ctrl_char (unsigned int ch)
     case KEY_LEFT:
       win_info->right_scroll (1);
       break;
+    case KEY_MOUSE:
+	{
+	  MEVENT mev;
+	  if (getmouse (&mev) != OK)
+	    break;
+
+	  for (tui_win_info *wi : all_tui_windows ())
+	    if (mev.x > wi->x && mev.x < wi->x + wi->width - 1
+		&& mev.y > wi->y && mev.y < wi->y + wi->height - 1)
+	      {
+		if ((mev.bstate & BUTTON1_CLICKED)
+		    || (mev.bstate & BUTTON2_CLICKED)
+		    || (mev.bstate & BUTTON3_CLICKED))
+		  {
+		    int button = (mev.bstate & BUTTON1_CLICKED) ? 1
+		      : (mev.bstate & BUTTON2_CLICKED) ? 2
+		      : 3;
+		    wi->click (mev.x - wi->x - 1, mev.y - wi->y - 1, button);
+		  }
+#ifdef BUTTON5_PRESSED
+		else if (mev.bstate & BUTTON4_PRESSED)
+		  wi->backward_scroll (3);
+		else if (mev.bstate & BUTTON5_PRESSED)
+		  wi->forward_scroll (3);
+#endif
+		break;
+	      }
+	}
+      break;
     case '\f':
       break;
     default:
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index af92b2a8042..a2654a2e5a4 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -508,6 +508,8 @@ tui_disable (void)
   rl_startup_hook = 0;
   rl_already_prompted = 0;
 
+  mousemask (0, NULL);
+
   /* Leave curses and restore previous gdb terminal setting.  */
   endwin ();
 
-- 
2.31.1


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

* [PATCHv2 2/2] Forward mouse click to python TUI window
  2021-05-29 14:26 ` [PATCHv2 1/2] Initial TUI mouse support Hannes Domani
@ 2021-05-29 14:26   ` Hannes Domani
  2021-05-29 14:49     ` Eli Zaretskii
  2021-06-02 18:49     ` Tom Tromey
  2021-06-02 18:48   ` [PATCHv2 1/2] Initial TUI mouse support Tom Tromey
  1 sibling, 2 replies; 5+ messages in thread
From: Hannes Domani @ 2021-05-29 14:26 UTC (permalink / raw)
  To: gdb-patches

If the TUI window object implements the click method, it is called for each
mouse click event in this window.

gdb/ChangeLog:

2021-05-29  Hannes Domani  <ssbssa@yahoo.de>

	* python/py-tui.c (class tui_py_window): Add click function.
	(tui_py_window::click): Likewise.

gdb/doc/ChangeLog:

2021-05-29  Hannes Domani  <ssbssa@yahoo.de>

	* python.texi (TUI Windows In Python): Document Window.click.
---
v2:
- Added ChangeLog.
- Specify in the documentation that mouse coordinates are 0-based.
---
 gdb/doc/python.texi |  6 ++++++
 gdb/python/py-tui.c | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 0d8f480e472..445ddd905bf 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -6022,6 +6022,12 @@ contents.  A positive argument should cause the viewport to move down,
 and so the content should appear to move up.
 @end defun
 
+@defun Window.click (@var{x}, @var{y}, @var{button})
+This is called on a mouse click in this window.  @var{x} and @var{y} are
+the mouse coordinates inside the window (0-based), and @var{button}
+specifies which mouse button was used.
+@end defun
+
 @node Python Auto-loading
 @subsection Python Auto-loading
 @cindex Python auto-loading
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index 97e9de7a00c..8dfed9d341f 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -101,6 +101,8 @@ class tui_py_window : public tui_win_info
       tui_win_info::refresh_window ();
   }
 
+  void click (int mouse_x, int mouse_y, int mouse_button) override;
+
   /* Erase and re-box the window.  */
   void erase ()
   {
@@ -229,6 +231,21 @@ tui_py_window::do_scroll_vertical (int num_to_scroll)
     }
 }
 
+void
+tui_py_window::click (int mouse_x, int mouse_y, int mouse_button)
+{
+  gdbpy_enter enter_py (get_current_arch (), current_language);
+
+  if (PyObject_HasAttrString (m_window.get (), "click"))
+    {
+      gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "click",
+					       "iii", mouse_x, mouse_y,
+					       mouse_button));
+      if (result == nullptr)
+	gdbpy_print_stack ();
+    }
+}
+
 void
 tui_py_window::output (const char *text, bool full_window)
 {
-- 
2.31.1


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

* Re: [PATCHv2 2/2] Forward mouse click to python TUI window
  2021-05-29 14:26   ` [PATCHv2 2/2] Forward mouse click to python TUI window Hannes Domani
@ 2021-05-29 14:49     ` Eli Zaretskii
  2021-06-02 18:49     ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2021-05-29 14:49 UTC (permalink / raw)
  To: Hannes Domani; +Cc: gdb-patches

> Date: Sat, 29 May 2021 16:26:36 +0200
> From: Hannes Domani via Gdb-patches <gdb-patches@sourceware.org>
> 
> If the TUI window object implements the click method, it is called for each
> mouse click event in this window.
> 
> gdb/ChangeLog:
> 
> 2021-05-29  Hannes Domani  <ssbssa@yahoo.de>
> 
> 	* python/py-tui.c (class tui_py_window): Add click function.
> 	(tui_py_window::click): Likewise.
> 
> gdb/doc/ChangeLog:
> 
> 2021-05-29  Hannes Domani  <ssbssa@yahoo.de>
> 
> 	* python.texi (TUI Windows In Python): Document Window.click.

OK for the documentation part.

Thanks.

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

* Re: [PATCHv2 1/2] Initial TUI mouse support
  2021-05-29 14:26 ` [PATCHv2 1/2] Initial TUI mouse support Hannes Domani
  2021-05-29 14:26   ` [PATCHv2 2/2] Forward mouse click to python TUI window Hannes Domani
@ 2021-06-02 18:48   ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2021-06-02 18:48 UTC (permalink / raw)
  To: Hannes Domani via Gdb-patches

>>>>> "Hannes" == Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> writes:

Hannes> Implements an overridable tui_win_info::click method whose arguments
Hannes> are the mouse coordinates inside the specific window, and the mouse
Hannes> button clicked.

Hannes> And if the curses implementation supports 5 buttons, the 4th and 5th
Hannes> buttons are used for scrolling.

Thank you for doing this.  I have a few minor comments.

Hannes> Should there be a configure option for this at build time?
Hannes> I don't know if the mousemask/getmouse functions are available for
Hannes> all curses variants, so I would imagine an option --enable-mouse:
Hannes> - yes -> error if getmouse can't be linked
Hannes> - no -> just disable
Hannes> - auto -> enable if getmouse can be linked

I think it's fine to move forward, and if we have problems with it, we
can add a configure check for 'mousemask' and use that to disable the
new code.

The ncurses man page says we could check NCURSES_MOUSE_VERSION to see if
this is available.  So maybe new configure code isn't even needed.

       The feature macro NCURSES_MOUSE_VERSION is provided so the preprocessor
       can be used to test whether these features are present.

Hannes> +  /* Called for each mouse click inside this window.  */
Hannes> +  virtual void click (int mouse_x, int mouse_y, int mouse_button)
Hannes> +  {

I think it would be nice if this comment documented the meaning of x/y
(are they window- or terminal-relative?  And 0- or 1-based?) and also
the possible/typical values of mouse_button (0- or 1-based?).

Hannes> diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
Hannes> index a2be4d4353e..7787789f0c7 100644
Hannes> --- a/gdb/tui/tui-io.c
Hannes> +++ b/gdb/tui/tui-io.c
Hannes> @@ -33,6 +33,7 @@
Hannes>  #include "tui/tui-wingeneral.h"
Hannes>  #include "tui/tui-file.h"
Hannes>  #include "tui/tui-out.h"
Hannes> +#include "tui/tui-source.h"

Why was this needed?

Hannes> +		if ((mev.bstate & BUTTON1_CLICKED)
Hannes> +		    || (mev.bstate & BUTTON2_CLICKED)
Hannes> +		    || (mev.bstate & BUTTON3_CLICKED))

gdb style would use a '!= 0' after each test.

Hannes> +		  {
Hannes> +		    int button = (mev.bstate & BUTTON1_CLICKED) ? 1
Hannes> +		      : (mev.bstate & BUTTON2_CLICKED) ? 2
Hannes> +		      : 3;

The right-hand-side here would normally have an extra layer of () so
that the continuation lines are indented.  Also it would be good to
reformat that so the "?..:" parts line up more clearly.

thanks,
Tom

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

* Re: [PATCHv2 2/2] Forward mouse click to python TUI window
  2021-05-29 14:26   ` [PATCHv2 2/2] Forward mouse click to python TUI window Hannes Domani
  2021-05-29 14:49     ` Eli Zaretskii
@ 2021-06-02 18:49     ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2021-06-02 18:49 UTC (permalink / raw)
  To: Hannes Domani via Gdb-patches

>>>>> "Hannes" == Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> writes:

Hannes> If the TUI window object implements the click method, it is called for each
Hannes> mouse click event in this window.

Thank you for doing this.

Hannes> +@defun Window.click (@var{x}, @var{y}, @var{button})
Hannes> +This is called on a mouse click in this window.  @var{x} and @var{y} are
Hannes> +the mouse coordinates inside the window (0-based), and @var{button}
Hannes> +specifies which mouse button was used.
Hannes> +@end defun

I think documenting that the button is 1-based would be good.

Otherwise, this looks good to me.

Tom

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

end of thread, other threads:[~2021-06-02 18:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210529142636.11432-1-ssbssa.ref@yahoo.de>
2021-05-29 14:26 ` [PATCHv2 1/2] Initial TUI mouse support Hannes Domani
2021-05-29 14:26   ` [PATCHv2 2/2] Forward mouse click to python TUI window Hannes Domani
2021-05-29 14:49     ` Eli Zaretskii
2021-06-02 18:49     ` Tom Tromey
2021-06-02 18:48   ` [PATCHv2 1/2] Initial TUI mouse support Tom Tromey

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).