diff --git a/App.cpp b/App.cpp index 0868c8a..fc05ba4 100644 --- a/App.cpp +++ b/App.cpp @@ -19,8 +19,10 @@ namespace krikkel::NCursesPtyWindow int App::run() { - Window *ptyWindow = new Window( - Root_Window->lines() + std::mutex writeMutex; + + Window *ptyWindow = new Window(&writeMutex + , Root_Window->lines() , Root_Window->cols() , 0 , 0); diff --git a/Window.cpp b/Window.cpp index e5479d1..40eabaa 100644 --- a/Window.cpp +++ b/Window.cpp @@ -18,8 +18,8 @@ namespace krikkel::NCursesPtyWindow using gsl::narrow; using std::lock_guard; - Window::Window(int lines, int columns, int y, int x) - : NCursesWindow(lines, columns, y, x) + Window::Window(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x) + : writeToNCursesMutex(writeToNCursesMutex), 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 @@ -245,10 +245,13 @@ namespace krikkel::NCursesPtyWindow else character = *vTermCell.chars; - setcchar(&converted, &character, formatting, colorPair, NULL); - move(cellPosition.row, cellPosition.col); - chgat(1, formatting, colorPair, NULL); - add_wch(&converted); + { + lock_guard nCursesLock(*writeToNCursesMutex); + setcchar(&converted, &character, formatting, colorPair, NULL); + move(cellPosition.row, cellPosition.col); + chgat(1, formatting, colorPair, NULL); + add_wch(&converted); + } } int Window::add_wch(const cchar_t *character) @@ -263,6 +266,7 @@ namespace krikkel::NCursesPtyWindow int Window::refresh() { + lock_guard nCursesLock(*writeToNCursesMutex); move(cursorY, cursorX); return NCursesWindow::refresh(); } @@ -271,7 +275,8 @@ namespace krikkel::NCursesPtyWindow /// resizing? int Window::wresize(int rows, int cols) { - std::lock_guard writeLock(writeToPseudoTerminalMutex); + lock_guard nCursesLock(*writeToNCursesMutex); + lock_guard writeLock(writeToPseudoTerminalMutex); winsize windowSize = { .ws_row = narrow(rows) diff --git a/Window.hpp b/Window.hpp index d2f03f1..243d063 100644 --- a/Window.hpp +++ b/Window.hpp @@ -29,7 +29,7 @@ namespace krikkel::NCursesPtyWindow class Window : public NCursesWindow { public: - Window(int lines, int columns, int y, int x); + Window(std::mutex *writeToNCursesMutex, int lines, int columns, int y, int x); ~Window(); int getFdPtyClient() const; @@ -49,6 +49,7 @@ namespace krikkel::NCursesPtyWindow struct termios terminalParameters; VTerm *pseudoTerminal; std::mutex writeToPseudoTerminalMutex; + std::mutex *writeToNCursesMutex; VTermScreen *pseudoTerminalScreen; static VTermScreenCallbacks screenCallbacks; /// @todo one line is at most 4096 chars long