From 6d02539162dbe4d938dac0f939a64c8b33dbec7d Mon Sep 17 00:00:00 2001 From: Christian Burger Date: Tue, 5 Apr 2022 12:34:35 +0200 Subject: [PATCH] =?UTF-8?q?fixes=20#4=20=E2=80=94=20albeit=20very=20slow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #2 needs fixing to remedy that problem with performance --- NCursesPtyApp.cpp | 5 +++++ NCursesPtyWindow.cpp | 21 +++++++++++++++++++-- NCursesPtyWindow.hpp | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/NCursesPtyApp.cpp b/NCursesPtyApp.cpp index 971b303..7d3e3b8 100644 --- a/NCursesPtyApp.cpp +++ b/NCursesPtyApp.cpp @@ -46,6 +46,11 @@ namespace krikkel::NCursesPtyWindow while(true) { input = ptyWindow->getch(); + if(input == KEY_RESIZE) + { + ptyWindow->wresize(Root_Window->lines(), Root_Window->cols()); + continue; + } ptyWindow->writeToClient((unsigned char) input); } diff --git a/NCursesPtyWindow.cpp b/NCursesPtyWindow.cpp index 44167bd..6bb3b9d 100644 --- a/NCursesPtyWindow.cpp +++ b/NCursesPtyWindow.cpp @@ -20,6 +20,7 @@ namespace krikkel::NCursesPtyWindow : NCursesWindow(lines, columns, y, x) { // to get the original terminal we need to shutdown ncurses for a moment + /// @todo maybe try `reset_prog_mode()` and `reset_shell_mode()` instead ::endwin(); tcgetattr(STDIN_FILENO, &terminalParameters); ::refresh(); @@ -32,7 +33,6 @@ namespace krikkel::NCursesPtyWindow openpty(&fdPtyHost, &fdPtyClient, NULL, &terminalParameters, &windowSize); pseudoTerminal = vterm_new(windowSize.ws_row, windowSize.ws_col); - __debug_log("window size (x: " + std::to_string(windowSize.ws_col) + ", y: " + std::to_string(windowSize.ws_row) + ")"); vterm_set_utf8(pseudoTerminal, true); pseudoTerminalScreen = vterm_obtain_screen(pseudoTerminal); vterm_screen_reset(pseudoTerminalScreen, true); @@ -42,7 +42,8 @@ namespace krikkel::NCursesPtyWindow keypad(false); /// @todo block all signals, this thread does not handle any - readPtyClientThread = std::thread(&NCursesPtyWindow::readFromPtyClientThreadMethod, this); + readPtyClientThread = + std::thread(&NCursesPtyWindow::readFromPtyClientThreadMethod, this); } NCursesPtyWindow::~NCursesPtyWindow() @@ -129,6 +130,7 @@ namespace krikkel::NCursesPtyWindow int NCursesPtyWindow::handlerMoveCursor(VTermPos pos, VTermPos oldpos, int visible) { + /// @todo maybe use `mvcur()` instead? cursorX = pos.col; cursorY = pos.row; refresh(); @@ -249,6 +251,21 @@ namespace krikkel::NCursesPtyWindow return NCursesWindow::refresh(); } + /// @todo potential racing condition where drawing into terminal while + /// resizing? + int NCursesPtyWindow::wresize(int rows, int cols) + { + winsize windowSize = + { + .ws_row = narrow(rows) + , .ws_col = narrow(cols) + }; + ioctl(fdPtyHost, TIOCSWINSZ, &windowSize); + vterm_set_size(pseudoTerminal, rows, cols); + + return NCursesWindow::wresize(rows, cols); + } + int NCursesPtyWindow::staticHandlerDamage(VTermRect rect, void *user) { NCursesPtyWindow *instance = static_cast(user); diff --git a/NCursesPtyWindow.hpp b/NCursesPtyWindow.hpp index 3ea1470..823bb26 100644 --- a/NCursesPtyWindow.hpp +++ b/NCursesPtyWindow.hpp @@ -28,6 +28,7 @@ namespace krikkel::NCursesPtyWindow int add_wch(cchar_t *character); int refresh() override; + int wresize(int rows, int cols); private: int fdPtyHost, fdPtyClient;