Skip to content

Commit 78d21da

Browse files
committed
patch 8.1.0940: MS-Windows console resizing not handled properly
Problem: MS-Windows console resizing not handled properly. Solution: Handle resizing the console better. (Nobuhiro Takasaki, closes #3968, closes #3611)
1 parent 3678f65 commit 78d21da

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

src/ex_docmd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9852,6 +9852,9 @@ ex_redraw(exarg_T *eap)
98529852
#ifdef FEAT_TITLE
98539853
if (need_maketitle)
98549854
maketitle();
9855+
#endif
9856+
#if defined(WIN3264) && !defined(FEAT_GUI_W32)
9857+
resize_console_buf();
98559858
#endif
98569859
RedrawingDisabled = r;
98579860
p_lz = p;

src/normal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5401,6 +5401,9 @@ nv_clear(cmdarg_T *cap)
54015401
# endif
54025402
#endif
54035403
redraw_later(CLEAR);
5404+
#if defined(WIN3264) && !defined(FEAT_GUI_W32)
5405+
resize_console_buf();
5406+
#endif
54045407
}
54055408
}
54065409

src/os_win32.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,8 @@ handle_focus_event(INPUT_RECORD ir)
14921492
ui_focus_change((int)g_fJustGotFocus);
14931493
}
14941494

1495+
static void ResizeConBuf(HANDLE hConsole, COORD coordScreen);
1496+
14951497
/*
14961498
* Wait until console input from keyboard or mouse is available,
14971499
* or the time is up.
@@ -1657,11 +1659,18 @@ WaitForChar(long msec, int ignore_input)
16571659
handle_focus_event(ir);
16581660
else if (ir.EventType == WINDOW_BUFFER_SIZE_EVENT)
16591661
{
1660-
/* Only call shell_resized() when the size actually change to
1661-
* avoid the screen is cleard. */
1662-
if (ir.Event.WindowBufferSizeEvent.dwSize.X != Columns
1663-
|| ir.Event.WindowBufferSizeEvent.dwSize.Y != Rows)
1662+
COORD dwSize = ir.Event.WindowBufferSizeEvent.dwSize;
1663+
1664+
// Only call shell_resized() when the size actually change to
1665+
// avoid the screen is cleard.
1666+
if (dwSize.X != Columns || dwSize.Y != Rows)
1667+
{
1668+
CONSOLE_SCREEN_BUFFER_INFO csbi;
1669+
GetConsoleScreenBufferInfo(g_hConOut, &csbi);
1670+
dwSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
1671+
ResizeConBuf(g_hConOut, dwSize);
16641672
shell_resized();
1673+
}
16651674
}
16661675
#ifdef FEAT_MOUSE
16671676
else if (ir.EventType == MOUSE_EVENT
@@ -6327,7 +6336,7 @@ write_chars(
63276336
* character was written, otherwise we get stuck. */
63286337
if (WriteConsoleOutputCharacterW(g_hConOut, unicodebuf, length,
63296338
coord, &cchwritten) == 0
6330-
|| cchwritten == 0)
6339+
|| cchwritten == 0 || cchwritten == (DWORD)-1)
63316340
cchwritten = 1;
63326341
}
63336342
else
@@ -6361,7 +6370,7 @@ write_chars(
63616370
* character was written, otherwise we get stuck. */
63626371
if (WriteConsoleOutputCharacter(g_hConOut, (LPCSTR)pchBuf, cbToWrite,
63636372
coord, &written) == 0
6364-
|| written == 0)
6373+
|| written == 0 || written == (DWORD)-1)
63656374
written = 1;
63666375
}
63676376
else
@@ -7707,7 +7716,7 @@ vtp_flag_init(void)
77077716

77087717
}
77097718

7710-
#ifndef FEAT_GUI_W32
7719+
#if !defined(FEAT_GUI_W32) || defined(PROTO)
77117720

77127721
static void
77137722
vtp_init(void)
@@ -7931,3 +7940,28 @@ is_conpty_stable(void)
79317940
{
79327941
return conpty_stable;
79337942
}
7943+
7944+
#if !defined(FEAT_GUI_W32) || defined(PROTO)
7945+
void
7946+
resize_console_buf(void)
7947+
{
7948+
CONSOLE_SCREEN_BUFFER_INFO csbi;
7949+
COORD coord;
7950+
SMALL_RECT newsize;
7951+
7952+
if (GetConsoleScreenBufferInfo(g_hConOut, &csbi))
7953+
{
7954+
coord.X = SRWIDTH(csbi.srWindow);
7955+
coord.Y = SRHEIGHT(csbi.srWindow);
7956+
SetConsoleScreenBufferSize(g_hConOut, coord);
7957+
7958+
newsize.Left = 0;
7959+
newsize.Top = 0;
7960+
newsize.Right = coord.X - 1;
7961+
newsize.Bottom = coord.Y - 1;
7962+
SetConsoleWindowInfo(g_hConOut, TRUE, &newsize);
7963+
7964+
SetConsoleScreenBufferSize(g_hConOut, coord);
7965+
}
7966+
}
7967+
#endif

src/proto/os_win32.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ int is_term_win32(void);
7575
int has_vtp_working(void);
7676
int has_conpty_working(void);
7777
int is_conpty_stable(void);
78+
void resize_console_buf(void);
7879
/* vim: set ft=c : */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ static char *(features[]) =
779779

780780
static int included_patches[] =
781781
{ /* Add new patch number below this line */
782+
/**/
783+
940,
782784
/**/
783785
939,
784786
/**/

0 commit comments

Comments
 (0)