nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0184-EFI-console-Implement-getkeystatus-support.patch

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