patch 8.2.0774: t_TI and t_TE are output when using 'visualbell'

Problem:    t_TI and t_TE are output when using 'visualbell'. (Dominique
            Pelle)
Solution:   Do not change the terminal mode for a short sleep.  Do not output
            t_TI and t_TE when switching to/from TMODE_SLEEP. Make tmode an
            enum.
diff --git a/src/globals.h b/src/globals.h
index 11e06be..60c3c66 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1171,7 +1171,7 @@
 EXTERN int	term_console INIT(= FALSE); // set to TRUE when console used
 #endif
 EXTERN int	termcap_active INIT(= FALSE);	// set by starttermcap()
-EXTERN int	cur_tmode INIT(= TMODE_COOK);	// input terminal mode
+EXTERN tmode_T	cur_tmode INIT(= TMODE_COOK);	// input terminal mode
 EXTERN int	bangredo INIT(= FALSE);	    // set to TRUE with ! command
 EXTERN int	searchcmdlen;		    // length of previous search cmd
 #ifdef FEAT_SYN_HL
diff --git a/src/os_amiga.c b/src/os_amiga.c
index 58e462d..850c26a 100644
--- a/src/os_amiga.c
+++ b/src/os_amiga.c
@@ -977,7 +977,7 @@
  *	it sends a 0 to the console to make it back into a CON: from a RAW:
  */
     void
-mch_settmode(int tmode)
+mch_settmode(tmode_T tmode)
 {
 #if defined(__AROS__) || defined(__amigaos4__)
     if (!SetMode(raw_in, tmode == TMODE_RAW ? 1 : 0))
diff --git a/src/os_mswin.c b/src/os_mswin.c
index 1c987c2..8000953 100644
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -553,7 +553,7 @@
 
 #if (defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)) || defined(PROTO)
     void
-mch_settmode(int tmode UNUSED)
+mch_settmode(tmode_T tmode UNUSED)
 {
     // nothing to do
 }
diff --git a/src/os_unix.c b/src/os_unix.c
index 9162f5b..6c308af 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -215,7 +215,8 @@
 static int dont_check_job_ended = 0;
 #endif
 
-static int curr_tmode = TMODE_COOK;	// contains current terminal mode
+// Current terminal mode from mch_settmode().  Can differ from cur_tmode.
+static tmode_T mch_cur_tmode = TMODE_COOK;
 
 #ifdef USE_XSMP
 typedef struct
@@ -581,7 +582,7 @@
     void
 mch_delay(long msec, int ignoreinput)
 {
-    int		old_tmode;
+    tmode_T	old_tmode;
 #ifdef FEAT_MZSCHEME
     long	total = msec; // remember original value
 #endif
@@ -591,9 +592,10 @@
 	// Go to cooked mode without echo, to allow SIGINT interrupting us
 	// here.  But we don't want QUIT to kill us (CTRL-\ used in a
 	// shell may produce SIGQUIT).
+	// Only do this if sleeping for more than half a second.
 	in_mch_delay = TRUE;
-	old_tmode = curr_tmode;
-	if (curr_tmode == TMODE_RAW)
+	old_tmode = mch_cur_tmode;
+	if (mch_cur_tmode == TMODE_RAW && msec > 500)
 	    settmode(TMODE_SLEEP);
 
 	/*
@@ -650,7 +652,8 @@
 	while (total > 0);
 #endif
 
-	settmode(old_tmode);
+	if (msec > 500)
+	    settmode(old_tmode);
 	in_mch_delay = FALSE;
     }
     else
@@ -3461,7 +3464,7 @@
 }
 
     void
-mch_settmode(int tmode)
+mch_settmode(tmode_T tmode)
 {
     static int first = TRUE;
 
@@ -3558,7 +3561,7 @@
 	ttybnew.sg_flags &= ~(ECHO);
     ioctl(read_cmd_fd, TIOCSETN, &ttybnew);
 #endif
-    curr_tmode = tmode;
+    mch_cur_tmode = tmode;
 }
 
 /*
@@ -4455,7 +4458,7 @@
     char	*ifn = NULL;
     char	*ofn = NULL;
 #endif
-    int		tmode = cur_tmode;
+    tmode_T	tmode = cur_tmode;
     char_u	*newcmd;	// only needed for unix
     int		x;
 
@@ -4549,7 +4552,7 @@
     char_u	*cmd,
     int		options)	// SHELL_*, see vim.h
 {
-    int		tmode = cur_tmode;
+    tmode_T	tmode = cur_tmode;
     pid_t	pid;
     pid_t	wpid = 0;
     pid_t	wait_pid = 0;
@@ -5939,7 +5942,7 @@
     void
 mch_breakcheck(int force)
 {
-    if ((curr_tmode == TMODE_RAW || force)
+    if ((mch_cur_tmode == TMODE_RAW || force)
 			       && RealWaitForChar(read_cmd_fd, 0L, NULL, NULL))
 	fill_input_buf(FALSE);
 }
diff --git a/src/os_vms.c b/src/os_vms.c
index 96fbc17..b8ad788 100644
--- a/src/os_vms.c
+++ b/src/os_vms.c
@@ -112,7 +112,7 @@
 }
 
     void
-mch_settmode(int tmode)
+mch_settmode(tmode_T tmode)
 {
     int	status;
 
diff --git a/src/os_win32.c b/src/os_win32.c
index d77e216..edd5cda 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -3600,7 +3600,7 @@
  * set the tty in (raw) ? "raw" : "cooked" mode
  */
     void
-mch_settmode(int tmode)
+mch_settmode(tmode_T tmode)
 {
     DWORD cmodein;
     DWORD cmodeout;
diff --git a/src/proto/os_amiga.pro b/src/proto/os_amiga.pro
index 8e12f4d..b2ad9c3 100644
--- a/src/proto/os_amiga.pro
+++ b/src/proto/os_amiga.pro
@@ -31,7 +31,7 @@
 int mch_nodetype(char_u *name);
 void mch_early_init(void);
 void mch_exit(int r);
-void mch_settmode(int tmode);
+void mch_settmode(tmode_T tmode);
 int mch_get_shellsize(void);
 void mch_set_shellsize(void);
 void mch_new_shellsize(void);
diff --git a/src/proto/os_mswin.pro b/src/proto/os_mswin.pro
index ade7cc2..e8a6cb9 100644
--- a/src/proto/os_mswin.pro
+++ b/src/proto/os_mswin.pro
@@ -10,7 +10,7 @@
 int mch_isFullName(char_u *fname);
 void slash_adjust(char_u *p);
 int vim_stat(const char *name, stat_T *stp);
-void mch_settmode(int tmode);
+void mch_settmode(tmode_T tmode);
 int mch_get_shellsize(void);
 void mch_set_shellsize(void);
 void mch_new_shellsize(void);
diff --git a/src/proto/os_unix.pro b/src/proto/os_unix.pro
index b9db0fc..cb84994 100644
--- a/src/proto/os_unix.pro
+++ b/src/proto/os_unix.pro
@@ -48,7 +48,7 @@
 void mch_early_init(void);
 void mch_free_mem(void);
 void mch_exit(int r);
-void mch_settmode(int tmode);
+void mch_settmode(tmode_T tmode);
 void get_stty(void);
 int get_tty_info(int fd, ttyinfo_T *info);
 void mch_setmouse(int on);
diff --git a/src/proto/os_vms.pro b/src/proto/os_vms.pro
index c1cfd44..b58118d 100644
--- a/src/proto/os_vms.pro
+++ b/src/proto/os_vms.pro
@@ -1,5 +1,5 @@
 /* os_vms.c */
-void mch_settmode(int tmode);
+void mch_settmode(tmode_T tmode);
 int mch_get_shellsize(void);
 void mch_set_shellsize(void);
 char_u *mch_getenv(char_u *lognam);
diff --git a/src/proto/os_win32.pro b/src/proto/os_win32.pro
index 15c1323..d8f9ac3 100644
--- a/src/proto/os_win32.pro
+++ b/src/proto/os_win32.pro
@@ -39,7 +39,7 @@
 vim_acl_T mch_get_acl(char_u *fname);
 void mch_set_acl(char_u *fname, vim_acl_T acl);
 void mch_free_acl(vim_acl_T acl);
-void mch_settmode(int tmode);
+void mch_settmode(tmode_T tmode);
 int mch_get_shellsize(void);
 void mch_set_shellsize(void);
 void mch_new_shellsize(void);
diff --git a/src/term.c b/src/term.c
index 1260c9a..a575227 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3471,7 +3471,12 @@
 #endif
 	    if (tmode != TMODE_RAW)
 		mch_setmouse(FALSE);	// switch mouse off
-	    if (termcap_active)
+
+	    // Disable bracketed paste and modifyOtherKeys in cooked mode.
+	    // Avoid doing this too often, on some terminals the codes are not
+	    // handled properly.
+	    if (termcap_active && tmode != TMODE_SLEEP
+						   && cur_tmode != TMODE_SLEEP)
 	    {
 		if (tmode != TMODE_RAW)
 		{
diff --git a/src/term.h b/src/term.h
index b9535ee..dca48d1 100644
--- a/src/term.h
+++ b/src/term.h
@@ -209,7 +209,9 @@
 #define T_SSI	(TERM_STR(KS_SSI))	// save icon text
 #define T_SRI	(TERM_STR(KS_SRI))	// restore icon text
 
-#define TMODE_COOK	0   // terminal mode for external cmds and Ex mode
-#define TMODE_SLEEP	1   // terminal mode for sleeping (cooked but no echo)
-#define TMODE_RAW	2   // terminal mode for Normal and Insert mode
-#define TMODE_UNKNOWN   9   // after executing a shell
+typedef enum {
+    TMODE_COOK,	    // terminal mode for external cmds and Ex mode
+    TMODE_SLEEP,    // terminal mode for sleeping (cooked but no echo)
+    TMODE_RAW,	    // terminal mode for Normal and Insert mode
+    TMODE_UNKNOWN   // after executing a shell
+} tmode_T;
diff --git a/src/version.c b/src/version.c
index 6a28ae3..9511379 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    774,
+/**/
     773,
 /**/
     772,