Skip to content

Commit

Permalink
Do not send resize request when window size was not changed
Browse files Browse the repository at this point in the history
In case of Vim, resize event seems to be sent when it started.
It causes of inputting noisy chars when TTY resizer is enabled.
Thus this change prevents to send resize request to TTY resizer when
"real" resize event (resizing console by the user) is not been sent.
  • Loading branch information
YaSuenag committed Oct 20, 2024
1 parent 930f936 commit 2169c4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 11 additions & 2 deletions SimpleCom/SerialConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef struct {
SimpleCom::SerialConnection *conn;
} TStdOutRedirectorParam;

static COORD current_window_sz = { 0 };


SimpleCom::SerialConnection::SerialConnection(TString& device, DCB* dcb, HWND hwnd, HANDLE hStdIn, HANDLE hStdOut, bool useTTYResizer, LPCTSTR logfilename, bool enableStdinLogging) :
_device(device),
Expand Down Expand Up @@ -237,8 +239,10 @@ bool SimpleCom::SerialConnection::StdInRedirector(const HANDLE hSerial, const HA
ProcessKeyEvents(inputs[idx].Event.KeyEvent, writer);
}
else if ((inputs[idx].EventType == WINDOW_BUFFER_SIZE_EVENT) && _useTTYResizer) {
CopyMemory(&newConsoleSize, &inputs[idx].Event.WindowBufferSizeEvent, sizeof(COORD));
isConsoleSizeUpdated = true;
if(memcmp(&current_window_sz, &inputs[idx].Event.WindowBufferSizeEvent.dwSize, sizeof(COORD)) != 0) {
newConsoleSize = inputs[idx].Event.WindowBufferSizeEvent.dwSize;
isConsoleSizeUpdated = true;
}
}

if (isConsoleSizeUpdated) {
Expand All @@ -248,6 +252,7 @@ bool SimpleCom::SerialConnection::StdInRedirector(const HANDLE hSerial, const HA
int len = snprintf(buf, sizeof(buf), "%c%d" RESIZER_SEPARATOR "%d%c", RESIZER_START_MARKER, newConsoleSize.Y, newConsoleSize.X, RESIZER_END_MARKER);
writer.PutData(buf, len);
isConsoleSizeUpdated = false;
current_window_sz = newConsoleSize;
}
}
}
Expand Down Expand Up @@ -288,6 +293,10 @@ bool SimpleCom::SerialConnection::DoSession(bool allowDetachDevice) {
OVERLAPPED serialReadOverlapped = { 0 };
serialReadOverlapped.hEvent = hIoEvent.handle();

CONSOLE_SCREEN_BUFFER_INFO console_info = { 0 };
CALL_WINAPI_WITH_DEBUGLOG(GetConsoleScreenBufferInfo(_hStdOut, &console_info), TRUE, __FILE__, __LINE__)
current_window_sz = console_info.dwSize;

// Create stdout redirector
TStdOutRedirectorParam param = {
.hSerial = hSerial.handle(),
Expand Down
4 changes: 0 additions & 4 deletions tty-resizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,3 @@ Both `Row` and `Col` are unsigned short.
When `0x12` (DC2) is received in tty-resizer, subsequent chars are captured in tty-resizer, and they will not propagate to real TTY. `t` is terminator, then capture mode in tty-resizer is finished, and subsequent chars are propagated to real TTY, and `TIOCSWINSZ` ioctl would be issued to the specified TTY. `c` means "cancel" for tty-resizer, then capture mode will be finished, and happens nothing.

0-9 and `;`, `t`, `c` is valid chars on capture mode. Capture mode will be aborted when other char is received - it would be treated as `c`.

# Known issue

TTY Resizer might not work fine with full-screen application like Vim. Noisy chars (for Vim) might be input, and TTY Resizer might not be able to set resized console size while that app is running.

0 comments on commit 2169c4b

Please sign in to comment.