From 1a34c007966c42cb0be431af5bf77b15cd2a25a9 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Thu, 27 Sep 2012 19:08:41 +0200 Subject: [PATCH] wlt: terminal: forward HUP event to the caller This forwards the PTY-HUP event to the caller so we can close the terminal window when the client application exits. Reported-by: Alexander Preisinger Signed-off-by: David Herrmann --- src/wlt_main.c | 17 +++++++++++++++++ src/wlt_terminal.c | 42 +++++++++++++++++++++++++++++++++--------- src/wlt_terminal.h | 11 +++++++++++ 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/wlt_main.c b/src/wlt_main.c index fdb05b0..afe9f05 100644 --- a/src/wlt_main.c +++ b/src/wlt_main.c @@ -68,6 +68,17 @@ static void window_close(struct wlt_window *wnd, void *data) ev_eloop_exit(app->eloop); } +static void terminal_close(struct wlt_terminal *term, unsigned int event, + void *data) +{ + struct wlt_app *app = data; + + if (event == WLT_TERMINAL_HUP) { + log_info("closing pty"); + ev_eloop_exit(app->eloop); + } +} + static int window_init(struct wlt_app *app) { int ret; @@ -94,6 +105,12 @@ static int window_init(struct wlt_app *app) return ret; } + ret = wlt_terminal_open(term, terminal_close, app); + if (ret) { + log_error("cannot open terminal"); + return ret; + } + return 0; } diff --git a/src/wlt_terminal.c b/src/wlt_terminal.c index 8fe95c3..f0dcf9e 100644 --- a/src/wlt_terminal.c +++ b/src/wlt_terminal.c @@ -40,6 +40,7 @@ #include "tsm_screen.h" #include "tsm_vte.h" #include "wlt_main.h" +#include "wlt_terminal.h" #include "wlt_toolkit.h" #define LOG_SUBSYSTEM "wlt_terminal" @@ -59,6 +60,9 @@ struct wlt_terminal { struct kmscon_font *font_normal; unsigned int cols; unsigned int rows; + + wlt_terminal_cb cb; + void *data; }; static int draw_cell(struct tsm_screen *scr, @@ -203,13 +207,7 @@ static void widget_resize(struct wlt_widget *widget, struct wlt_rect *alloc, ret = tsm_screen_resize(term->scr, term->cols, term->rows); if (ret) log_error("cannot resize TSM screen: %d", ret); - - if (!term->pty_open) { - term->pty_open = true; - kmscon_pty_open(term->pty, term->cols, term->rows); - } else { - kmscon_pty_resize(term->pty, term->cols, term->rows); - } + kmscon_pty_resize(term->pty, term->cols, term->rows); } static void widget_key(struct wlt_widget *widget, unsigned int mask, @@ -241,8 +239,9 @@ static void pty_input(struct kmscon_pty *pty, const char *u8, size_t len, struct wlt_terminal *term = data; if (!len) { - log_debug("hangup on PTY"); - /* TODO: signal that to caller */ + term->pty_open = false; + if (term->cb) + term->cb(term, WLT_TERMINAL_HUP, term->data); } else { tsm_vte_input(term->vte, u8, len); wlt_window_schedule_redraw(term->wnd); @@ -280,6 +279,8 @@ int wlt_terminal_new(struct wlt_terminal **out, struct wlt_window *wnd) memset(term, 0, sizeof(*term)); term->wnd = wnd; term->eloop = wlt_window_get_eloop(wnd); + term->cols = 80; + term->rows = 24; attr.ppi = wlt_conf.font_ppi; attr.points = wlt_conf.font_size; @@ -352,3 +353,26 @@ void wlt_terminal_destroy(struct wlt_terminal *term) wlt_widget_destroy(term->widget); } + +int wlt_terminal_open(struct wlt_terminal *term, wlt_terminal_cb cb, + void *data) +{ + int ret; + + if (!term) + return -EINVAL; + + if (term->pty_open) + return -EALREADY; + + term->cb = cb; + term->data = data; + + kmscon_pty_close(term->pty); + ret = kmscon_pty_open(term->pty, term->cols, term->rows); + if (ret) + return ret; + + term->pty_open = true; + return 0; +} diff --git a/src/wlt_terminal.h b/src/wlt_terminal.h index d60dab9..0016414 100644 --- a/src/wlt_terminal.h +++ b/src/wlt_terminal.h @@ -35,7 +35,18 @@ struct wlt_terminal; +enum wlt_terminal_event_type { + WLT_TERMINAL_HUP, +}; + +typedef void (*wlt_terminal_cb) (struct wlt_terminal *term, + unsigned int event, + void *data); + int wlt_terminal_new(struct wlt_terminal **out, struct wlt_window *wnd); void wlt_terminal_destroy(struct wlt_terminal *term); +int wlt_terminal_open(struct wlt_terminal *term, wlt_terminal_cb cb, + void *data); + #endif /* WLT_TERMINAL_H */ -- 2.7.4