]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: Improve update handling in nested screens
authorSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Wed, 2 Sep 2015 05:43:39 +0000 (15:43 +1000)
committerSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Mon, 7 Sep 2015 06:55:52 +0000 (16:55 +1000)
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 <sam.mj@au1.ibm.com>
ui/ncurses/nc-boot-editor.c
ui/ncurses/nc-config.c
ui/ncurses/nc-cui.c
ui/ncurses/nc-subset.c
ui/ncurses/nc-sysinfo.c
ui/ncurses/nc-textscreen.c
ui/ncurses/nc-textscreen.h

index e2357f9b4623e556e15830c6ce5206c52c4aad88..4012ec5a7658dfdc8f429e00130307ed7692ec44 100644 (file)
@@ -44,6 +44,7 @@ struct boot_editor {
                                        struct pmenu_item *item,
                                        struct pb_boot_data *bd);
        bool                    need_redraw;
+       bool                    need_update;
 
        int                     label_x;
        int                     field_x;
@@ -109,7 +110,14 @@ static struct boot_editor *boot_editor_from_arg(void *arg)
 static int boot_editor_post(struct nc_scr *scr)
 {
        struct boot_editor *boot_editor = boot_editor_from_scr(scr);
-       widgetset_post(boot_editor->widgetset);
+
+       if (boot_editor->need_update) {
+               boot_editor_update(boot_editor, boot_editor->cui->sysinfo);
+               boot_editor->need_update = false;
+       } else {
+               widgetset_post(boot_editor->widgetset);
+       }
+
        nc_scr_frame_draw(scr);
        if (boot_editor->need_redraw) {
                redrawwin(scr->main_ncw);
@@ -506,6 +514,11 @@ void boot_editor_update(struct boot_editor *boot_editor,
 {
        int height;
 
+       if (boot_editor->cui->current != boot_editor_scr(boot_editor)) {
+               boot_editor->need_update = true;
+               return;
+       }
+
        widgetset_unpost(boot_editor->widgetset);
 
        height = pad_height(sysinfo ? sysinfo->n_blockdevs : 0);
@@ -546,6 +559,7 @@ struct boot_editor *boot_editor_init(struct cui *cui,
        boot_editor->on_exit = on_exit;
        boot_editor->state = STATE_EDIT;
        boot_editor->need_redraw = false;
+       boot_editor->need_update = false;
 
        int ncols1 = strncols(_("Device tree:"));
        int ncols2 = strncols(_("Boot arguments:"));
index b257076d03b2f50be229b2a51a718abe8a8822e7..7c02250ce6e47765531f86364ec3639af65e47d1 100644 (file)
@@ -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;
 
index 56e7653af112c67e8f0afc67c6fc45b4d6cb794e..c975c0f126e0095bc0f65db3b29d2dadd65835e0 100644 (file)
@@ -698,6 +698,9 @@ static void cui_update_sysinfo(struct system_info *sysinfo, void *arg)
        if (cui->sysinfo_screen)
                sysinfo_screen_update(cui->sysinfo_screen, sysinfo);
 
+       if (cui->subset_screen)
+               subset_screen_update(cui->subset_screen);
+
        /* ... and do the same with the config screen... */
        if (cui->config_screen)
                config_screen_update(cui->config_screen, cui->config, sysinfo);
@@ -744,6 +747,9 @@ static void cui_update_config(struct config *config, void *arg)
        if (config->lang)
                cui_update_language(cui, config->lang);
 
+       if (cui->subset_screen)
+               subset_screen_update(cui->subset_screen);
+
        if (cui->config_screen)
                config_screen_update(cui->config_screen, config, cui->sysinfo);
 
index f38e3949b5561ea3105c8df869af9fe78b03a901..0faed3b1d6f1b510fdaa9872f81ab69099c8d4af 100644 (file)
@@ -62,6 +62,12 @@ struct nc_scr *subset_screen_return_scr(struct subset_screen *screen)
        return screen->return_scr;
 }
 
+void subset_screen_update(struct subset_screen *screen)
+{
+       pb_debug("Exiting subset due to update\n");
+       return screen->on_exit(screen->cui);
+}
+
 static struct subset_screen *subset_screen_from_scr(struct nc_scr *scr)
 {
        struct subset_screen *subset_screen;
index bde8b331ce2b05fbe9ced376f5736fd31a78226f..ac8ece785f6533a3708233de608c6652941e1cde 100644 (file)
@@ -104,7 +104,11 @@ void sysinfo_screen_update(struct sysinfo_screen *screen,
                const struct system_info *sysinfo)
 {
        sysinfo_screen_populate(screen, sysinfo);
-       text_screen_draw(&screen->text_scr);
+
+       if (screen->text_scr.cui->help_screen)
+               screen->text_scr.need_update = true;
+       else
+               text_screen_draw(&screen->text_scr);
 }
 
 struct sysinfo_screen *sysinfo_screen_init(struct cui *cui,
index 826244cb0a0e9618f086e5a47d133ca751a8de2f..55428e791986d102665fc0aaa42fa36addea3fda 100644 (file)
@@ -183,6 +183,13 @@ void text_screen_set_help(struct text_screen *screen, const char *title,
 
 static int text_screen_post(struct nc_scr *scr)
 {
+       struct text_screen *screen = text_screen_from_scr(scr);
+
+       if (screen->need_update) {
+               text_screen_draw(screen);
+               screen->need_update = false;
+       }
+
        nc_scr_frame_draw(scr);
        redrawwin(scr->main_ncw);
        wrefresh(scr->main_ncw);
@@ -202,6 +209,7 @@ void text_screen_init(struct text_screen *screen, struct cui *cui,
 
        screen->cui = cui;
        screen->on_exit = on_exit;
+       screen->need_update = false;
 
        screen->scr.frame.ltitle = talloc_strdup(screen, title);
        screen->scr.frame.rtitle = NULL;
index 25107cb476caadf32fcf97d311960064ae0cace4..df47186287f7cbb6967d88387e3036f3117b1c5a 100644 (file)
@@ -28,6 +28,7 @@ struct text_screen {
        int                     n_lines;
        int                     n_alloc_lines;
        int                     scroll_y;
+       bool                    need_update;
        const char              *help_title;
        const struct help_text  *help_text;
        void                    (*on_exit)(struct cui *);