From 52e1c3c04415dad29c7f529c9d5a2f32d25b6786 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 9 Apr 2005 17:21:14 +0000 Subject: [PATCH] MiniTerminal now sets the correct window size and updates it when resized. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12278 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/apps/miniterminal/MiniView.cpp | 58 ++++++++++++++++------ src/tests/apps/miniterminal/MiniView.h | 3 ++ src/tests/apps/miniterminal/ViewBuffer.cpp | 2 +- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/tests/apps/miniterminal/MiniView.cpp b/src/tests/apps/miniterminal/MiniView.cpp index 9c5f7c4a8a..1ee07e74fc 100644 --- a/src/tests/apps/miniterminal/MiniView.cpp +++ b/src/tests/apps/miniterminal/MiniView.cpp @@ -74,6 +74,9 @@ MiniView::MiniView(BRect frame) MiniView::~MiniView() { + kill_thread(fConsoleWriter); + kill_thread(fShellExecutor); + kill_thread(fShellProcess); } void @@ -90,9 +93,9 @@ MiniView::Start() setsid(); // move our stdin and stdout to the console - /*dup2(fSlaveFD, 0); + dup2(fSlaveFD, 0); dup2(fSlaveFD, 1); - dup2(fSlaveFD, 2);*/ + dup2(fSlaveFD, 2); if (SpawnThreads() != B_OK) TRACE(("error in SpawnThreads\n")); @@ -183,11 +186,18 @@ MiniView::OpenTTY() // set terminal interface tcsetattr(fSlaveFD, TCSANOW, &tio); - // set window size (currently disabled) - /*ws.ws_row = rows; + // set window size + winsize ws; + int32 rows, cols; + GetSize(&cols, &rows); + ws.ws_row = rows; ws.ws_col = cols; - - ioctl(con->tty_slave_fd, TIOCSWINSZ, &ws);*/ + if (LockLooper()) { + ws.ws_xpixel = Bounds().IntegerWidth(); + ws.ws_ypixel = Bounds().IntegerHeight(); + UnlockLooper(); + } + ioctl(fSlaveFD, TIOCSWINSZ, &ws); } break; } @@ -206,6 +216,22 @@ MiniView::OpenTTY() return B_OK; } +void +MiniView::FrameResized(float width, float height) +{ + ViewBuffer::FrameResized(width, height); + + winsize ws; + int32 rows, cols; + GetSize(&cols, &rows); + ws.ws_row = rows; + ws.ws_col = cols; + ws.ws_xpixel = (uint16)width; + ws.ws_ypixel = (uint16)height; + ioctl(fSlaveFD, TIOCSWINSZ, &ws); +} + + void MiniView::KeyDown(const char *bytes, int32 numBytes) { @@ -218,16 +244,16 @@ MiniView::KeyDown(const char *bytes, int32 numBytes) } else { switch (bytes[0]) { case B_LEFT_ARROW: - write(fMasterFD, LEFT_ARROW_KEY_CODE, sizeof(LEFT_ARROW_KEY_CODE)); + write(fMasterFD, LEFT_ARROW_KEY_CODE, sizeof(LEFT_ARROW_KEY_CODE) - 1); break; case B_RIGHT_ARROW: - write(fMasterFD, RIGHT_ARROW_KEY_CODE, sizeof(RIGHT_ARROW_KEY_CODE)); + write(fMasterFD, RIGHT_ARROW_KEY_CODE, sizeof(RIGHT_ARROW_KEY_CODE) - 1); break; case B_UP_ARROW: - write(fMasterFD, UP_ARROW_KEY_CODE, sizeof(UP_ARROW_KEY_CODE)); + write(fMasterFD, UP_ARROW_KEY_CODE, sizeof(UP_ARROW_KEY_CODE) - 1); break; case B_DOWN_ARROW: - write(fMasterFD, DOWN_ARROW_KEY_CODE, sizeof(DOWN_ARROW_KEY_CODE)); + write(fMasterFD, DOWN_ARROW_KEY_CODE, sizeof(DOWN_ARROW_KEY_CODE) - 1); break; default: write(fMasterFD, bytes, numBytes); @@ -245,13 +271,13 @@ MiniView::SpawnThreads() return B_ERROR; TRACE(("console writer thread is: %d\n", fConsoleWriter)); - fShellProcess = spawn_thread(&MiniView::ExecuteShell, "shell process", B_URGENT_DISPLAY_PRIORITY, this); - if (fShellProcess < 0) + fShellExecutor = spawn_thread(&MiniView::ExecuteShell, "shell process", B_URGENT_DISPLAY_PRIORITY, this); + if (fShellExecutor < 0) return B_ERROR; TRACE(("shell process thread is: %d\n", fShellProcess)); resume_thread(fConsoleWriter); - resume_thread(fShellProcess); + resume_thread(fShellExecutor); return B_OK; } @@ -292,11 +318,11 @@ MiniView::ExecuteShell(void *arg) dup2(view->fSlaveFD, 1); dup2(view->fSlaveFD, 2); - thread_id shell = load_image(2, argv, (const char **)environ); - setpgid(shell, 0); + view->fShellProcess = load_image(2, argv, (const char **)environ); + setpgid(view->fShellProcess, 0); status_t return_code; - wait_for_thread(shell, &return_code); + wait_for_thread(view->fShellProcess, &return_code); dup2(saved_stdin, 0); dup2(saved_stdout, 1); diff --git a/src/tests/apps/miniterminal/MiniView.h b/src/tests/apps/miniterminal/MiniView.h index a74bf317be..7baa6d9a4b 100644 --- a/src/tests/apps/miniterminal/MiniView.h +++ b/src/tests/apps/miniterminal/MiniView.h @@ -14,6 +14,8 @@ virtual ~MiniView(); void Start(); status_t OpenTTY(); status_t SpawnThreads(); + +virtual void FrameResized(float width, float height); virtual void KeyDown(const char *bytes, int32 numBytes); private: @@ -24,6 +26,7 @@ static filter_result MessageFilter(BMessage *message, BHandler **target, BMessa Console *fConsole; int fMasterFD; int fSlaveFD; + thread_id fShellExecutor; thread_id fShellProcess; thread_id fConsoleWriter; }; diff --git a/src/tests/apps/miniterminal/ViewBuffer.cpp b/src/tests/apps/miniterminal/ViewBuffer.cpp index 94d1d0a8b1..1b370d3521 100644 --- a/src/tests/apps/miniterminal/ViewBuffer.cpp +++ b/src/tests/apps/miniterminal/ViewBuffer.cpp @@ -12,7 +12,7 @@ #include "ViewBuffer.h" #define CHAR_WIDTH 7 -#define CHAR_HEIGHT 12 +#define CHAR_HEIGHT 13 // Palette is (black and white are swapt like in normal BeOS Terminal) // 0 - black,