From: Jan Janssen Date: Sat, 14 Aug 2021 11:04:29 +0000 (+0200) Subject: sd-boot: Improve selection of initial entries to show X-Git-Tag: v250-rc1~818^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=730b7194068febc87478d825411dd8633399e275;p=thirdparty%2Fsystemd.git sd-boot: Improve selection of initial entries to show --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 82da9843253..56cd4a489de 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -512,19 +512,19 @@ static BOOLEAN menu_run( EFI_STATUS err; UINTN visible_max; - UINTN idx_highlight; - UINTN idx_highlight_prev; + UINTN idx_highlight = config->idx_default; + UINTN idx_highlight_prev = 0; UINTN idx_first; UINTN idx_last; - BOOLEAN refresh; - BOOLEAN highlight; + BOOLEAN refresh = TRUE; + BOOLEAN highlight = FALSE; UINTN line_width; CHAR16 **lines; UINTN x_start; UINTN y_start; UINTN x_max; UINTN y_max; - CHAR16 *status; + CHAR16 *status = NULL; CHAR16 *clearline; UINTN timeout_remain = config->timeout_sec; INT16 idx; @@ -554,20 +554,19 @@ static BOOLEAN menu_run( y_max = 25; } - idx_highlight = config->idx_default; - idx_highlight_prev = 0; - visible_max = y_max - 2; - if ((UINTN)config->idx_default >= visible_max) - idx_first = config->idx_default-1; - else + /* Drawing entries starts at idx_first until idx_last. We want to make + * sure that idx_highlight is centered, but not if we are close to the + * beginning/end of the entry list. Otherwise we would have a half-empty + * screen. */ + if (config->entry_count <= visible_max || idx_highlight <= visible_max / 2) idx_first = 0; - - idx_last = idx_first + visible_max-1; - - refresh = TRUE; - highlight = FALSE; + else if (idx_highlight >= config->entry_count - (visible_max / 2)) + idx_first = config->entry_count - visible_max; + else + idx_first = idx_highlight - (visible_max / 2); + idx_last = idx_first + visible_max - 1; /* length of the longest entry */ line_width = 5; @@ -605,7 +604,6 @@ static BOOLEAN menu_run( lines[i][x_max] = '\0'; } - status = NULL; clearline = AllocatePool((x_max+1) * sizeof(CHAR16)); for (UINTN i = 0; i < x_max; i++) clearline[i] = ' ';