From c511bd79460fb883a4eb7d110a45fac0667fb5b3 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 2 Sep 2011 13:30:59 +0400 Subject: [PATCH] Fix of mouse and ca capabilities check. Based on patch from Andrey V. Malyshev http://mail.gnome.org/archives/mc-devel/2005-November/msg00052.html Signed-off-by: Andrew Borodin --- lib/tty/tty-internal.h | 4 ++++ lib/tty/tty.c | 15 +++++++++++++-- lib/tty/win.c | 7 +++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/tty/tty-internal.h b/lib/tty/tty-internal.h index 450b1fe75..1e89a95df 100644 --- a/lib/tty/tty-internal.h +++ b/lib/tty/tty-internal.h @@ -36,6 +36,10 @@ extern gboolean ugly_line_drawing; /* The mouse is currently: TRUE - enabled, FALSE - disabled */ extern gboolean mouse_enabled; +/* terminal ca capabilities */ +extern char *smcup; +extern char *rmcup; + /*** declarations of public functions ************************************************************/ char *mc_tty_normalize_from_utf8 (const char *); diff --git a/lib/tty/tty.c b/lib/tty/tty.c index fe2dc49e4..f8b0149fd 100644 --- a/lib/tty/tty.c +++ b/lib/tty/tty.c @@ -243,8 +243,19 @@ tty_init_xterm_support (gboolean is_xterm) termvalue = getenv ("TERM"); - /* Check mouse capabilities */ - xmouse_seq = tty_tgetstr ("Km"); + /* Check mouse and ca capabilities */ + /* terminfo/termcap structures have been already initialized, + in slang_init() or/and init_curses() */ + /* Check terminfo at first, then check termcap */ + xmouse_seq = tty_tgetstr ("kmous"); + if (xmouse_seq == NULL) + xmouse_seq = tty_tgetstr ("Km"); + smcup = tty_tgetstr ("smcup"); + if (smcup == NULL) + smcup = tty_tgetstr ("ti"); + rmcup = tty_tgetstr ("rmcup"); + if (rmcup == NULL) + rmcup = tty_tgetstr ("te"); if (strcmp (termvalue, "cygwin") == 0) { diff --git a/lib/tty/win.c b/lib/tty/win.c index f55bd8d6e..ac14e6ec6 100644 --- a/lib/tty/win.c +++ b/lib/tty/win.c @@ -34,6 +34,7 @@ #include "lib/global.h" #include "lib/util.h" /* is_printable() */ +#include "tty-internal.h" #include "tty.h" /* tty_gotoyx, tty_print_char */ #include "win.h" #include "src/consaver/cons.saver.h" /* console_flag */ @@ -45,6 +46,8 @@ gboolean xterm_flag = FALSE; extern int keybar_visible; +char *smcup = NULL; +char *rmcup = NULL; /*** file scope macro definitions ****************************************************************/ @@ -95,7 +98,7 @@ anything_ready (void) void do_enter_ca_mode (void) { - if (xterm_flag) + if (xterm_flag && smcup != NULL) { fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h"); fflush (stdout); @@ -107,7 +110,7 @@ do_enter_ca_mode (void) void do_exit_ca_mode (void) { - if (xterm_flag) + if (xterm_flag && rmcup != NULL) { fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m"); fflush (stdout); -- 2.11.4.GIT