]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot: Improve selection of initial entries to show
authorJan Janssen <medhefgo@web.de>
Sat, 14 Aug 2021 11:04:29 +0000 (13:04 +0200)
committerJan Janssen <medhefgo@web.de>
Mon, 16 Aug 2021 13:52:09 +0000 (15:52 +0200)
src/boot/efi/boot.c

index 82da9843253f60467af25d7d669e07564ae026eb..56cd4a489de93b2f0c0fcb597d91be554a8168e7 100644 (file)
@@ -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] = ' ';