From a22b0c3ac64198be91e4c1ea3a94570830ba4ae7 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 7 Feb 2018 17:49:57 +0100 Subject: [PATCH] noux: respond to terminal-size changes --- repos/ports/include/noux_session/sysio.h | 5 +++-- repos/ports/src/lib/libc_noux/plugin.cc | 1 + repos/ports/src/noux/child.h | 5 +++-- repos/ports/src/noux/interrupt_handler.h | 4 +++- repos/ports/src/noux/io_channel.h | 4 ++-- repos/ports/src/noux/terminal_io_channel.h | 11 ++++++++++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/repos/ports/include/noux_session/sysio.h b/repos/ports/include/noux_session/sysio.h index 5defa8f4e..b6e32819b 100644 --- a/repos/ports/include/noux_session/sysio.h +++ b/repos/ports/include/noux_session/sysio.h @@ -39,8 +39,9 @@ struct Noux::Sysio { /* signal numbers must match with libc signal numbers */ enum Signal { - SIG_INT = 2, - SIG_CHLD = 20, + SIG_INT = 2, + SIG_CHLD = 20, + SIG_WINCH = 28 }; enum { SIGNAL_QUEUE_SIZE = 32 }; diff --git a/repos/ports/src/lib/libc_noux/plugin.cc b/repos/ports/src/lib/libc_noux/plugin.cc index 355357c67..020617ea2 100644 --- a/repos/ports/src/lib/libc_noux/plugin.cc +++ b/repos/ports/src/lib/libc_noux/plugin.cc @@ -210,6 +210,7 @@ static bool noux_syscall(Noux::Session::Syscall opcode) if (signal_action[signal].sa_handler == SIG_DFL) { switch (signal) { case SIGCHLD: + case SIGWINCH: /* ignore */ break; default: diff --git a/repos/ports/src/noux/child.h b/repos/ports/src/noux/child.h index 719a17cdc..a2dbf376a 100644 --- a/repos/ports/src/noux/child.h +++ b/repos/ports/src/noux/child.h @@ -568,13 +568,14 @@ class Noux::Child : public Rpc_object, return child; } + /********************************* ** Interrupt_handler interface ** *********************************/ - void handle_interrupt() + void handle_interrupt(Sysio::Signal signal) { - submit_signal(Sysio::SIG_INT); + submit_signal(signal); } }; diff --git a/repos/ports/src/noux/interrupt_handler.h b/repos/ports/src/noux/interrupt_handler.h index 213e0ab6c..4d43840f7 100644 --- a/repos/ports/src/noux/interrupt_handler.h +++ b/repos/ports/src/noux/interrupt_handler.h @@ -14,11 +14,13 @@ #ifndef _NOUX__INTERRUPT_HANDLER__H_ #define _NOUX__INTERRUPT_HANDLER__H_ +#include + namespace Noux { struct Interrupt_handler { - virtual void handle_interrupt() = 0; + virtual void handle_interrupt(Sysio::Signal) = 0; }; }; diff --git a/repos/ports/src/noux/io_channel.h b/repos/ports/src/noux/io_channel.h index eae726390..6154b744a 100644 --- a/repos/ports/src/noux/io_channel.h +++ b/repos/ports/src/noux/io_channel.h @@ -177,14 +177,14 @@ class Noux::Io_channel : public Reference_counter /** * Tell all registered handlers about an interrupt event */ - void invoke_all_interrupt_handlers() + void invoke_all_interrupt_handlers(Sysio::Signal signal) { Lock::Guard signal_lock_guard(signal_lock()); Lock::Guard guard(_interrupt_handlers_lock); for (Io_channel_listener *l = _interrupt_handlers.first(); l; l = l->next()) - l->object()->handle_interrupt(); + l->object()->handle_interrupt(signal); } /** diff --git a/repos/ports/src/noux/terminal_io_channel.h b/repos/ports/src/noux/terminal_io_channel.h index adce896a8..9686a1668 100644 --- a/repos/ports/src/noux/terminal_io_channel.h +++ b/repos/ports/src/noux/terminal_io_channel.h @@ -33,6 +33,8 @@ struct Noux::Terminal_io_channel : Io_channel Signal_handler _read_avail_handler; + Signal_handler _resize_handler; + bool eof = false; enum Type { STDIN, STDOUT, STDERR } type; @@ -44,6 +46,7 @@ struct Noux::Terminal_io_channel : Io_channel : _terminal(terminal), _read_avail_handler(ep, *this, &Terminal_io_channel::_handle_read_avail), + _resize_handler (ep, *this, &Terminal_io_channel::_handle_resize), type(type) { /* @@ -59,6 +62,7 @@ struct Noux::Terminal_io_channel : Io_channel */ if (type == STDIN) { terminal.read_avail_sigh(_read_avail_handler); + terminal.size_changed_sigh(_resize_handler); } } @@ -211,7 +215,7 @@ struct Noux::Terminal_io_channel : Io_channel enum { INTERRUPT = 3 }; if (c == INTERRUPT) { - Io_channel::invoke_all_interrupt_handlers(); + Io_channel::invoke_all_interrupt_handlers(Sysio::SIG_INT); } else { read_buffer.add(c); } @@ -219,6 +223,11 @@ struct Noux::Terminal_io_channel : Io_channel Io_channel::invoke_all_notifiers(); } + + void _handle_resize() + { + Io_channel::invoke_all_interrupt_handlers(Sysio::SIG_WINCH); + } }; #endif /* _NOUX__TERMINAL_IO_CHANNEL_H_ */