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
This commit is contained in:
Michael Lotz
2005-04-09 17:21:14 +00:00
parent 68ca240b53
commit 52e1c3c044
3 changed files with 46 additions and 17 deletions
+42 -16
View File
@@ -74,6 +74,9 @@ MiniView::MiniView(BRect frame)
MiniView::~MiniView() MiniView::~MiniView()
{ {
kill_thread(fConsoleWriter);
kill_thread(fShellExecutor);
kill_thread(fShellProcess);
} }
void void
@@ -90,9 +93,9 @@ MiniView::Start()
setsid(); setsid();
// move our stdin and stdout to the console // move our stdin and stdout to the console
/*dup2(fSlaveFD, 0); dup2(fSlaveFD, 0);
dup2(fSlaveFD, 1); dup2(fSlaveFD, 1);
dup2(fSlaveFD, 2);*/ dup2(fSlaveFD, 2);
if (SpawnThreads() != B_OK) if (SpawnThreads() != B_OK)
TRACE(("error in SpawnThreads\n")); TRACE(("error in SpawnThreads\n"));
@@ -183,11 +186,18 @@ MiniView::OpenTTY()
// set terminal interface // set terminal interface
tcsetattr(fSlaveFD, TCSANOW, &tio); tcsetattr(fSlaveFD, TCSANOW, &tio);
// set window size (currently disabled) // set window size
/*ws.ws_row = rows; winsize ws;
int32 rows, cols;
GetSize(&cols, &rows);
ws.ws_row = rows;
ws.ws_col = cols; ws.ws_col = cols;
if (LockLooper()) {
ioctl(con->tty_slave_fd, TIOCSWINSZ, &ws);*/ ws.ws_xpixel = Bounds().IntegerWidth();
ws.ws_ypixel = Bounds().IntegerHeight();
UnlockLooper();
}
ioctl(fSlaveFD, TIOCSWINSZ, &ws);
} }
break; break;
} }
@@ -206,6 +216,22 @@ MiniView::OpenTTY()
return B_OK; 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 void
MiniView::KeyDown(const char *bytes, int32 numBytes) MiniView::KeyDown(const char *bytes, int32 numBytes)
{ {
@@ -218,16 +244,16 @@ MiniView::KeyDown(const char *bytes, int32 numBytes)
} else { } else {
switch (bytes[0]) { switch (bytes[0]) {
case B_LEFT_ARROW: 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; break;
case B_RIGHT_ARROW: 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; break;
case B_UP_ARROW: 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; break;
case B_DOWN_ARROW: 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; break;
default: default:
write(fMasterFD, bytes, numBytes); write(fMasterFD, bytes, numBytes);
@@ -245,13 +271,13 @@ MiniView::SpawnThreads()
return B_ERROR; return B_ERROR;
TRACE(("console writer thread is: %d\n", fConsoleWriter)); TRACE(("console writer thread is: %d\n", fConsoleWriter));
fShellProcess = spawn_thread(&MiniView::ExecuteShell, "shell process", B_URGENT_DISPLAY_PRIORITY, this); fShellExecutor = spawn_thread(&MiniView::ExecuteShell, "shell process", B_URGENT_DISPLAY_PRIORITY, this);
if (fShellProcess < 0) if (fShellExecutor < 0)
return B_ERROR; return B_ERROR;
TRACE(("shell process thread is: %d\n", fShellProcess)); TRACE(("shell process thread is: %d\n", fShellProcess));
resume_thread(fConsoleWriter); resume_thread(fConsoleWriter);
resume_thread(fShellProcess); resume_thread(fShellExecutor);
return B_OK; return B_OK;
} }
@@ -292,11 +318,11 @@ MiniView::ExecuteShell(void *arg)
dup2(view->fSlaveFD, 1); dup2(view->fSlaveFD, 1);
dup2(view->fSlaveFD, 2); dup2(view->fSlaveFD, 2);
thread_id shell = load_image(2, argv, (const char **)environ); view->fShellProcess = load_image(2, argv, (const char **)environ);
setpgid(shell, 0); setpgid(view->fShellProcess, 0);
status_t return_code; status_t return_code;
wait_for_thread(shell, &return_code); wait_for_thread(view->fShellProcess, &return_code);
dup2(saved_stdin, 0); dup2(saved_stdin, 0);
dup2(saved_stdout, 1); dup2(saved_stdout, 1);
+3
View File
@@ -14,6 +14,8 @@ virtual ~MiniView();
void Start(); void Start();
status_t OpenTTY(); status_t OpenTTY();
status_t SpawnThreads(); status_t SpawnThreads();
virtual void FrameResized(float width, float height);
virtual void KeyDown(const char *bytes, int32 numBytes); virtual void KeyDown(const char *bytes, int32 numBytes);
private: private:
@@ -24,6 +26,7 @@ static filter_result MessageFilter(BMessage *message, BHandler **target, BMessa
Console *fConsole; Console *fConsole;
int fMasterFD; int fMasterFD;
int fSlaveFD; int fSlaveFD;
thread_id fShellExecutor;
thread_id fShellProcess; thread_id fShellProcess;
thread_id fConsoleWriter; thread_id fConsoleWriter;
}; };
+1 -1
View File
@@ -12,7 +12,7 @@
#include "ViewBuffer.h" #include "ViewBuffer.h"
#define CHAR_WIDTH 7 #define CHAR_WIDTH 7
#define CHAR_HEIGHT 12 #define CHAR_HEIGHT 13
// Palette is (black and white are swapt like in normal BeOS Terminal) // Palette is (black and white are swapt like in normal BeOS Terminal)
// 0 - black, // 0 - black,