Skip to content

Commit f64be25

Browse files
MingcongBaichenx97
authored andcommitted
menu: add GRUB_RIGHT_TO_SELECT to toggle select-by-right-arrow-key
Normally, GRUB allows using a combination of the Return/Enter (`\n' and `\r'), Ctrl-F, and the right arrow key to select a menu item. However, on some keyboards (especially those half-height arrow keys found on laptop computers), it is very easy to accidentally select a menu item when the user meant to press the up/down arrow key. Implement an GRUB_RIGHT_TO_SELECT option (boolean) to enable/disable right arrow key for selecting menu items. Co-developed-by: Mag Mell <[email protected]> Signed-off-by: Mingcong Bai <[email protected]>
1 parent 2dd46c9 commit f64be25

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

docs/grub.texi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,10 @@ This option may be set to a list of GRUB module names separated by spaces.
15931593
Each module will be loaded as early as possible, at the start of
15941594
@file{grub.cfg}.
15951595

1596+
@item GRUB_RIGHT_TO_SELECT
1597+
This option may be set to specify whether the right arrow key may be used
1598+
to make a selection. This option defaults to @samp{true}.
1599+
15961600
@end table
15971601

15981602
The following options are still accepted for compatibility with existing

grub-core/normal/menu.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <grub/script_sh.h>
3333
#include <grub/gfxterm.h>
3434
#include <grub/dl.h>
35+
#include <grub/env.h>
3536

3637
/* Time to delay after displaying an error message about a default/fallback
3738
entry failing to boot. */
@@ -579,11 +580,16 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot, int *notify_boot)
579580
int default_entry, current_entry;
580581
int timeout;
581582
enum timeout_style timeout_style;
583+
bool right_to_select;
582584

583585
*notify_boot = 1;
584586

585587
default_entry = get_entry_number (menu, "default");
586588

589+
/* Read if the right arrow key is enabled for selection. Default to `true'
590+
if unset. */
591+
right_to_select = grub_env_get_bool ("right_to_select", true);
592+
587593
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
588594
the first entry. */
589595
if (default_entry < 0 || default_entry >= menu->size)
@@ -762,9 +768,17 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot, int *notify_boot)
762768
case '\r':
763769
case GRUB_TERM_KEY_RIGHT:
764770
case GRUB_TERM_CTRL | 'f':
765-
menu_fini ();
766-
*auto_boot = 0;
767-
return current_entry;
771+
/* Right arrow key to select only when boolean value
772+
`right_to_select' is set to `true' or not specified
773+
(defaults to `true'). */
774+
if ((c != GRUB_TERM_KEY_RIGHT) ||
775+
right_to_select)
776+
{
777+
menu_fini ();
778+
*auto_boot = 0;
779+
return current_entry;
780+
}
781+
break;
768782

769783
case GRUB_TERM_ESC:
770784
if (nested)

util/grub-mkconfig.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ export GRUB_DEFAULT \
254254
GRUB_ENABLE_CRYPTODISK \
255255
GRUB_BADRAM \
256256
GRUB_OS_PROBER_SKIP_LIST \
257-
GRUB_DISABLE_SUBMENU
257+
GRUB_DISABLE_SUBMENU \
258+
GRUB_RIGHT_TO_SELECT
258259

259260
if test "x${grub_cfg}" != "x"; then
260261
rm -f "${grub_cfg}.new"

util/grub.d/00_header.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
3737
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
3838
if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
3939
if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi
40+
if [ "x${GRUB_RIGHT_TO_SELECT}" = "x" ] ; then GRUB_RIGHT_TO_SELECT=true ; fi
4041

4142
if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi
4243
if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi
@@ -373,3 +374,8 @@ fi
373374
if [ "x${GRUB_BADRAM}" != "x" ] ; then
374375
echo "badram ${GRUB_BADRAM}"
375376
fi
377+
378+
# Whether to allow selecting with the right arrow key.
379+
cat << EOF
380+
set right_to_select=${GRUB_RIGHT_TO_SELECT}
381+
EOF

0 commit comments

Comments
 (0)