[01/22] Initial TUI mouse support

Message ID 20210306173417.21528-2-ssbssa@yahoo.de
State Superseded
Headers show
Series
  • [01/22] Initial TUI mouse support
Related show

Commit Message

Mike Frysinger via Gdb-patches March 6, 2021, 5:33 p.m.
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.
---
 gdb/ser-mingw.c    |  5 +++++
 gdb/tui/tui-data.h |  4 ++++
 gdb/tui/tui-io.c   | 32 ++++++++++++++++++++++++++++++++
 gdb/tui/tui.c      |  2 ++
 4 files changed, 43 insertions(+)

-- 
2.30.1

Comments

Tom Tromey March 11, 2021, 5:32 p.m. | #1
>>>>> "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.

Thank you.  This is a very welcome development.

I won't comment on tests or comments in the code.

Hannes> +#ifdef BUTTON5_PRESSED
Hannes> +		else if (mev.bstate & BUTTON4_PRESSED)
Hannes> +		  wi->backward_scroll (3);
Hannes> +		else if (mev.bstate & BUTTON5_PRESSED)
Hannes> +		  wi->forward_scroll (3);
Hannes> +#endif

One question I have here is that, right now, the mouse wheel already
works to scroll for me.

I assume this won't change.  But I wonder why new code is needed.
Maybe it's the case that if you enable mouse events, curses turns off
automatic translation of scroll wheel to scrolling?

Tom
Mike Frysinger via Gdb-patches March 11, 2021, 5:48 p.m. | #2
Am Donnerstag, 11. März 2021, 18:32:32 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:

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

>

> Thank you.  This is a very welcome development.

>

> I won't comment on tests or comments in the code.

>

> Hannes> +#ifdef BUTTON5_PRESSED

> Hannes> +        else if (mev.bstate & BUTTON4_PRESSED)

> Hannes> +          wi->backward_scroll (3);

> Hannes> +        else if (mev.bstate & BUTTON5_PRESSED)

> Hannes> +          wi->forward_scroll (3);

> Hannes> +#endif

>

> One question I have here is that, right now, the mouse wheel already

> works to scroll for me.

>

> I assume this won't change.  But I wonder why new code is needed.

> Maybe it's the case that if you enable mouse events, curses turns off

> automatic translation of scroll wheel to scrolling?


I was not aware of that, and have never seen this behavior.
How does that work, how is the mouse wheel currently translated to
window scrolling?


Hannes
Tom Tromey March 12, 2021, 4:35 p.m. | #3
>> One question I have here is that, right now, the mouse wheel already

>> works to scroll for me.

>> 

>> I assume this won't change.  But I wonder why new code is needed.

>> Maybe it's the case that if you enable mouse events, curses turns off

>> automatic translation of scroll wheel to scrolling?


Hannes> I was not aware of that, and have never seen this behavior.
Hannes> How does that work, how is the mouse wheel currently translated to
Hannes> window scrolling?

I debugged today, and tui_dispatch_ctrl_char gets a KEY_UP key when I
use the scroll wheel.  So, I think it's just a feature built in to
ncurses.

Tom
Mike Frysinger via Gdb-patches March 12, 2021, 4:43 p.m. | #4
Am Freitag, 12. März 2021, 17:35:15 MEZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:

> >> One question I have here is that, right now, the mouse wheel already

> >> works to scroll for me.

> >>

> >> I assume this won't change.  But I wonder why new code is needed.

> >> Maybe it's the case that if you enable mouse events, curses turns off

> >> automatic translation of scroll wheel to scrolling?

>

> Hannes> I was not aware of that, and have never seen this behavior.

> Hannes> How does that work, how is the mouse wheel currently translated to

> Hannes> window scrolling?

>

> I debugged today, and tui_dispatch_ctrl_char gets a KEY_UP key when I

> use the scroll wheel.  So, I think it's just a feature built in to

> ncurses.


I see, so this always scrolls the window with focus.
With this patch, it scrolls the window where the mouse is, so I don't have to
change the focus back and forth.


Hannes
Tom Tromey March 12, 2021, 5:02 p.m. | #5
>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:


Hannes> I see, so this always scrolls the window with focus.
Hannes> With this patch, it scrolls the window where the mouse is, so I don't have to
Hannes> change the focus back and forth.

FWIW that does seem like an improvement to me.

Tom

Patch

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..46ccb72b97c 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -137,6 +137,10 @@  struct tui_win_info
     return true;
   }
 
+  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 ();