From: Hannes Domani <ssbssa@yahoo.de>
To: gdb-patches@sourceware.org
Subject: [PATCHv3 1/2] Initial TUI mouse support
Date: Thu, 3 Jun 2021 17:14:52 +0200 [thread overview]
Message-ID: <20210603151453.15248-1-ssbssa@yahoo.de> (raw)
In-Reply-To: <20210603151453.15248-1-ssbssa.ref@yahoo.de>
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-06-03 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.
---
v2:
- Added ChangeLog.
v3:
- Use NCURSES_MOUSE_VERSION to check if mouse functions are available.
- Mention possible mouse_button values in click function.
- Remove useless #include "tui/tui-source.h"
- Fix code style issues.
---
gdb/ser-mingw.c | 5 +++++
gdb/tui/tui-data.h | 7 +++++++
gdb/tui/tui-io.c | 37 +++++++++++++++++++++++++++++++++++++
gdb/tui/tui.c | 4 ++++
4 files changed, 53 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..9fa39fa58f3 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -137,6 +137,13 @@ struct tui_win_info
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. */
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index a2be4d4353e..7df0e2f1bd3 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -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:
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index af92b2a8042..529fc62c9ac 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -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 ();
--
2.31.1
next parent reply other threads:[~2021-06-03 15:15 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210603151453.15248-1-ssbssa.ref@yahoo.de>
2021-06-03 15:14 ` Hannes Domani [this message]
2021-06-03 15:14 ` [PATCHv3 2/2] Forward mouse click to python TUI window Hannes Domani
2021-06-03 17:16 ` Eli Zaretskii
2021-06-04 13:52 ` Tom Tromey
2021-06-04 13:51 ` [PATCHv3 1/2] Initial TUI mouse support Tom Tromey
2021-06-04 14:21 ` Hannes Domani
2021-06-04 15:20 ` Pedro Alves
2021-06-04 16:06 ` Hannes Domani
2021-06-04 16:23 ` Pedro Alves
2021-06-04 18:59 ` Eli Zaretskii
2021-06-04 18:57 ` Eli Zaretskii
2021-06-04 16:29 ` Pedro Alves
2021-06-04 16:48 ` Hannes Domani
2021-06-04 18:05 ` Joel Brobecker
2021-06-04 18:13 ` Simon Marchi
2021-06-04 18:39 ` Joel Brobecker
2021-06-04 20:31 ` Pedro Alves
2021-06-04 20:43 ` Pedro Alves
2021-06-04 21:15 ` Hannes Domani
2021-06-04 22:19 ` Pedro Alves
2021-06-10 18:44 ` Tom Tromey
2021-06-13 17:26 ` Pedro Alves
2021-06-18 15:01 ` Tom Tromey
2021-06-18 17:42 ` Pedro Alves
2021-06-04 18:46 ` Tom Tromey
2021-06-04 20:54 ` Pedro Alves
2021-06-04 23:48 ` Pedro Alves
2021-06-05 14:40 ` Hannes Domani
2021-06-06 5:46 ` Eli Zaretskii
2021-06-10 18:46 ` Tom Tromey
2021-06-11 11:02 ` Hannes Domani
2021-06-12 2:41 ` POC: Make the TUI command window support the mouse (Re: [PATCHv3 1/2] Initial TUI mouse support) Pedro Alves
2021-06-12 12:32 ` Hannes Domani
2021-06-12 18:08 ` Pedro Alves
2021-06-13 2:46 ` [PATCH v2] Make the TUI command window support the mouse Pedro Alves
2021-06-13 10:35 ` Eli Zaretskii
2021-06-13 17:29 ` Pedro Alves
2021-06-13 18:02 ` Eli Zaretskii
2021-06-13 18:13 ` Pedro Alves
2021-06-13 13:04 ` Hannes Domani
2021-06-13 17:25 ` [PATCH v3] " Pedro Alves
2021-06-13 17:55 ` Hannes Domani
2021-06-13 17:59 ` Pedro Alves
2021-06-17 11:04 ` [PUSHED v4] " Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210603151453.15248-1-ssbssa@yahoo.de \
--to=ssbssa@yahoo.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).