From: Zbigniew Jędrzejewski-Szmek Date: Sun, 8 Oct 2023 10:33:43 +0000 (+0200) Subject: efi/boot: make timeout changes relative to current value X-Git-Tag: v255-rc1~256^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1cd26e5e56e1b407d62374f98bab2dd0a531a486;p=thirdparty%2Fsystemd.git efi/boot: make timeout changes relative to current value When the user pressed + or -, we would set the efivar override, starting from the default of 0. Instead, set an override that starts at the current value. This means that when user has e.g. a configured override of 5 s, and they press +, they get an override of 6 s. I think this is leads to a much smoother experience for a user, who does not necessarilly need to know that we have three levels of overrides, they just want to easily configure the timeout with keys. If they press +, the timeout should increase, and not jump to some low value. Also, once an override has been set via the boot menu, i.e. the efivar is set, do not allow unsetting the efivar from the boot menu. This way we also avoid an unexpected "jump" to whatever the other sources of configuration specify. The user can configure any value with the keys that they want, so we don't need to allow unsetting. --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 6c0d41c6846..403858ba1ef 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -390,27 +390,29 @@ static size_t entry_lookup_key(Config *config, size_t start, char16_t key) { return IDX_INVALID; } -static char16_t *update_timeout_efivar(uint32_t *t, bool inc) { - assert(t); +static char16_t* update_timeout_efivar(Config *config, bool inc) { + assert(config); - switch (*t) { + switch (config->timeout_sec) { case TIMEOUT_MAX: - *t = inc ? TIMEOUT_MAX : (*t - 1); + config->timeout_sec = inc ? TIMEOUT_MAX : config->timeout_sec - 1; break; case TIMEOUT_UNSET: - *t = inc ? TIMEOUT_MENU_FORCE : TIMEOUT_UNSET; + config->timeout_sec = inc ? TIMEOUT_MENU_FORCE : TIMEOUT_UNSET; break; case TIMEOUT_MENU_FORCE: - *t = inc ? TIMEOUT_MENU_HIDDEN : TIMEOUT_UNSET; + config->timeout_sec = inc ? TIMEOUT_MENU_HIDDEN : TIMEOUT_MENU_FORCE; break; case TIMEOUT_MENU_HIDDEN: - *t = inc ? TIMEOUT_MIN : TIMEOUT_MENU_FORCE; + config->timeout_sec = inc ? TIMEOUT_MIN : TIMEOUT_MENU_FORCE; break; default: - *t += inc ? 1 : -1; + config->timeout_sec = config->timeout_sec + (inc ? 1 : -1); } - switch (*t) { + config->timeout_sec_efivar = config->timeout_sec; + + switch (config->timeout_sec) { case TIMEOUT_UNSET: return xstrdup16(u"Menu timeout defined by configuration file."); case TIMEOUT_MENU_FORCE: @@ -418,7 +420,7 @@ static char16_t *update_timeout_efivar(uint32_t *t, bool inc) { case TIMEOUT_MENU_HIDDEN: return xstrdup16(u"Menu disabled. Hold down key at bootup to show menu."); default: - return xasprintf("Menu timeout set to %u s.", *t); + return xasprintf("Menu timeout set to %u s.", config->timeout_sec_efivar); } } @@ -935,12 +937,12 @@ static bool menu_run( case KEYPRESS(0, 0, '-'): case KEYPRESS(0, 0, 'T'): - status = update_timeout_efivar(&config->timeout_sec_efivar, false); + status = update_timeout_efivar(config, false); break; case KEYPRESS(0, 0, '+'): case KEYPRESS(0, 0, 't'): - status = update_timeout_efivar(&config->timeout_sec_efivar, true); + status = update_timeout_efivar(config, true); break; case KEYPRESS(0, 0, 'e'):