kern/term: Accept ESC, F4 and holding SHIFT as user interrupt keys
PATCH 7/10 kern/term: Accept ESC, F4 and holding SHIFT as user interrupt keys
From: Hans de Goede <[email protected]>
On some devices the ESC key is the hotkey to enter the BIOS/EFI setup screen, making it really hard to time pressing it right. Besides that ESC is also pretty hard to discover for a user who does not know it will unhide the menu.
This commit makes F4, which used to be the hotkey to show the Windows boot menu during boot for a long long time, also interrupt sleeps / stop the menu countdown.
This solves the ESC gets into the BIOS setup and also somewhat solves the discoverability issue, but leaves the timing issue unresolved.
This commit fixes the timing issue by also adding support for keeping SHIFT pressed during boot to stop the menu countdown. This matches what Ubuntu is doing, which should also help with discoverability.
---
grub-core/commands/sleep.c | 2 +- grub-core/kern/term.c | 16 ++++++++++++++++ grub-core/normal/menu.c | 2 +- include/grub/term.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)
grub-core/commands/sleep.c +1 -1
@@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms) start =grub_get_time_ms ();while (grub_get_time_ms () - start < ms) -if (grub_getkey_noblock () ==GRUB_TERM_ESC ) +if (grub_key_is_interrupt (grub_getkey_noblock ()))return 1 ;return 0 ;
grub-core/kern/term.c +16 -0
@@ -138,6 +138,22 @@ grub_getkeystatus (void)return status; } +int +grub_key_is_interrupt (int key) +{ +/* ESC sometimes is the BIOS setup hotkey and may be hard to discover, also +check F4, which was the key to get the Windows bootmenu for a long time. */ +if (key ==GRUB_TERM_ESC || key ==GRUB_TERM_KEY_F4 ) +return 1 ; + +/* Pressing keys at the right time during boot is hard to time, also allow +interrupting sleeps / the menu countdown by keeping shift pressed. */ +if (grub_getkeystatus () & (GRUB_TERM_STATUS_LSHIFT |GRUB_TERM_STATUS_RSHIFT )) +return 1 ; + +return 0 ; +} +void grub_refresh (void ) {
grub-core/normal/menu.c +1 -1
@@ -623,7 +623,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)if (entry >=0 )break ; } -if (key ==GRUB_TERM_ESC ) +if (grub_key_is_interrupt (key)) { timeout =-1 ;break ;
include/grub/term.h +1 -0
@@ -330,6 +330,7 @@ void grub_putcode (grub_uint32_t code, struct grub_term_output *term);int EXPORT_FUNC (grub_getkey ) (void );int EXPORT_FUNC (grub_getkey_noblock ) (void );int EXPORT_FUNC (grub_getkeystatus ) (void ); +int EXPORT_FUNC (grub_key_is_interrupt ) (int key);void grub_cls (void );void EXPORT_FUNC (grub_refresh ) (void );void grub_puts_terminal (const char *str,struct grub_term_output *term);
Signature · 1 line
2.24.1
Quoted 11 lines · Javier Martinez Canillas
From: Hans de Goede <[email protected]>
On some devices the ESC key is the hotkey to enter the BIOS/EFI setup screen, making it really hard to time pressing it right. Besides that ESC is also pretty hard to discover for a user who does not know it will unhide the menu.
This commit makes F4, which used to be the hotkey to show the Windows boot menu during boot for a long long time, also interrupt sleeps / stop the menu countdown.
Hans pointed me out that this part of the commit message is wrong after I modified his patch to use F4 as a hotkey instead of F8. I did this because that was decided in the previous version of this patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00136.html
But F4 is not a hotkey used by Windows so this whole paragraph should be removed. And instead explain that F4 was chosen because is not used as a hotkey to enter the BIOS setup by any vendor.
[snip]
grub-core/kern/term.c grub_getkeystatus (void) · line 145
Quoted 5 lines
grub-core/kern/term.c +5
-0+int +grub_key_is_interrupt (int key) +{ +/* ESC sometimes is the BIOS setup hotkey and may be hard to discover, also +check F4, which was the key to get the Windows bootmenu for a long time. */
And this comment should also be fixed since is wrong now.
I'll fix both issues on v2 but will wait first for review before doing that.
Best regards,
Signature · 3 lines
Javier Martinez Canillas Software Engineer - Desktop Hardware Enablement Red Hat
Quoted 14 lines · Javier Martinez Canillas
From: Hans de Goede <[email protected]>
On some devices the ESC key is the hotkey to enter the BIOS/EFI setup screen, making it really hard to time pressing it right. Besides that ESC is also pretty hard to discover for a user who does not know it will unhide the menu.
This commit makes F4, which used to be the hotkey to show the Windows boot menu during boot for a long long time, also interrupt sleeps / stop the menu countdown.
This solves the ESC gets into the BIOS setup and also somewhat solves the discoverability issue, but leaves the timing issue unresolved.
Quoted 7 lines
This commit fixes the timing issue by also adding support for keeping SHIFT pressed during boot to stop the menu countdown. This matches what Ubuntu is doing, which should also help with discoverability.
Signed-off-by Hans de Goede <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>
Please drop this empty line...
Quoted 26 lines
---
grub-core/commands/sleep.c | 2 +- grub-core/kern/term.c | 16 ++++++++++++++++ grub-core/normal/menu.c | 2 +- include/grub/term.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-)grub-core/commands/sleep.c +1
-1@@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms) start =grub_get_time_ms ();while (grub_get_time_ms () - start < ms) -if (grub_getkey_noblock () ==GRUB_TERM_ESC ) +if (grub_key_is_interrupt (grub_getkey_noblock ()))return 1 ;return 0 ;grub-core/kern/term.c +0
-0
grub-core/kern/term.c grub_getkeystatus (void) · line 145
Quoted 8 lines
grub-core/kern/term.c +5
-0@@ -138,6 +138,22 @@ grub_getkeystatus (void)return status; } +int +grub_key_is_interrupt (int key) +{ +/* ESC sometimes is the BIOS setup hotkey and may be hard to discover, also +check F4, which was the key to get the Windows bootmenu for a long time. */
Incorrect comment formating...
grub-core/kern/term.c grub_getkeystatus (void) · line 150
Quoted 5 lines
grub-core/kern/term.c +5
-0+if (key ==GRUB_TERM_ESC || key ==GRUB_TERM_KEY_F4 ) +return 1 ; + +/* Pressing keys at the right time during boot is hard to time, also allow +interrupting sleeps / the menu countdown by keeping shift pressed. */
Ditto...
Otherwise LGTM == my RB.
Daniel