From ba4d5cca5a9187539acca81e15db4ac0fdb448b4 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sun, 14 Aug 2011 02:43:04 -0400 Subject: [PATCH] Handle resize --- stm-server.cpp | 11 +++++++++++ stm.cpp | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/stm-server.cpp b/stm-server.cpp index 307da92..f7812da 100644 --- a/stm-server.cpp +++ b/stm-server.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "networktransport.hpp" #include "completeterminal.hpp" @@ -153,6 +154,16 @@ void serve( int host_fd ) /* apply userstream to terminal */ for ( size_t i = 0; i < us.size(); i++ ) { terminal_to_host += terminal.act( us.get_action( i ) ); + if ( typeid( *us.get_action( i ) ) == typeid( Parser::Resize ) ) { + /* tell child process of resize */ + const Parser::Resize *res = static_cast( us.get_action( i ) ); + window_size.ws_col = res->width; + window_size.ws_col = res->height; + if ( ioctl( host_fd, TIOCSWINSZ, &window_size ) < 0 ) { + perror( "ioctl TIOCSWINSZ" ); + return; + } + } } /* update client with new state of terminal */ diff --git a/stm.cpp b/stm.cpp index 0c4457d..5f23e9a 100644 --- a/stm.cpp +++ b/stm.cpp @@ -112,8 +112,6 @@ void client( const char *ip, int port, const char *key ) return; } - /* XXX transmit initial resize and initialize */ - /* local state */ Terminal::Complete terminal( window_size.ws_col, window_size.ws_row ); Terminal::Framebuffer state( window_size.ws_col, window_size.ws_row ); @@ -123,6 +121,9 @@ void client( const char *ip, int port, const char *key ) Network::Transport< Network::UserStream, Terminal::Complete > network( blank, terminal, key, ip, port ); + /* set terminal size */ + network.get_current_state().push_back( Parser::Resize( window_size.ws_col, window_size.ws_row ) ); + /* prepare to poll for events */ struct pollfd pollfds[ 3 ]; @@ -175,7 +176,19 @@ void client( const char *ip, int port, const char *key ) } if ( pollfds[ 2 ].revents & POLLIN ) { - /* handle resize */ + /* resize */ + struct signalfd_siginfo info; + assert( read( winch_fd, &info, sizeof( info ) ) == sizeof( info ) ); + assert( info.ssi_signo == SIGWINCH ); + + /* get new size */ + if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) { + perror( "ioctl TIOCGWINSZ" ); + return; + } + + /* tell emulator */ + network.get_current_state().push_back( Parser::Resize( window_size.ws_col, window_size.ws_row ) ); } if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents)