]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Initial TUI mouse support
authorHannes Domani <ssbssa@yahoo.de>
Sun, 20 Dec 2020 15:45:57 +0000 (16:45 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Fri, 4 Jun 2021 14:15:01 +0000 (16:15 +0200)
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/ChangeLog:

2021-06-04  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.

gdb/ChangeLog
gdb/ser-mingw.c
gdb/tui/tui-data.h
gdb/tui/tui-io.c
gdb/tui/tui.c

index 1dd4d3e76f12bd5c6934b96985dce2d54ed53367..fca6750de384a6d6199aa11216e2a5fbec788ea2 100644 (file)
@@ -1,3 +1,12 @@
+2021-06-04  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.
+
 2021-06-03  Magne Hov  <mhov@undo.io>
 
        PR python/27841
index 043bb50b577f0ad569f1ac25a524c9d4ae09f730..2bad51310f67cb65a5792ef2fe93243d3a9bdaf3 100644 (file)
@@ -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);
index b4d788dd0a485ab10f1e79c9e6397a6e51b4ec44..9fa39fa58f3e6356edb6ad4508ac5f61a74e7c15 100644 (file)
@@ -137,6 +137,13 @@ public:
     return true;
   }
 
+  /* Called for each mouse click inside this window.  Coordinates MOUSE_X
+     and MOUSE_Y are 0-based relative to the window, and MOUSE_BUTTON can
+     be 1 (left), 2 (middle), or 3 (right).  */
+  virtual void click (int mouse_x, int mouse_y, int mouse_button)
+  {
+  }
+
   void check_and_display_highlight_if_needed ();
 
   /* Window handle.  */
index a2be4d4353e736963479b5a50d0e5823f49af3bf..7df0e2f1bd30f905985a8b52fe13d6abe00830ac 100644 (file)
@@ -639,6 +639,9 @@ tui_redisplay_readline (void)
 static void
 tui_prep_terminal (int notused1)
 {
+#ifdef NCURSES_MOUSE_VERSION
+  mousemask (ALL_MOUSE_EVENTS, NULL);
+#endif
 }
 
 /* Readline callback to restore the terminal.  It is called once each
@@ -646,6 +649,9 @@ tui_prep_terminal (int notused1)
 static void
 tui_deprep_terminal (void)
 {
+#ifdef NCURSES_MOUSE_VERSION
+  mousemask (0, NULL);
+#endif
 }
 
 #ifdef TUI_USE_PIPE_FOR_READLINE
@@ -978,6 +984,37 @@ tui_dispatch_ctrl_char (unsigned int ch)
     case KEY_LEFT:
       win_info->right_scroll (1);
       break;
+#ifdef NCURSES_MOUSE_VERSION
+    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) != 0
+                   || (mev.bstate & BUTTON2_CLICKED) != 0
+                   || (mev.bstate & BUTTON3_CLICKED) != 0)
+                 {
+                   int button = (mev.bstate & BUTTON1_CLICKED) != 0 ? 1
+                     :         ((mev.bstate & BUTTON2_CLICKED) != 0 ? 2
+                                : 3);
+                   wi->click (mev.x - wi->x - 1, mev.y - wi->y - 1, button);
+                 }
+#ifdef BUTTON5_PRESSED
+               else if ((mev.bstate & BUTTON4_PRESSED) != 0)
+                 wi->backward_scroll (3);
+               else if ((mev.bstate & BUTTON5_PRESSED) != 0)
+                 wi->forward_scroll (3);
+#endif
+               break;
+             }
+       }
+      break;
+#endif
     case '\f':
       break;
     default:
index af92b2a804261fb83965db679f28de15cd68635f..529fc62c9ac3000c4c8c1b082d45e9311679abdf 100644 (file)
@@ -508,6 +508,10 @@ tui_disable (void)
   rl_startup_hook = 0;
   rl_already_prompted = 0;
 
+#ifdef NCURSES_MOUSE_VERSION
+  mousemask (0, NULL);
+#endif
+
   /* Leave curses and restore previous gdb terminal setting.  */
   endwin ();