15a2072
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
15a2072
From: Hans de Goede <hdegoede@redhat.com>
15a2072
Date: Wed, 6 Jun 2018 16:16:47 +0200
15a2072
Subject: [PATCH] EFI: console: Implement getkeystatus() support
15a2072
15a2072
Implement getkeystatus() support.
15a2072
15a2072
Note that if a non-modifier key gets pressed and repeated calls to
15a2072
getkeystatus() are made then it will return the modifier status at the
15a2072
time of the non-modifier key, until that key-press gets consumed by a
15a2072
getkey() call.
15a2072
15a2072
This is a side-effect of how the EFI simple-text-input protocol works
15a2072
and cannot be avoided.
15a2072
15a2072
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
15a2072
---
15a2072
 grub-core/term/efi/console.c | 34 ++++++++++++++++++++++++++++++++++
15a2072
 1 file changed, 34 insertions(+)
15a2072
15a2072
diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c
15a2072
index 3d36c5c701b..92dd4996bb7 100644
15a2072
--- a/grub-core/term/efi/console.c
15a2072
+++ b/grub-core/term/efi/console.c
15a2072
@@ -223,6 +223,39 @@ grub_console_getkey_ex(struct grub_term_input *term)
15a2072
   return key;
15a2072
 }
15a2072
 
15a2072
+static int
15a2072
+grub_console_getkeystatus(struct grub_term_input *term)
15a2072
+{
15a2072
+  grub_efi_key_data_t key_data;
15a2072
+  grub_efi_uint32_t kss;
15a2072
+  int key, mods = 0;
15a2072
+
15a2072
+  if (grub_efi_is_finished)
15a2072
+    return 0;
15a2072
+
15a2072
+  if (grub_console_read_key_stroke (term->data, &key_data, &key, 0))
15a2072
+    return 0;
15a2072
+
15a2072
+  kss = key_data.key_state.key_shift_state;
15a2072
+  if (kss & GRUB_EFI_SHIFT_STATE_VALID)
15a2072
+    {
15a2072
+      if (kss & GRUB_EFI_LEFT_SHIFT_PRESSED)
15a2072
+        mods |= GRUB_TERM_STATUS_LSHIFT;
15a2072
+      if (kss & GRUB_EFI_RIGHT_SHIFT_PRESSED)
15a2072
+        mods |= GRUB_TERM_STATUS_RSHIFT;
15a2072
+      if (kss & GRUB_EFI_LEFT_ALT_PRESSED)
15a2072
+        mods |= GRUB_TERM_STATUS_LALT;
15a2072
+      if (kss & GRUB_EFI_RIGHT_ALT_PRESSED)
15a2072
+        mods |= GRUB_TERM_STATUS_RALT;
15a2072
+      if (kss & GRUB_EFI_LEFT_CONTROL_PRESSED)
15a2072
+        mods |= GRUB_TERM_STATUS_LCTRL;
15a2072
+      if (kss & GRUB_EFI_RIGHT_CONTROL_PRESSED)
15a2072
+        mods |= GRUB_TERM_STATUS_RCTRL;
15a2072
+    }
15a2072
+
15a2072
+  return mods;
15a2072
+}
15a2072
+
15a2072
 static grub_err_t
15a2072
 grub_efi_console_input_init (struct grub_term_input *term)
15a2072
 {
15a2072
@@ -403,6 +436,7 @@ static struct grub_term_input grub_console_term_input =
15a2072
   {
15a2072
     .name = "console",
15a2072
     .getkey = grub_console_getkey,
15a2072
+    .getkeystatus = grub_console_getkeystatus,
15a2072
     .init = grub_efi_console_input_init,
15a2072
   };
15a2072