Blame SOURCES/0186-Accept-ESC-F8-and-holding-SHIFT-as-user-interrupt-ke.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Hans de Goede <hdegoede@redhat.com>
d9d99f
Date: Mon, 26 Mar 2018 16:15:53 +0200
d9d99f
Subject: [PATCH] Accept ESC, F8 and holding SHIFT as user interrupt keys
d9d99f
d9d99f
On some devices the ESC key is the hotkey to enter the BIOS/EFI setup
d9d99f
screen, making it really hard to time pressing it right. Besides that
d9d99f
ESC is also pretty hard to discover for a user who does not know it
d9d99f
will unhide the menu.
d9d99f
d9d99f
This commit makes F8, which used to be the hotkey to show the Windows
d9d99f
boot menu during boot for a long long time, also interrupt sleeps /
d9d99f
stop the menu countdown.
d9d99f
d9d99f
This solves the ESC gets into the BIOS setup and also somewhat solves
d9d99f
the discoverability issue, but leaves the timing issue unresolved.
d9d99f
d9d99f
This commit fixes the timing issue by also adding support for keeping
d9d99f
SHIFT pressed during boot to stop the menu countdown. This matches
d9d99f
what Ubuntu is doing, which should also help with discoverability.
d9d99f
d9d99f
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
d9d99f
---
d9d99f
 grub-core/commands/sleep.c |  2 +-
d9d99f
 grub-core/kern/term.c      | 16 ++++++++++++++++
d9d99f
 grub-core/normal/menu.c    |  2 +-
d9d99f
 include/grub/term.h        |  1 +
d9d99f
 4 files changed, 19 insertions(+), 2 deletions(-)
d9d99f
d9d99f
diff --git a/grub-core/commands/sleep.c b/grub-core/commands/sleep.c
d9d99f
index e77e7900fac..a1370b710c9 100644
d9d99f
--- a/grub-core/commands/sleep.c
d9d99f
+++ b/grub-core/commands/sleep.c
d9d99f
@@ -55,7 +55,7 @@ grub_interruptible_millisleep (grub_uint32_t ms)
d9d99f
   start = grub_get_time_ms ();
d9d99f
 
d9d99f
   while (grub_get_time_ms () - start < ms)
d9d99f
-    if (grub_getkey_noblock () == GRUB_TERM_ESC)
d9d99f
+    if (grub_key_is_interrupt (grub_getkey_noblock ()))
d9d99f
       return 1;
d9d99f
 
d9d99f
   return 0;
d9d99f
diff --git a/grub-core/kern/term.c b/grub-core/kern/term.c
d9d99f
index 93bd3378d18..6cae4c23e7a 100644
d9d99f
--- a/grub-core/kern/term.c
d9d99f
+++ b/grub-core/kern/term.c
d9d99f
@@ -138,6 +138,22 @@ grub_getkeystatus (void)
d9d99f
   return status;
d9d99f
 }
d9d99f
 
d9d99f
+int
d9d99f
+grub_key_is_interrupt (int key)
d9d99f
+{
d9d99f
+  /* ESC sometimes is the BIOS setup hotkey and may be hard to discover, also
d9d99f
+     check F8, which was the key to get the Windows bootmenu for a long time. */
d9d99f
+  if (key == GRUB_TERM_ESC || key == GRUB_TERM_KEY_F8)
d9d99f
+    return 1;
d9d99f
+
d9d99f
+  /* Pressing keys at the right time during boot is hard to time, also allow
d9d99f
+     interrupting sleeps / the menu countdown by keeping shift pressed. */
d9d99f
+  if (grub_getkeystatus() & (GRUB_TERM_STATUS_LSHIFT|GRUB_TERM_STATUS_RSHIFT))
d9d99f
+    return 1;
d9d99f
+
d9d99f
+  return 0;
d9d99f
+}
d9d99f
+
d9d99f
 void
d9d99f
 grub_refresh (void)
d9d99f
 {
d9d99f
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
d9d99f
index 5e2f5283d3d..6cb2a071490 100644
d9d99f
--- a/grub-core/normal/menu.c
d9d99f
+++ b/grub-core/normal/menu.c
d9d99f
@@ -655,7 +655,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
d9d99f
 	      if (entry >= 0)
d9d99f
 		break;
d9d99f
 	    }
d9d99f
-	  if (key == GRUB_TERM_ESC)
d9d99f
+	  if (grub_key_is_interrupt (key))
d9d99f
 	    {
d9d99f
 	      timeout = -1;
d9d99f
 	      break;
d9d99f
diff --git a/include/grub/term.h b/include/grub/term.h
d9d99f
index c215133383f..2b079c29b80 100644
d9d99f
--- a/include/grub/term.h
d9d99f
+++ b/include/grub/term.h
d9d99f
@@ -328,6 +328,7 @@ void grub_putcode (grub_uint32_t code, struct grub_term_output *term);
d9d99f
 int EXPORT_FUNC(grub_getkey) (void);
d9d99f
 int EXPORT_FUNC(grub_getkey_noblock) (void);
d9d99f
 int EXPORT_FUNC(grub_getkeystatus) (void);
d9d99f
+int EXPORT_FUNC(grub_key_is_interrupt) (int key);
d9d99f
 void grub_cls (void);
d9d99f
 void EXPORT_FUNC(grub_refresh) (void);
d9d99f
 void grub_puts_terminal (const char *str, struct grub_term_output *term);