I’m testing edits I made to grub2, mode specifically grub-core/term/usb_keyboard.c.
I have the source code obtained from https://github.com/rhboot/grub2/blob/fedora-44/grub-core and also the source obtained from https://kojipkgs.fedoraproject.org//packages/grub2/2.12/60.fc44/src/grub2-2.12-60.fc44.src.rpm.
I tried to recompile from the former but got this error when running
./bootstrap
./configure
make
:
configure: error: in '/home/shizuma/.local/src/grub2':
configure: error: no acceptable C compiler found in $PATH
See 'config.log' for more details
This PC was never meant to compile C code.
What I’d prefer is a way to recompile grub without having to deal with a gazillion of devel files and dependencies that there is no easy way to get rid of after compilation.
There’s a beautiful method described there but I’m afraid it’s specific to rpmfusion.
Edits are below:
--- usb_keyboard.c.orig 2026-07-27 08:35:13.144132452 -0400
+++ usb_keyboard.c 2026-07-27 08:35:32.725865065 -0400
@@ -28,7 +28,8 @@
GRUB_MOD_LICENSE ("GPLv3+");
-
+/* Définition du délai anti-rebond en millisecondes */
+#define GRUB_USB_DEBOUNCE_DELAY_MS 80
enum
{
@@ -80,6 +81,10 @@
grub_uint8_t last_report[8];
int index;
int max_index;
+
+ /* NOUVEAU: Variables pour l'anti-rebond (Key Debouncing) */
+ int last_accepted_keycode;
+ grub_uint64_t last_accepted_time;
};
static int grub_usb_keyboard_getkey (struct grub_term_input *term);
@@ -220,27 +225,7 @@
return 0;
}
- /* Test showed that getting report may make the keyboard go nuts.
- Moreover since we're reattaching keyboard it usually sends
- an initial message on interrupt pipe and so we retrieve
- the same keystatus.
- */
-#if 0
- {
- grub_uint8_t report[8];
- grub_usb_err_t err;
- grub_memset (report, 0, sizeof (report));
- err = grub_usb_control_msg (usbdev, GRUB_USB_REQTYPE_CLASS_INTERFACE_IN,
- USB_HID_GET_REPORT, 0x0100, interfno,
- sizeof (report), (char *) report);
- if (err)
- data->status = 0;
- else
- data->status = report[0];
- }
-#else
data->status = 0;
-#endif
data->transfer = grub_usb_bulk_read_background (usbdev,
data->endp,
@@ -256,6 +241,10 @@
data->mods = 0;
data->dead = 0;
+ /* NOUVEAU: Initialisation des variables anti-rebond */
+ data->last_accepted_keycode = KEY_NO_KEY;
+ data->last_accepted_time = 0;
+
grub_term_register_input_active ("usb_keyboard", &grub_usb_keyboards[curnum]);
return 1;
@@ -283,6 +270,7 @@
{
int index = termdata->index;
int i, keycode;
+ grub_uint64_t current_time;
/* Sanity check */
if (index < 2)
@@ -300,8 +288,6 @@
/* Don't parse (rest of) this report */
termdata->index = 0;
if (keycode != KEY_NO_KEY)
- /* Don't replace last report with current faulty report
- * in future ! */
grub_memcpy (termdata->current_report,
termdata->last_report,
sizeof (termdata->report));
@@ -317,6 +303,19 @@
* ignore it. */
continue;
+ /*
+ * NOUVEAU : FILTRE ANTI-REBOND (KEY DEBOUNCING)
+ * Si la touche est identique à la dernière touche enregistrée et
+ * qu'elle survient trop vite (moins de GRUB_USB_DEBOUNCE_DELAY_MS),
+ * on l'ignore (rebond du dongle/clavier sans-fil).
+ */
+ current_time = grub_get_time_ms ();
+ if (keycode == termdata->last_accepted_keycode &&
+ (current_time - termdata->last_accepted_time) < GRUB_USB_DEBOUNCE_DELAY_MS)
+ {
+ continue; /* Rebond détecté, passer à la touche suivante */
+ }
+
if (keycode == KEY_CAPS_LOCK)
{
termdata->mods ^= GRUB_TERM_STATUS_CAPS;
@@ -331,6 +330,10 @@
continue;
}
+ /* NOUVEAU: Sauvegarder la touche acceptée et le timestamp */
+ termdata->last_accepted_keycode = keycode;
+ termdata->last_accepted_time = current_time;
+
termdata->last_key = grub_term_map_key (keycode,
interpret_status (termdata->current_report[0])
| termdata->mods);