Message ID | CAC-ggsEszq2WX7eZ_UdvgaBtM1YdnBFyJstr4Z0=BNW6VcMEEQ@mail.gmail.com |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C1E33858422 for <patchwork@sourceware.org>; Sat, 28 Jan 2023 00:43:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C1E33858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674866618; bh=SaJij+NS21HMKqSd9N8dyyAMd5p5SoRkS2rWUlqln+Y=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=eJcem5sktBcs4ppU5rhbrcz4F+/xqUTHmbLVrQDFlJa4VefUEplSROp2UKQvvqEXE knXNBOMyKvfzZhtrVFmSVP5/HQrXWl4CmLVjXqUryOBQIOwoJ5PlXHSLx00mwoLLtO Tc4fHn8txFBXkNWD44M+luwx/39pvfDkAnhQZQMo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id A5E053858C54 for <gdb-patches@sourceware.org>; Sat, 28 Jan 2023 00:43:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5E053858C54 Received: by mail-ot1-x32c.google.com with SMTP id m18-20020a05683026d200b0068661404380so2770155otu.2 for <gdb-patches@sourceware.org>; Fri, 27 Jan 2023 16:43:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SaJij+NS21HMKqSd9N8dyyAMd5p5SoRkS2rWUlqln+Y=; b=MTdNnYoHiJ9zA3TqaRPha3PcorbECvUCUF5bRkilJStHfLEyUlV1f1kHeiFUBnFmqm u0RfuKIqmFsEJ6JYHYHnPJ3eiVNgaIYnffq/pBR3Uq82j5Hmif+1pOGBDsCN/5cyfC6o 2nlpfjcEw2SVP1xInvcQeFLVEZlW7CUASk3hkbq1Gl819WbOUje72RWqOA5ps9aGm5RT 9KO/ETjimj8GYoHi2GcrYyzzJzSVIby1SdUlzmIbMEjLcDygpAb54ji1gH3GZVHyxTI+ Fckww81TnLV5I2Xo6PdhGLlPKCMKvb3o+mBEND9zRNZZ2iookQT9bxrbuBo0HG5qN4Yd w/6A== X-Gm-Message-State: AFqh2kohPX399n3t8IxZtYLUxT7MQvCBUZeq0nNvA8ev97lB+TE2uNEC z8v091EBruV4SPdcdIWNhsfwGrnUbKlwAguv46Jp1Xmf6e8= X-Google-Smtp-Source: AMrXdXuSPCqJ2IHxx9w365Snl133uuDUQEEuVhn6dYqDCqd/bq2ats1tW/CQud0DRUc5pWOPYHMdW+5DDnKkCGZKD7w= X-Received: by 2002:a05:6830:2656:b0:686:df23:4276 with SMTP id f22-20020a056830265600b00686df234276mr891339otu.148.1674866589805; Fri, 27 Jan 2023 16:43:09 -0800 (PST) MIME-Version: 1.0 Date: Fri, 27 Jan 2023 16:42:58 -0800 Message-ID: <CAC-ggsEszq2WX7eZ_UdvgaBtM1YdnBFyJstr4Z0=BNW6VcMEEQ@mail.gmail.com> Subject: [PATCH] gdb/tui: add 'set tui mouse-events off' to restore mouse selection To: gdb-patches@sourceware.org Content-Type: multipart/mixed; boundary="00000000000021fa8405f348449f" X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> From: strager via Gdb-patches <gdb-patches@sourceware.org> Reply-To: strager <strager.nds@gmail.com> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
gdb/tui: add 'set tui mouse-events off' to restore mouse selection
|
|
Commit Message
strager
Jan. 28, 2023, 12:42 a.m. UTC
From 991bf4f7c3d58cb8d8858cf4284c360719843350 Mon Sep 17 00:00:00 2001
From: "Matthew \"strager\" Glazar" <strager.nds@gmail.com>
Date: Fri, 27 Jan 2023 16:19:45 -0800
Subject: [PATCH] gdb/tui: add 'set tui mouse-events off' to restore mouse
selection
Rationale:
I use the mouse with my terminal to select and copy text. In gdb, I use
the mouse to select a function name to set a breakpoint, or a variable
name to print, for example.
When gdb is compiled with ncurses mouse support, gdb's TUI mode
intercepts mouse events. Left-clicking and dragging, which would
normally select text, seems to do nothing. This means I cannot select
text using my mouse anymore. This makes it harder to set breakpoints,
print variables, etc.
Solution:
I tried to fix this issue by editing the 'mousemask' call to only enable
buttons 4 and 5. However, this still caused my terminal (gnome-terminal)
to not allow text to be selected. The only way I could make it work is
by calling 'mousemask (0, NULL);'. But doing so disables the mouse code
entirely, which other people might want.
I therefore decided to make a setting in gdb called 'tui mouse-events'.
If enabled (the default), the behavior is as it is now: terminal mouse
events are given to gdb, disabling the terminal's default behavior.
If disabled (opt-in), the behavior is as it was before the year 2020:
terminal mouse events are not given to gdb, therefore the mouse can be
used to select and copy text.
Notes:
I am not attached to the setting name or its description. Feel free to
suggest better wording.
Testing:
I tested this change in gnome-terminal by performing the following steps
manually:
1. Run: gdb --args ./myprogram
2. Enable TUI: press ctrl-x ctrl-a
3. Click and drag text with the mouse. Observe no selection.
4. Input: set tui mouse-events off
5. Click and drag text with the mouse. Observe that selection works now.
6. Input: set tui mouse-events on
7. Click and drag text with the mouse Observe no selection.
---
gdb/NEWS | 7 +++++++
gdb/doc/gdb.texinfo | 13 +++++++++++++
gdb/tui/tui-io.c | 3 ++-
gdb/tui/tui-win.c | 24 ++++++++++++++++++++++++
gdb/tui/tui-win.h | 3 +++
5 files changed, 49 insertions(+), 1 deletion(-)
Comments
> Date: Fri, 27 Jan 2023 16:42:58 -0800 > From: strager via Gdb-patches <gdb-patches@sourceware.org> > > Rationale: > I use the mouse with my terminal to select and copy text. In gdb, I use > the mouse to select a function name to set a breakpoint, or a variable > name to print, for example. > > When gdb is compiled with ncurses mouse support, gdb's TUI mode > intercepts mouse events. Left-clicking and dragging, which would > normally select text, seems to do nothing. This means I cannot select > text using my mouse anymore. This makes it harder to set breakpoints, > print variables, etc. > > Solution: > I tried to fix this issue by editing the 'mousemask' call to only enable > buttons 4 and 5. However, this still caused my terminal (gnome-terminal) > to not allow text to be selected. The only way I could make it work is > by calling 'mousemask (0, NULL);'. But doing so disables the mouse code > entirely, which other people might want. > > I therefore decided to make a setting in gdb called 'tui mouse-events'. > If enabled (the default), the behavior is as it is now: terminal mouse > events are given to gdb, disabling the terminal's default behavior. > If disabled (opt-in), the behavior is as it was before the year 2020: > terminal mouse events are not given to gdb, therefore the mouse can be > used to select and copy text. Thanks. > --- gdb/NEWS > +++ gdb/NEWS > @@ -17,6 +17,13 @@ maintenance print record-instruction [ N ] > prints how GDB would undo the N-th previous instruction, and if N is > positive, it prints how GDB will redo the N-th following instruction. > > +set tui mouse-events [on|off] > +show tui mouse-events > + When on (default), the TUI will interpret mouse clicks (including > scroll wheel > + presses), overwriting the terminal's default behavior (usually text > + selection). When off, the TUI will preserve the terminal's default behavior > + for mouse events. Instead of talking about overriding the terminal's behavior, this text should say that the mouse events are interpreted either by GDB or by the terminal. > +Set whether the TUI source window is displayed in ``compact'' form. > +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. This part sounds unrelated?
Oops, I forgot to cc gdb-patches@. > Instead of talking about overriding the terminal's behavior, this text > should say that the mouse events are interpreted either by GDB or by > the terminal. Thanks for the feedback. I removed the duplicate copy of 'set tui compact-source' documentation. I rewrote the 'set tui mouse-events' documentation to avoid mentioning 'overriding'. I also fixed a typo in the 'show tui mouse-events' command and fixed a typo in the commit message (see attached). --- gdb/NEWS | 6 ++++++ gdb/doc/gdb.texinfo | 6 ++++++ gdb/tui/tui-io.c | 3 ++- gdb/tui/tui-win.c | 23 +++++++++++++++++++++++ gdb/tui/tui-win.h | 3 +++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git gdb/NEWS gdb/NEWS index 445d28efed9..21399e86caa 100644 --- gdb/NEWS +++ gdb/NEWS @@ -38,6 +38,12 @@ maintenance print record-instruction [ N ] prints how GDB would undo the N-th previous instruction, and if N is positive, it prints how GDB will redo the N-th following instruction. +set tui mouse-events [on|off] +show tui mouse-events + When on (default), mouse clicks control the TUI and can be accessed by + plugins. When off, mouse clicks are handled by the terminal. This enables + terminal-native text selection. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo index 03033c7f9e3..02de9ad753a 100644 --- gdb/doc/gdb.texinfo +++ gdb/doc/gdb.texinfo @@ -29888,6 +29888,12 @@ 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-events @r{[}on@r{|}off@r{]} +@kindex set tui mouse-events +When on (default), mouse clicks control the TUI and can be accessed by plugins. +When off, mouse clicks are handled by the terminal. This enables terminal-native +text selection. + @kindex set debug tui @item set debug tui @r{[}on|off@r{]} Turn on or off display of @value{GDBN} internal debug messages relating diff --git gdb/tui/tui-io.c gdb/tui/tui-io.c index a17cf38a1f2..45ef34aeab5 100644 --- gdb/tui/tui-io.c +++ gdb/tui/tui-io.c @@ -655,7 +655,8 @@ static void tui_prep_terminal (int notused1) { #ifdef NCURSES_MOUSE_VERSION - mousemask (ALL_MOUSE_EVENTS, NULL); + if (tui_enable_mouse) + mousemask (ALL_MOUSE_EVENTS, NULL); #endif } diff --git gdb/tui/tui-win.c gdb/tui/tui-win.c index 008189eb99b..d7124592ca4 100644 --- gdb/tui/tui-win.c +++ gdb/tui/tui-win.c @@ -897,6 +897,17 @@ tui_show_compact_source (struct ui_file *file, int from_tty, gdb_printf (file, _("TUI source window compactness is %s.\n"), value); } +bool tui_enable_mouse = true; + +/* Implement 'show tui mouse-events'. */ + +static void +show_tui_mouse_events (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("TUI mouse events are %s.\n"), value); +} + /* Set the tab width of the specified window. */ static void tui_set_tab_width_command (const char *arg, int from_tty) @@ -1284,6 +1295,18 @@ position indicator is styled."), &style_set_list, &style_show_list); + add_setshow_boolean_cmd ("mouse-events", class_tui, + &tui_enable_mouse, _("\ +Set whether TUI mode handles mouse clicks."), _("\ +Show whether TUI mode handles mouse clicks."), _("\ +When on (default), mouse clicks control the TUI and can be accessed by plugins.\n\ +When off, mouse clicks are handled by the terminal. This enables terminal-native\n\ +text selection."), + + NULL, + show_tui_mouse_events, + &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 gdb/tui/tui-win.h gdb/tui/tui-win.h index 4b33f1f2b54..039993fba34 100644 --- gdb/tui/tui-win.h +++ gdb/tui/tui-win.h @@ -51,6 +51,9 @@ struct cmd_list_element **tui_get_cmd_list (void); /* Whether compact source display should be used. */ extern bool compact_source; +/* Whether the TUI should intercept terminal mouse events. */ +extern bool tui_enable_mouse; + /* Whether to style the source and assembly code highlighted by the TUI's current position indicator. */ extern bool style_tui_current_position;
> From: strager <strager.nds@gmail.com> > Date: Wed, 1 Feb 2023 00:35:47 -0800 > Cc: gdb-patches@sourceware.org > > +set tui mouse-events [on|off] > +show tui mouse-events > + When on (default), mouse clicks control the TUI and can be accessed by > + plugins. When off, mouse clicks are handled by the terminal. This enables > + terminal-native text selection. This is OK, except that I don't think we use the term "plug-in" in our documentation. I suggest to use "Python extensions" instead. > +@item set tui mouse-events @r{[}on@r{|}off@r{]} > +@kindex set tui mouse-events > +When on (default), mouse clicks control the TUI and can be accessed by plugins. > +When off, mouse clicks are handled by the terminal. This enables > terminal-native > +text selection. Likewise here, and also please leave 2 spaces between sentences, per US English conventions we use in our documentation.
strager via Gdb-patches <gdb-patches@sourceware.org> writes: > Oops, I forgot to cc gdb-patches@. > >> Instead of talking about overriding the terminal's behavior, this text >> should say that the mouse events are interpreted either by GDB or by >> the terminal. > > Thanks for the feedback. I removed the duplicate copy of 'set tui > compact-source' documentation. I rewrote the 'set tui mouse-events' > documentation to avoid mentioning 'overriding'. I also fixed a typo in > the 'show tui mouse-events' command and fixed a typo in the commit > message (see attached). > > --- > gdb/NEWS | 6 ++++++ > gdb/doc/gdb.texinfo | 6 ++++++ > gdb/tui/tui-io.c | 3 ++- > gdb/tui/tui-win.c | 23 +++++++++++++++++++++++ > gdb/tui/tui-win.h | 3 +++ > 5 files changed, 40 insertions(+), 1 deletion(-) > > diff --git gdb/NEWS gdb/NEWS > index 445d28efed9..21399e86caa 100644 > --- gdb/NEWS > +++ gdb/NEWS > @@ -38,6 +38,12 @@ maintenance print record-instruction [ N ] > prints how GDB would undo the N-th previous instruction, and if N is > positive, it prints how GDB will redo the N-th following instruction. > > +set tui mouse-events [on|off] > +show tui mouse-events > + When on (default), mouse clicks control the TUI and can be accessed by > + plugins. When off, mouse clicks are handled by the terminal. This enables > + terminal-native text selection. > + > * MI changes > > ** mi now reports 'no-history' as a stop reason when hitting the end of the > diff --git gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo > index 03033c7f9e3..02de9ad753a 100644 > --- gdb/doc/gdb.texinfo > +++ gdb/doc/gdb.texinfo > @@ -29888,6 +29888,12 @@ 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-events @r{[}on@r{|}off@r{]} > +@kindex set tui mouse-events > +When on (default), mouse clicks control the TUI and can be accessed by plugins. > +When off, mouse clicks are handled by the terminal. This enables > terminal-native > +text selection. > + > @kindex set debug tui > @item set debug tui @r{[}on|off@r{]} > Turn on or off display of @value{GDBN} internal debug messages relating > diff --git gdb/tui/tui-io.c gdb/tui/tui-io.c > index a17cf38a1f2..45ef34aeab5 100644 > --- gdb/tui/tui-io.c > +++ gdb/tui/tui-io.c > @@ -655,7 +655,8 @@ static void > tui_prep_terminal (int notused1) > { > #ifdef NCURSES_MOUSE_VERSION > - mousemask (ALL_MOUSE_EVENTS, NULL); > + if (tui_enable_mouse) > + mousemask (ALL_MOUSE_EVENTS, NULL); > #endif > } > > diff --git gdb/tui/tui-win.c gdb/tui/tui-win.c > index 008189eb99b..d7124592ca4 100644 > --- gdb/tui/tui-win.c > +++ gdb/tui/tui-win.c > @@ -897,6 +897,17 @@ tui_show_compact_source (struct ui_file *file, > int from_tty, > gdb_printf (file, _("TUI source window compactness is %s.\n"), value); > } > > +bool tui_enable_mouse = true; > + > +/* Implement 'show tui mouse-events'. */ > + > +static void > +show_tui_mouse_events (struct ui_file *file, int from_tty, > + struct cmd_list_element *c, const char *value) > +{ > + gdb_printf (file, _("TUI mouse events are %s.\n"), value); > +} > + > /* Set the tab width of the specified window. */ > static void > tui_set_tab_width_command (const char *arg, int from_tty) > @@ -1284,6 +1295,18 @@ position indicator is styled."), > &style_set_list, > &style_show_list); > > + add_setshow_boolean_cmd ("mouse-events", class_tui, > + &tui_enable_mouse, _("\ > +Set whether TUI mode handles mouse clicks."), _("\ > +Show whether TUI mode handles mouse clicks."), _("\ > +When on (default), mouse clicks control the TUI and can be accessed > by plugins.\n\ > +When off, mouse clicks are handled by the terminal. This enables > terminal-native\n\ > +text selection."), > + > + NULL, > + show_tui_mouse_events, > + &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 gdb/tui/tui-win.h gdb/tui/tui-win.h > index 4b33f1f2b54..039993fba34 100644 > --- gdb/tui/tui-win.h > +++ gdb/tui/tui-win.h > @@ -51,6 +51,9 @@ struct cmd_list_element **tui_get_cmd_list (void); > /* Whether compact source display should be used. */ > extern bool compact_source; > > +/* Whether the TUI should intercept terminal mouse events. */ > +extern bool tui_enable_mouse; > + > /* Whether to style the source and assembly code highlighted by the TUI's > current position indicator. */ > extern bool style_tui_current_position; > -- > 2.29.2 > From 3ee6bc8ad0b5ac17725233ba88aa4d12167df4f7 Mon Sep 17 00:00:00 2001 > From: "Matthew \"strager\" Glazar" <strager.nds@gmail.com> > Date: Fri, 27 Jan 2023 16:19:45 -0800 > Subject: [PATCH] gdb/tui: add 'set tui mouse-events off' to restore mouse > selection > > Rationale: > I use the mouse with my terminal to select and copy text. In gdb, I use > the mouse to select a function name to set a breakpoint, or a variable > name to print, for example. > > When gdb is compiled with ncurses mouse support, gdb's TUI mode > intercepts mouse events. Left-clicking and dragging, which would > normally select text, seems to do nothing. This means I cannot select > text using my mouse anymore. This makes it harder to set breakpoints, > print variables, etc. > > Solution: > I tried to fix this issue by editing the 'mousemask' call to only enable > buttons 4 and 5. However, this still caused my terminal (gnome-terminal) > to not allow text to be selected. The only way I could make it work is > by calling 'mousemask (0, NULL);'. But doing so disables the mouse code > entirely, which other people might want. > > I therefore decided to make a setting in gdb called 'tui mouse-events'. > If enabled (the default), the behavior is as it is now: terminal mouse > events are given to gdb, disabling the terminal's default behavior. > If disabled (opt-in), the behavior is as it was before the year 2020: > terminal mouse events are not given to gdb, therefore the mouse can be > used to select and copy text. > > Notes: > I am not attached to the setting name or its description. Feel free to > suggest better wording. > > Testing: > I tested this change in gnome-terminal by performing the following steps > manually: > > 1. Run: gdb --args ./myprogram > 2. Enable TUI: press ctrl-x ctrl-a > 3. Click and drag text with the mouse. Observe no selection. > 4. Input: set tui mouse-events off > 5. Click and drag text with the mouse. Observe that selection works now. > 6. Input: set tui mouse-events on. > 7. Click and drag text with the mouse Observe no selection. > --- > gdb/NEWS | 6 ++++++ > gdb/doc/gdb.texinfo | 6 ++++++ > gdb/tui/tui-io.c | 3 ++- > gdb/tui/tui-win.c | 23 +++++++++++++++++++++++ > gdb/tui/tui-win.h | 3 +++ > 5 files changed, 40 insertions(+), 1 deletion(-) > > diff --git gdb/NEWS gdb/NEWS > index 445d28efed9..21399e86caa 100644 > --- gdb/NEWS > +++ gdb/NEWS > @@ -38,6 +38,12 @@ maintenance print record-instruction [ N ] > prints how GDB would undo the N-th previous instruction, and if N is > positive, it prints how GDB will redo the N-th following instruction. > > +set tui mouse-events [on|off] > +show tui mouse-events > + When on (default), mouse clicks control the TUI and can be accessed by > + plugins. When off, mouse clicks are handled by the terminal. This enables > + terminal-native text selection. > + > * MI changes > > ** mi now reports 'no-history' as a stop reason when hitting the end of the > diff --git gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo > index 03033c7f9e3..02de9ad753a 100644 > --- gdb/doc/gdb.texinfo > +++ gdb/doc/gdb.texinfo > @@ -29888,6 +29888,12 @@ 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-events @r{[}on@r{|}off@r{]} > +@kindex set tui mouse-events > +When on (default), mouse clicks control the TUI and can be accessed by plugins. > +When off, mouse clicks are handled by the terminal. This enables terminal-native > +text selection. I think it would be worth adding some text to the description of Window.click in doc/python.texi, along with a cross-reference back to this setting, as the Window.click is not going to work when this setting is off. Thanks, Andrew > + > @kindex set debug tui > @item set debug tui @r{[}on|off@r{]} > Turn on or off display of @value{GDBN} internal debug messages relating > diff --git gdb/tui/tui-io.c gdb/tui/tui-io.c > index a17cf38a1f2..45ef34aeab5 100644 > --- gdb/tui/tui-io.c > +++ gdb/tui/tui-io.c > @@ -655,7 +655,8 @@ static void > tui_prep_terminal (int notused1) > { > #ifdef NCURSES_MOUSE_VERSION > - mousemask (ALL_MOUSE_EVENTS, NULL); > + if (tui_enable_mouse) > + mousemask (ALL_MOUSE_EVENTS, NULL); > #endif > } > > diff --git gdb/tui/tui-win.c gdb/tui/tui-win.c > index 008189eb99b..d7124592ca4 100644 > --- gdb/tui/tui-win.c > +++ gdb/tui/tui-win.c > @@ -897,6 +897,17 @@ tui_show_compact_source (struct ui_file *file, int from_tty, > gdb_printf (file, _("TUI source window compactness is %s.\n"), value); > } > > +bool tui_enable_mouse = true; > + > +/* Implement 'show tui mouse-events'. */ > + > +static void > +show_tui_mouse_events (struct ui_file *file, int from_tty, > + struct cmd_list_element *c, const char *value) > +{ > + gdb_printf (file, _("TUI mouse events are %s.\n"), value); > +} > + > /* Set the tab width of the specified window. */ > static void > tui_set_tab_width_command (const char *arg, int from_tty) > @@ -1284,6 +1295,18 @@ position indicator is styled."), > &style_set_list, > &style_show_list); > > + add_setshow_boolean_cmd ("mouse-events", class_tui, > + &tui_enable_mouse, _("\ > +Set whether TUI mode handles mouse clicks."), _("\ > +Show whether TUI mode handles mouse clicks."), _("\ > +When on (default), mouse clicks control the TUI and can be accessed by plugins.\n\ > +When off, mouse clicks are handled by the terminal. This enables terminal-native\n\ > +text selection."), > + > + NULL, > + show_tui_mouse_events, > + &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 gdb/tui/tui-win.h gdb/tui/tui-win.h > index 4b33f1f2b54..039993fba34 100644 > --- gdb/tui/tui-win.h > +++ gdb/tui/tui-win.h > @@ -51,6 +51,9 @@ struct cmd_list_element **tui_get_cmd_list (void); > /* Whether compact source display should be used. */ > extern bool compact_source; > > +/* Whether the TUI should intercept terminal mouse events. */ > +extern bool tui_enable_mouse; > + > /* Whether to style the source and assembly code highlighted by the TUI's > current position indicator. */ > extern bool style_tui_current_position; > -- > 2.29.2
On Wed, Feb 1, 2023 at 4:41 AM Eli Zaretskii <eliz@gnu.org> wrote: > This is OK, except that I don't think we use the term "plug-in" in our > documentation. I suggest to use "Python extensions" instead. Fixed! On Wed, Feb 1, 2023 at 4:41 AM Eli Zaretskii <eliz@gnu.org> wrote: > Likewise here, and also please leave 2 spaces between sentences, per > US English conventions we use in our documentation. Fixed! On Wed, Feb 1, 2023 at 5:27 AM Andrew Burgess <aburgess@redhat.com> wrote: > I think it would be worth adding some text to the description of > Window.click in doc/python.texi, along with a cross-reference back to > this setting, as the Window.click is not going to work when this setting > is off. Great idea! I also found the "TUI Mouse Support" section and included a few links in there too. This is my first time using texinfo, so let me know if I made any mistakes. Updated patch is attached. --- gdb/NEWS | 6 ++++++ gdb/doc/gdb.texinfo | 15 ++++++++++++++- gdb/doc/python.texi | 5 +++++ gdb/tui/tui-io.c | 3 ++- gdb/tui/tui-win.c | 22 ++++++++++++++++++++++ gdb/tui/tui-win.h | 3 +++ 6 files changed, 52 insertions(+), 2 deletions(-) diff --git gdb/NEWS gdb/NEWS index 445d28efed9..1a00a6bd799 100644 --- gdb/NEWS +++ gdb/NEWS @@ -38,6 +38,12 @@ maintenance print record-instruction [ N ] prints how GDB would undo the N-th previous instruction, and if N is positive, it prints how GDB will redo the N-th following instruction. +set tui mouse-events [on|off] +show tui mouse-events + When on (default), mouse clicks control the TUI and can be accessed by + Python extensions. When off, mouse clicks are handled by the terminal, + enabling terminal-native text selection. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo index 03033c7f9e3..65e85c7f8a1 100644 --- gdb/doc/gdb.texinfo +++ gdb/doc/gdb.texinfo @@ -29606,7 +29606,13 @@ the @key{SHIFT} key on your keyboard to temporarily bypass @value{GDBN}'s TUI and access the terminal's native mouse copy/paste functionality (commonly, click-drag-release or double-click to select text, middle-click to paste). This copy/paste works with the -terminal's selection buffer, as opposed to the TUI's buffer. +terminal's selection buffer, as opposed to the TUI's buffer. Alternatively, to +disable mouse support in the TUI entirely and give the terminal control over +mouse clicks, turn off the @code{tui mouse-events} setting +(@pxref{tui-mouse-events,,set tui mouse-events}). + +Python extensions can react to mouse clicks +(@pxref{python-window-click,,Window.click}). @node TUI Commands @section TUI-specific Commands @@ -29888,6 +29894,13 @@ 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. +@anchor{tui-mouse-events} +@item set tui mouse-events @r{[}on@r{|}off@r{]} +@kindex set tui mouse-events +When on (default), mouse clicks control the TUI (@pxref{TUI Mouse Support}). +When off, mouse clicks are handled by the terminal, enabling terminal-native +text selection. + @kindex set debug tui @item set debug tui @r{[}on|off@r{]} Turn on or off display of @value{GDBN} internal debug messages relating diff --git gdb/doc/python.texi gdb/doc/python.texi index b04f1de2ddf..ab3050ca15c 100644 --- gdb/doc/python.texi +++ gdb/doc/python.texi @@ -6722,11 +6722,16 @@ contents. A positive argument should cause the viewport to move down, and so the content should appear to move up. @end defun +@anchor{python-window-click} @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, from the top left corner), and @var{button} specifies which mouse button was used, whose values can be 1 (left), 2 (middle), or 3 (right). + +When TUI mouse events are disabled by turning off the @code{tui mouse-events} +setting (@pxref{tui-mouse-events,,set tui mouse-events}), then @code{click} will +not be called. @end defun @node Disassembly In Python diff --git gdb/tui/tui-io.c gdb/tui/tui-io.c index a17cf38a1f2..45ef34aeab5 100644 --- gdb/tui/tui-io.c +++ gdb/tui/tui-io.c @@ -655,7 +655,8 @@ static void tui_prep_terminal (int notused1) { #ifdef NCURSES_MOUSE_VERSION - mousemask (ALL_MOUSE_EVENTS, NULL); + if (tui_enable_mouse) + mousemask (ALL_MOUSE_EVENTS, NULL); #endif } diff --git gdb/tui/tui-win.c gdb/tui/tui-win.c index 008189eb99b..101fefcfe0a 100644 --- gdb/tui/tui-win.c +++ gdb/tui/tui-win.c @@ -897,6 +897,17 @@ tui_show_compact_source (struct ui_file *file, int from_tty, gdb_printf (file, _("TUI source window compactness is %s.\n"), value); } +bool tui_enable_mouse = true; + +/* Implement 'show tui mouse-events'. */ + +static void +show_tui_mouse_events (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("TUI mouse events are %s.\n"), value); +} + /* Set the tab width of the specified window. */ static void tui_set_tab_width_command (const char *arg, int from_tty) @@ -1284,6 +1295,17 @@ position indicator is styled."), &style_set_list, &style_show_list); + add_setshow_boolean_cmd ("mouse-events", class_tui, + &tui_enable_mouse, _("\ +Set whether TUI mode handles mouse clicks."), _("\ +Show whether TUI mode handles mouse clicks."), _("\ +When on (default), mouse clicks control the TUI and can be accessed by Python\n\ +extensions. When off, mouse clicks are handled by the terminal, enabling\n\ +terminal-native text selection."), + NULL, + show_tui_mouse_events, + &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 gdb/tui/tui-win.h gdb/tui/tui-win.h index 4b33f1f2b54..039993fba34 100644 --- gdb/tui/tui-win.h +++ gdb/tui/tui-win.h @@ -51,6 +51,9 @@ struct cmd_list_element **tui_get_cmd_list (void); /* Whether compact source display should be used. */ extern bool compact_source; +/* Whether the TUI should intercept terminal mouse events. */ +extern bool tui_enable_mouse; + /* Whether to style the source and assembly code highlighted by the TUI's current position indicator. */ extern bool style_tui_current_position;
> From: strager <strager.nds@gmail.com> > Date: Wed, 1 Feb 2023 17:08:55 -0800 > Cc: gdb-patches@sourceware.org > > --- > gdb/NEWS | 6 ++++++ > gdb/doc/gdb.texinfo | 15 ++++++++++++++- > gdb/doc/python.texi | 5 +++++ > gdb/tui/tui-io.c | 3 ++- > gdb/tui/tui-win.c | 22 ++++++++++++++++++++++ > gdb/tui/tui-win.h | 3 +++ > 6 files changed, 52 insertions(+), 2 deletions(-) The documentation parts of this version are OK, thanks.
Hi, Thanks for working on this! I think I got used to use the "shift" key when I try to select, but soon might soon have "set tui mouse-events off" in my rc file. I have some code formatting remarks: - In GDB codebase, we use tab for indentation[1]: Lines should be indented with a mix of tabs and spaces. 8 spaces should be replaced with Tab. It looks like you patch uses spaces for indentation. -GDB prefers "nullptr" instead of "NULL". I have inlined in the patch below where this is relevant. Otherwise, and for what this is worth (I am not a maintainer), the change looks reasonable to me. Best, Lancelot. [1] https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Code_indentation > diff --git gdb/tui/tui-win.c gdb/tui/tui-win.c > index 008189eb99b..5709bfcbac1 100644 > --- gdb/tui/tui-win.c > +++ gdb/tui/tui-win.c > @@ -897,6 +897,17 @@ tui_show_compact_source (struct ui_file *file, > int from_tty, > gdb_printf (file, _("TUI source window compactness is %s.\n"), value); > } > > +bool tui_enable_mouse = true; > + > +/* Implement 'show tui mouse-events'. */ > + > +static void > +show_tui_mouse_events (struct ui_file *file, int from_tty, > + struct cmd_list_element *c, const char *value) Use tabs here. > +{ > + gdb_printf (file, _("TUI mouse events 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) > @@ -1284,6 +1295,19 @@ position indicator is styled."), > &style_set_list, > &style_show_list); > > + add_setshow_boolean_cmd ("mouse-events", class_tui, > + &tui_enable_mouse, _("\ Same > +Set whether TUI mode handles mouse clicks."), _("\ > +Show whether TUI mode handles mouse clicks."), _("\ > +When on, the TUI will interpret mouse clicks (including scroll wheel > presses),\n\ > +overwriting the terminal's default behavior (usually text selection).\n\ > +When off, the TUI will preserve the terminal's default behavior for mouse\n\ > +events."), > + Extra empty line here could be removed. > + NULL, s/NULL/nullptr/ > + show_tui_mouse_events, > + &tui_setlist, &tui_showlist); and tabs instead of spaces for the above lines. > + > tui_border_style.changed.attach (tui_rehighlight_all, "tui-win"); > tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win"); > }
On 2023-02-02 1:08 a.m., strager via Gdb-patches wrote: > --- gdb/doc/gdb.texinfo > +++ gdb/doc/gdb.texinfo > @@ -29606,7 +29606,13 @@ the @key{SHIFT} key on your keyboard to > temporarily bypass > @value{GDBN}'s TUI and access the terminal's native mouse copy/paste > functionality (commonly, click-drag-release or double-click to select > text, middle-click to paste). This copy/paste works with the > -terminal's selection buffer, as opposed to the TUI's buffer. > +terminal's selection buffer, as opposed to the TUI's buffer. Alternatively, to > +disable mouse support in the TUI entirely and give the terminal control over > +mouse clicks, turn off the @code{tui mouse-events} setting > +(@pxref{tui-mouse-events,,set tui mouse-events}). > + I noticed the new command doesn't have a "set" callback, so I guess this means that you have to disable and re-enable the TUI for the setting to take effect? Or does it take effect immediately somehow?
On Thu, Feb 2, 2023 at 11:50 AM Pedro Alves <pedro@palves.net> wrote: > I noticed the new command doesn't have a "set" callback, so I guess this means > that you have to disable and re-enable the TUI for the setting to take effect? > Or does it take effect immediately somehow? I tested it and it does take effect immediately. (I was surprised too.) I think it's because you enter readline after you type the 'set' command, and the mousemask code runs every readline.
diff --git gdb/NEWS gdb/NEWS index 2bc1672632a..c14158e41b5 100644 --- gdb/NEWS +++ gdb/NEWS @@ -17,6 +17,13 @@ maintenance print record-instruction [ N ] prints how GDB would undo the N-th previous instruction, and if N is positive, it prints how GDB will redo the N-th following instruction. +set tui mouse-events [on|off] +show tui mouse-events + When on (default), the TUI will interpret mouse clicks (including scroll wheel + presses), overwriting the terminal's default behavior (usually text + selection). When off, the TUI will preserve the terminal's default behavior + for mouse events. + * MI changes ** mi now reports 'no-history' as a stop reason when hitting the end of the diff --git gdb/doc/gdb.texinfo gdb/doc/gdb.texinfo index b5fad2cb16e..c36c24273d3 100644 --- gdb/doc/gdb.texinfo +++ gdb/doc/gdb.texinfo @@ -29867,6 +29867,19 @@ 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-events @r{[}on@r{|}off@r{]} +@kindex set tui mouse-events +When on (default), the TUI will interpret mouse clicks (including scroll wheel +presses), overwriting the terminal's default behavior (usually text selection). +When off, the TUI will preserve the terminal's default behavior for mouse +events. + +Set whether the TUI source window is displayed in ``compact'' form. +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. + @kindex set debug tui @item set debug tui @r{[}on|off@r{]} Turn on or off display of @value{GDBN} internal debug messages relating diff --git gdb/tui/tui-io.c gdb/tui/tui-io.c index a17cf38a1f2..45ef34aeab5 100644 --- gdb/tui/tui-io.c +++ gdb/tui/tui-io.c @@ -655,7 +655,8 @@ static void tui_prep_terminal (int notused1) { #ifdef NCURSES_MOUSE_VERSION - mousemask (ALL_MOUSE_EVENTS, NULL); + if (tui_enable_mouse) + mousemask (ALL_MOUSE_EVENTS, NULL); #endif } diff --git gdb/tui/tui-win.c gdb/tui/tui-win.c index 008189eb99b..5709bfcbac1 100644 --- gdb/tui/tui-win.c +++ gdb/tui/tui-win.c @@ -897,6 +897,17 @@ tui_show_compact_source (struct ui_file *file, int from_tty, gdb_printf (file, _("TUI source window compactness is %s.\n"), value); } +bool tui_enable_mouse = true; + +/* Implement 'show tui mouse-events'. */ + +static void +show_tui_mouse_events (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + gdb_printf (file, _("TUI mouse events 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) @@ -1284,6 +1295,19 @@ position indicator is styled."), &style_set_list, &style_show_list); + add_setshow_boolean_cmd ("mouse-events", class_tui, + &tui_enable_mouse, _("\ +Set whether TUI mode handles mouse clicks."), _("\ +Show whether TUI mode handles mouse clicks."), _("\ +When on, the TUI will interpret mouse clicks (including scroll wheel presses),\n\ +overwriting the terminal's default behavior (usually text selection).\n\ +When off, the TUI will preserve the terminal's default behavior for mouse\n\ +events."), + + NULL, + show_tui_mouse_events, + &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 gdb/tui/tui-win.h gdb/tui/tui-win.h index 4b33f1f2b54..039993fba34 100644 --- gdb/tui/tui-win.h +++ gdb/tui/tui-win.h @@ -51,6 +51,9 @@ struct cmd_list_element **tui_get_cmd_list (void); /* Whether compact source display should be used. */ extern bool compact_source; +/* Whether the TUI should intercept terminal mouse events. */ +extern bool tui_enable_mouse; + /* Whether to style the source and assembly code highlighted by the TUI's current position indicator. */ extern bool style_tui_current_position;