Handle resize
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "networktransport.hpp"
|
#include "networktransport.hpp"
|
||||||
#include "completeterminal.hpp"
|
#include "completeterminal.hpp"
|
||||||
@@ -153,6 +154,16 @@ void serve( int host_fd )
|
|||||||
/* apply userstream to terminal */
|
/* apply userstream to terminal */
|
||||||
for ( size_t i = 0; i < us.size(); i++ ) {
|
for ( size_t i = 0; i < us.size(); i++ ) {
|
||||||
terminal_to_host += terminal.act( us.get_action( 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<const Parser::Resize *>( 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 */
|
/* update client with new state of terminal */
|
||||||
|
|||||||
@@ -112,8 +112,6 @@ void client( const char *ip, int port, const char *key )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX transmit initial resize and initialize */
|
|
||||||
|
|
||||||
/* local state */
|
/* local state */
|
||||||
Terminal::Complete terminal( window_size.ws_col, window_size.ws_row );
|
Terminal::Complete terminal( window_size.ws_col, window_size.ws_row );
|
||||||
Terminal::Framebuffer state( 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,
|
Network::Transport< Network::UserStream, Terminal::Complete > network( blank, terminal,
|
||||||
key, ip, port );
|
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 */
|
/* prepare to poll for events */
|
||||||
struct pollfd pollfds[ 3 ];
|
struct pollfd pollfds[ 3 ];
|
||||||
|
|
||||||
@@ -175,7 +176,19 @@ void client( const char *ip, int port, const char *key )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( pollfds[ 2 ].revents & POLLIN ) {
|
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)
|
if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents)
|
||||||
|
|||||||
Reference in New Issue
Block a user