0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

patch 9.0.0868: MS-Windows: after Vim exits console resizing problem

Problem:    MS-Windows: after Vim exits console resizing does not work
            properly.
Solution:   Restore screen behavior checks for various WT and VTP
            combinations. (Christopher Plewright, closes #11526,
            closes #11507)
This commit is contained in:
Christopher Plewright 2022-11-12 18:46:05 +00:00 committed by Bram Moolenaar
parent d6e91385f0
commit 1140b51e83
3 changed files with 38 additions and 20 deletions

View File

@ -202,7 +202,7 @@ static void vtp_sgr_bulk(int arg);
static void vtp_sgr_bulks(int argc, int *argv);
static int wt_working = 0;
static void wt_init();
static void wt_init(void);
static int g_color_index_bg = 0;
static int g_color_index_fg = 7;
@ -238,6 +238,7 @@ static int suppress_winsize = 1; // don't fiddle with console
static char_u *exe_path = NULL;
static BOOL win8_or_later = FALSE;
static BOOL win11_or_later = FALSE;
/*
* Get version number including build number
@ -893,6 +894,10 @@ PlatformId(void)
|| ovi.dwMajorVersion > 6)
win8_or_later = TRUE;
if ((ovi.dwMajorVersion == 10 && ovi.dwBuildNumber >= 22000)
|| ovi.dwMajorVersion > 10)
win11_or_later = TRUE;
#ifdef HAVE_ACL
// Enable privilege for getting or setting SACLs.
win32_enable_privilege(SE_SECURITY_NAME, TRUE);
@ -2683,6 +2688,11 @@ SaveConsoleBuffer(
}
cb->IsValid = TRUE;
// VTP uses alternate screen buffer.
// No need to save buffer contents for restoration.
if (win11_or_later && vtp_working)
return TRUE;
/*
* Allocate a buffer large enough to hold the entire console screen
* buffer. If this ConsoleBuffer structure has already been initialized
@ -2776,6 +2786,11 @@ RestoreConsoleBuffer(
SMALL_RECT WriteRegion;
int i;
// VTP uses alternate screen buffer.
// No need to restore buffer contents.
if (win11_or_later && vtp_working)
return TRUE;
if (cb == NULL || !cb->IsValid)
return FALSE;
@ -5736,7 +5751,9 @@ termcap_mode_start(void)
if (g_fTermcapMode)
return;
if (!p_rs && USE_VTP)
// VTP uses alternate screen buffer.
// Switch to a new alternate screen buffer.
if (win11_or_later && p_rs && vtp_working)
vtp_printf("\033[?1049h");
SaveConsoleBuffer(&g_cbNonTermcap);
@ -5816,17 +5833,22 @@ termcap_mode_end(void)
# endif
RestoreConsoleBuffer(cb, p_rs);
restore_console_color_rgb();
SetConsoleCursorInfo(g_hConOut, &g_cci);
if (p_rs || exiting)
// VTP uses alternate screen buffer.
// Switch back to main screen buffer.
if (exiting && win11_or_later && p_rs && vtp_working)
vtp_printf("\033[?1049l");
if (!USE_WT && (p_rs || exiting))
{
/*
* Clear anything that happens to be on the current line.
*/
coord.X = 0;
coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1));
FillConsoleOutputCharacter(g_hConOut, ' ',
cb->Info.dwSize.X, coord, &dwDummy);
if (!vtp_working)
FillConsoleOutputCharacter(g_hConOut, ' ',
cb->Info.dwSize.X, coord, &dwDummy);
/*
* The following is just for aesthetics. If we are exiting without
* restoring the screen, then we want to have a prompt string
@ -5842,10 +5864,7 @@ termcap_mode_end(void)
*/
SetConsoleCursorPosition(g_hConOut, coord);
}
if (!p_rs && USE_VTP)
vtp_printf("\033[?1049l");
SetConsoleCursorInfo(g_hConOut, &g_cci);
g_fTermcapMode = FALSE;
}
#endif // !FEAT_GUI_MSWIN || VIMDLL
@ -7946,8 +7965,12 @@ mch_setenv(char *var, char *value, int x UNUSED)
* Not stable now.
*/
#define CONPTY_STABLE_BUILD MAKE_VER(10, 0, 32767) // T.B.D.
// Note: Windows 11 (build >= 22000 means Windows 11, even though the major
// version says 10!)
// Notes:
// Win 10 22H2 Final is build 19045, it's conpty is widely used.
// Strangely, 19045 is newer but is a lower build number than the 2020 insider
// preview which had a build 19587. And, not sure how stable that was?
// Win Server 2022 (May 10, 2022) is build 20348, its conpty is widely used.
// Win 11 starts from build 22000, even though the major version says 10!
static void
vtp_flag_init(void)
@ -8202,13 +8225,7 @@ vtp_sgr_bulks(
static void
wt_init(void)
{
wt_working = (mch_getenv("WT_SESSION") != NULL);
}
int
use_wt(void)
{
return USE_WT;
wt_working = mch_getenv("WT_SESSION") != NULL;
}
# ifdef FEAT_TERMGUICOLORS

View File

@ -72,7 +72,6 @@ void set_alist_count(void);
void fix_arg_enc(void);
int mch_setenv(char *var, char *value, int x);
int vtp_printf(char *format, ...);
int use_wt(void);
void get_default_console_color(int *cterm_fg, int *cterm_bg, guicolor_T *gui_fg, guicolor_T *gui_bg);
void control_console_color_rgb(void);
int use_vtp(void);

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
868,
/**/
867,
/**/