From f52f0e354a16da7df8eea49efa00834adf0b4b59 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Wed, 6 Dec 2017 21:36:22 -0500 Subject: [PATCH] User resizing for the Win32 console (recent Windows versions only). --- win32/pdckbd.c | 18 +++++++++++++++--- win32/pdcscrn.c | 42 +++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/win32/pdckbd.c b/win32/pdckbd.c index ff8464b4..298130db 100644 --- a/win32/pdckbd.c +++ b/win32/pdckbd.c @@ -36,9 +36,10 @@ static int save_press = 0; #define KEV save_ip.Event.KeyEvent #define MEV save_ip.Event.MouseEvent +#define REV save_ip.Event.WindowBufferSizeEvent /************************************************************************ - * Table for key code translation of function keys in keypad mode * + * Table for key code translation of function keys in keypad mode * * These values are for strict IBM keyboard compatibles only * ************************************************************************/ @@ -614,7 +615,8 @@ int PDC_get_key(void) ReadConsoleInput(pdc_con_in, &save_ip, 1, &count); event_count--; - if (save_ip.EventType == MOUSE_EVENT) + if (save_ip.EventType == MOUSE_EVENT || + save_ip.EventType == WINDOW_BUFFER_SIZE_EVENT) key_count = 1; else if (save_ip.EventType == KEY_EVENT) key_count = _get_key_count(); @@ -631,6 +633,16 @@ int PDC_get_key(void) case MOUSE_EVENT: return _process_mouse_event(); + + case WINDOW_BUFFER_SIZE_EVENT: + if (REV.dwSize.Y != LINES || REV.dwSize.X != COLS) + { + if (!SP->resized) + { + SP->resized = TRUE; + return KEY_RESIZE; + } + } } } @@ -655,7 +667,7 @@ int PDC_mouse_set(void) had on startup, and clear all other flags */ SetConsoleMode(pdc_con_in, SP->_trap_mbe ? - (ENABLE_MOUSE_INPUT|0x0080) : (pdc_quick_edit|0x0080)); + (ENABLE_MOUSE_INPUT|0x0088) : (pdc_quick_edit|0x0088)); memset(&old_mouse_status, 0, sizeof(old_mouse_status)); diff --git a/win32/pdcscrn.c b/win32/pdcscrn.c index bc7dfb4d..a86f50e0 100644 --- a/win32/pdcscrn.c +++ b/win32/pdcscrn.c @@ -512,30 +512,38 @@ int PDC_resize_screen(int nlines, int ncols) SMALL_RECT rect; COORD size, max; - if (nlines < 2 || ncols < 2) - return ERR; + if (nlines || ncols) + { + if (nlines < 2 || ncols < 2) + return ERR; - max = GetLargestConsoleWindowSize(pdc_con_out); + max = GetLargestConsoleWindowSize(pdc_con_out); - rect.Left = rect.Top = 0; - rect.Right = ncols - 1; + rect.Left = rect.Top = 0; + rect.Right = ncols - 1; - if (rect.Right > max.X) - rect.Right = max.X; + if (rect.Right > max.X) + rect.Right = max.X; - rect.Bottom = nlines - 1; + rect.Bottom = nlines - 1; - if (rect.Bottom > max.Y) - rect.Bottom = max.Y; + if (rect.Bottom > max.Y) + rect.Bottom = max.Y; - size.X = rect.Right + 1; - size.Y = rect.Bottom + 1; + size.X = rect.Right + 1; + size.Y = rect.Bottom + 1; - _fit_console_window(pdc_con_out, &rect); - SetConsoleScreenBufferSize(pdc_con_out, size); - _fit_console_window(pdc_con_out, &rect); - SetConsoleScreenBufferSize(pdc_con_out, size); - SetConsoleActiveScreenBuffer(pdc_con_out); + _fit_console_window(pdc_con_out, &rect); + SetConsoleScreenBufferSize(pdc_con_out, size); + _fit_console_window(pdc_con_out, &rect); + SetConsoleScreenBufferSize(pdc_con_out, size); + SetConsoleActiveScreenBuffer(pdc_con_out); + } + + PDC_flushinp(); + + SP->resized = FALSE; + SP->cursrow = SP->curscol = 0; return OK; }