From 9384b0ab3b9bec1744c19c64ac5431db99110b04 Mon Sep 17 00:00:00 2001 From: Samuel Mendoza-Jonas Date: Wed, 2 Sep 2015 15:43:39 +1000 Subject: ui/ncurses: Improve update handling in nested screens Several screens in petitboot-nc require an update if a config or sysinfo update is received. However if those screens exist but are not the current screen they will incorrectly try to draw to the screen. Where the currently active screen is a textscreen (eg. a help screen) the update is delayed until after the screen is exited. In the particular case of nc-config where the current screen can be an nc-subset screen, the nc-subset screen is exited immediately so the update can be performed, since the nc-subset screen depends on the information in the previous screen. Signed-off-by: Samuel Mendoza-Jonas --- ui/ncurses/nc-config.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'ui/ncurses/nc-config.c') diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c index b257076..7c02250 100644 --- a/ui/ncurses/nc-config.c +++ b/ui/ncurses/nc-config.c @@ -53,6 +53,7 @@ struct config_screen { bool show_help; bool show_subset; bool need_redraw; + bool need_update; void (*on_exit)(struct cui *); @@ -170,21 +171,6 @@ static void config_screen_resize(struct nc_scr *scr) (void)screen; } -static int config_screen_post(struct nc_scr *scr) -{ - struct config_screen *screen = config_screen_from_scr(scr); - screen->show_subset = false; - widgetset_post(screen->widgetset); - nc_scr_frame_draw(scr); - if (screen->need_redraw) { - redrawwin(scr->main_ncw); - screen->need_redraw = false; - } - wrefresh(screen->scr.main_ncw); - pad_refresh(screen); - return 0; -} - static int config_screen_unpost(struct nc_scr *scr) { struct config_screen *screen = config_screen_from_scr(scr); @@ -1014,10 +1000,38 @@ void config_screen_update(struct config_screen *screen, const struct config *config, const struct system_info *sysinfo) { + if (screen->cui->current != config_screen_scr(screen)) { + screen->need_update = true; + return; + } + config_screen_draw(screen, config, sysinfo); pad_refresh(screen); } +static int config_screen_post(struct nc_scr *scr) +{ + struct config_screen *screen = config_screen_from_scr(scr); + screen->show_subset = false; + + if (screen->need_update) { + config_screen_draw(screen, screen->cui->config, + screen->cui->sysinfo); + screen->need_update = false; + } else { + widgetset_post(screen->widgetset); + } + + nc_scr_frame_draw(scr); + if (screen->need_redraw) { + redrawwin(scr->main_ncw); + screen->need_redraw = false; + } + wrefresh(screen->scr.main_ncw); + pad_refresh(screen); + return 0; +} + static int config_screen_destroy(void *arg) { struct config_screen *screen = arg; @@ -1043,6 +1057,7 @@ struct config_screen *config_screen_init(struct cui *cui, screen->cui = cui; screen->on_exit = on_exit; screen->need_redraw = false; + screen->need_update = false; screen->label_x = 2; screen->field_x = 17; -- cgit v1.2.1