Skip to contentSkip to conversation

efi/console: Implement getkeystatus() support

PATCH Superseded Javier Martinez Canillas 2 participants 2 messages Mar 13, 2020 – Apr 3, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 5/10 efi/console: Implement getkeystatus() support

From: Hans de Goede <[email protected]>

Implement getkeystatus() support.

Note that if a non-modifier key gets pressed and repeated calls to getkeystatus() are made then it will return the modifier status at the time of the non-modifier key, until that key-press gets consumed by a getkey() call.

This is a side-effect of how the EFI simple-text-input protocol works and cannot be avoided.

---

 grub-core/term/efi/console.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
grub-core/term/efi/console.c +34 -0
index 11f85e84790..0e909c30ae1 100644
@@ -293,6 +293,39 @@ grub_console_getkey_ex(struct grub_term_input *term)
   return key;
 }
 
+static int
+grub_console_getkeystatus(struct grub_term_input *term)
+{
+  grub_efi_key_data_t key_data;
+  grub_efi_uint32_t kss;
+  int key, mods = 0;
+
+  if (grub_efi_is_finished)
+    return 0;
+
+  if (grub_console_read_key_stroke (term->data, &key_data, &key, 0))
+    return 0;
+
+  kss = key_data.key_state.key_shift_state;
+  if (kss & GRUB_EFI_SHIFT_STATE_VALID)
+    {
+      if (kss & GRUB_EFI_LEFT_SHIFT_PRESSED)
+        mods |= GRUB_TERM_STATUS_LSHIFT;
+      if (kss & GRUB_EFI_RIGHT_SHIFT_PRESSED)
+        mods |= GRUB_TERM_STATUS_RSHIFT;
+      if (kss & GRUB_EFI_LEFT_ALT_PRESSED)
+        mods |= GRUB_TERM_STATUS_LALT;
+      if (kss & GRUB_EFI_RIGHT_ALT_PRESSED)
+        mods |= GRUB_TERM_STATUS_RALT;
+      if (kss & GRUB_EFI_LEFT_CONTROL_PRESSED)
+        mods |= GRUB_TERM_STATUS_LCTRL;
+      if (kss & GRUB_EFI_RIGHT_CONTROL_PRESSED)
+        mods |= GRUB_TERM_STATUS_RCTRL;
+    }
+
+  return mods;
+}
+
 static grub_err_t
 grub_efi_console_input_init (struct grub_term_input *term)
 {
@@ -402,6 +435,7 @@ static struct grub_term_input grub_console_term_input =
   {
     .name = "console",
     .getkey = grub_console_getkey,
+    .getkeystatus = grub_console_getkeystatus,
     .init = grub_efi_console_input_init,
   };
 
Signature · 1 line
2.24.1
#1 lore raw
Quoted 3 lines · Javier Martinez Canillas

From: Hans de Goede <[email protected]>

Implement getkeystatus() support.

This commit misses explanation why this patch is needed.

Quoted 21 lines

Note that if a non-modifier key gets pressed and repeated calls to getkeystatus() are made then it will return the modifier status at the time of the non-modifier key, until that key-press gets consumed by a getkey() call.

This is a side-effect of how the EFI simple-text-input protocol works and cannot be avoided.

---

 grub-core/term/efi/console.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
grub-core/term/efi/console.c +0 -0
index 11f85e84790..0e909c30ae1 100644

grub-core/term/efi/console.c grub_console_getkey_ex(struct grub_term_input *term) · line 297

Quoted 5 lines
grub-core/term/efi/console.c +2 -0
@@ -293,6 +293,39 @@ grub_console_getkey_ex(struct grub_term_input *term)
   return key;
 }
 
+static int
+grub_console_getkeystatus(struct grub_term_input *term)

Missing space after function name...

Otherise you can add Reviewed-by: Daniel Kiper <[email protected]>

Daniel