0

[NaCl SDK] ppapi_simple: Allow initial terminal size to to be set on startup.

Allow the initial terminal size to be set via the PS_TTY_ROWS
and PS_TTY_COLS environment variables.

This allows ppapi_simple application to know the TTY
size before the main function runs.

R=binji@chromium.org

Review URL: https://codereview.chromium.org/66343004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234130 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
sbc@chromium.org
2013-11-09 17:34:17 +00:00
parent 53c1dd73d9
commit 56c953af6b
3 changed files with 34 additions and 5 deletions
native_client_sdk/src/libraries

@ -257,6 +257,8 @@ Error MountNodeTty::VIoctl(int request, va_list args) {
struct winsize* size = va_arg(args, struct winsize*);
{
AUTO_LOCK(node_lock_);
if (rows_ == size->ws_row && cols_ == size->ws_col)
return 0;
rows_ = size->ws_row;
cols_ = size->ws_col;
}

@ -238,6 +238,26 @@ bool PSInstance::ProcessProperties() {
if (tty_resize)
RegisterMessageHandler(tty_resize, MessageHandlerResizeStatic, this);
char* tty_rows = getenv("PS_TTY_ROWS");
char* tty_cols = getenv("PS_TTY_COLS");
if (tty_rows && tty_cols) {
char* end = tty_rows;
int rows = strtol(tty_rows, &end, 10);
if (*end != '\0' || rows < 0) {
Error("Invalid value for PS_TTY_ROWS: %s", tty_rows);
} else {
end = tty_cols;
int cols = strtol(tty_cols, &end, 10);
if (*end != '\0' || cols < 0)
Error("Invalid value for PS_TTY_COLS: %s", tty_cols);
else
HandleResize(cols, rows);
}
}
else if (tty_rows || tty_cols) {
Error("PS_TTY_ROWS and PS_TTY_COLS must be set together");
}
tioc_nacl_output handler;
handler.handler = TtyOutputHandlerStatic;
handler.user_data = this;
@ -372,16 +392,22 @@ void PSInstance::MessageHandlerInput(const pp::Var& message) {
}
}
void PSInstance::HandleResize(int width, int height){
struct winsize size;
memset(&size, 0, sizeof(size));
size.ws_col = width;
size.ws_row = height;
ioctl(tty_fd_, TIOCSWINSZ, reinterpret_cast<char*>(&size));
}
void PSInstance::MessageHandlerResize(const pp::Var& message) {
assert(message.is_array());
pp::VarArray array(message);
assert(array.GetLength() == 2);
struct winsize size;
memset(&size, 0, sizeof(size));
size.ws_col = array.Get(0).AsInt();
size.ws_row = array.Get(1).AsInt();
ioctl(tty_fd_, TIOCSWINSZ, reinterpret_cast<char*>(&size));
int width = array.Get(0).AsInt();
int height = array.Get(1).AsInt();
HandleResize(width, height);
}
ssize_t PSInstance::TtyOutputHandlerStatic(const char* buf,

@ -154,6 +154,7 @@ class PSInstance : public pp::Instance, pp::MouseLock, pp::Graphics3DClient {
ssize_t TtyOutputHandler(const char* buf, size_t count);
void MessageHandlerInput(const pp::Var& message);
void MessageHandlerResize(const pp::Var& message);
void HandleResize(int width, int height);
static ssize_t TtyOutputHandlerStatic(const char* buf, size_t count,
void* user_data);