Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 753578 - app-misc/mc[-slang]: mouse keys insert garbage on terminal without basic X10 mouse support
Summary: app-misc/mc[-slang]: mouse keys insert garbage on terminal without basic X10 ...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Lars Wendler (Polynomial-C) (RETIRED)
URL: https://midnight-commander.org/ticket...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-08 16:12 UTC by Thomas Deutschmann (RETIRED)
Modified: 2021-07-13 12:02 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Deutschmann (RETIRED) gentoo-dev 2020-11-08 16:12:43 UTC
When using app-misc/mc[-slang] you cannot use your mouse (trackpad). If you click left key for example, mcedit will insert "7;6M7;6m" and when you press right key it will insert "2;3M2;2m".

When using app-misc/mc[slang], you can use your mouse as expected.
Comment 1 Thomas Deutschmann (RETIRED) gentoo-dev 2020-11-08 16:18:46 UTC
Screencast showing the problem: https://dev.gentoo.org/~whissi/stuff/mc-copy-paste-problem.webm
Comment 2 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2020-11-08 17:32:16 UTC
I can confirm this weird behavior. As intermediate measure I suggest default-enabling the "slang" USE flag.
What do you think Sergei?
Comment 3 Sergei Trofimovich (RETIRED) gentoo-dev 2020-11-08 18:12:04 UTC
(In reply to Lars Wendler (Polynomial-C) from comment #2)
> I can confirm this weird behavior. As intermediate measure I suggest
> default-enabling the "slang" USE flag.
> What do you think Sergei?

Sounds OK, but I think we already do it for a long while for some related reason (I vaguely remember function keys have unexpected offset):

IUSE="+edit gpm nls samba sftp +slang spell test unicode X +xdg"
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2020-11-08 18:18:34 UTC
Looking at a specific problem '7;6M7;6m' sounds like unhandled escape.

Maybe we can dig a bit where handling mismatch happens.

What terminal do you both use?
- Which X11 terminal or linux console?
- What $TERM variable?
- What gpm driver is that? (Probably a /etc/conf.d/gpm value or /lib/systemd/system/gpm.service) I think it should only be used for linux console, but i'm not sure.
Comment 5 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2020-11-08 18:51:01 UTC
(In reply to Sergei Trofimovich from comment #4)
> Looking at a specific problem '7;6M7;6m' sounds like unhandled escape.
> 
> Maybe we can dig a bit where handling mismatch happens.
> 
> What terminal do you both use?
> - Which X11 terminal or linux console?

kde-apps/konsole

> - What $TERM variable?

xterm-256color

> - What gpm driver is that? (Probably a /etc/conf.d/gpm value or
> /lib/systemd/system/gpm.service) I think it should only be used for linux
> console, but i'm not sure.

sys-libs/gpm is not installed here



Some additional notes:

I can see even more escape sequences being "pasted" into mcedit by holding the left mouse button pressed inside mcedit and then start moving the mouse. This "auto-activates" constant escape sequence pasting even when I depress left mouse button again.
Comment 6 Sergei Trofimovich (RETIRED) gentoo-dev 2020-11-09 23:11:20 UTC
Aha, thank you! Reproduced locally as well.

I was confused by tmux being able to translate ncurses into something that works. Running mc on top of terminal shows the problem. Looking.
Comment 7 Sergei Trofimovich (RETIRED) gentoo-dev 2020-11-10 00:07:13 UTC
The bug seems to be in the code that attemts to distinct between X10 (old simple mode, enabled by "\e[?9h") and XTERM (extended mode, enabled by "\e[?1000h"). It looks like xterm does not support X10 mode, And yet mc thinks it does and tries to handle the keys:

Both `xmouse_seq` and `xmouse_extended_seq` are initialized at:


    /* There's only one termcap entry "kmous", typically containing "\E[M" or "\E[<".
     * We need the former in xmouse_seq, the latter in xmouse_extended_seq.
     * See tickets 2956, 3954, and 4063 for details. */
    if (xmouse_seq != NULL)
    {
        if (strcmp (xmouse_seq, ESC_STR "[<") == 0)
            xmouse_seq = ESC_STR "[M";

        xmouse_extended_seq = ESC_STR "[<";
    }

This hack restores the mouse support. I'll file upstream bug.

$ git diff | cat
diff --git a/lib/tty/key.c b/lib/tty/key.c
index 4abfc71d7..22769871e 100644
--- a/lib/tty/key.c
+++ b/lib/tty/key.c
@@ -2124,8 +2124,7 @@ tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block)
         gboolean extended = c == MCKEY_EXTENDED_MOUSE;

 #ifdef KEY_MOUSE
-        extended = extended || (c == KEY_MOUSE && xmouse_seq == NULL
-                                && xmouse_extended_seq != NULL);
+        extended = extended || (c == KEY_MOUSE && xmouse_extended_seq != NULL);
 #endif /* KEY_MOUSE */

         xmouse_get_event (event, extended);
Comment 8 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2020-11-10 00:43:49 UTC
Wrong bug. My apologies
Comment 9 Marek Szuba (RETIRED) archtester gentoo-dev 2021-07-13 11:47:38 UTC
I have seen this happen in recent versions of x11-terms/xterm as well as in x11-terms/gnome-terminal, not in x11-terms/rxvt-unicode though.

Will just merge the proposed patch - my tests suggest it helps under xterm without breaking rxvt-unicode or the USE=slang case, and this patch breaking mouse support under ncurses5 is not a problem for us.
Comment 10 Larry the Git Cow gentoo-dev 2021-07-13 12:02:54 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=25aac466357a303896fa961e759488e9d4ea6eee

commit 25aac466357a303896fa961e759488e9d4ea6eee
Author:     Marek Szuba <marecki@gentoo.org>
AuthorDate: 2021-07-13 11:46:02 +0000
Commit:     Marek Szuba <marecki@gentoo.org>
CommitDate: 2021-07-13 11:57:41 +0000

    app-misc/mc: fix mouse-key garbage output on ncurses and modern terminals
    
    While at it, bump to EAPI 8 and fix some DEPEND/BDEPEND confusion.
    
    Closes: https://bugs.gentoo.org/753578
    Signed-off-by: Marek Szuba <marecki@gentoo.org>

 app-misc/mc/files/mc-4.8.26-ncurses-mouse.patch |  16 +++
 app-misc/mc/mc-4.8.26-r3.ebuild                 | 125 ++++++++++++++++++++++++
 2 files changed, 141 insertions(+)