Hotkey support
* include/grub/menu.h (grub_menu_entry): New field 'hotkey'. * normal/main.c (hotkey_aliases): New variable. (grub_normal_add_menu_entry): Parse "--hotkey". * normal/menu_text.c (run_menu): Handle hotkeys.
This commit is contained in:
commit
c5ac9b32ac
4 changed files with 62 additions and 0 deletions
|
@ -155,6 +155,17 @@ free_menu_entry_classes (struct grub_menu_entry_class *head)
|
|||
}
|
||||
}
|
||||
|
||||
static struct
|
||||
{
|
||||
char *name;
|
||||
int key;
|
||||
} hotkey_aliases[] =
|
||||
{
|
||||
{"backspace", '\b'},
|
||||
{"tab", '\t'},
|
||||
{"delete", GRUB_TERM_DC}
|
||||
};
|
||||
|
||||
/* Add a menu entry to the current menu context (as given by the environment
|
||||
variable data slot `menu'). As the configuration file is read, the script
|
||||
parser calls this when a menu entry is to be created. */
|
||||
|
@ -171,6 +182,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
|
|||
struct grub_menu_entry_class *classes_head; /* Dummy head node for list. */
|
||||
struct grub_menu_entry_class *classes_tail;
|
||||
char *users = NULL;
|
||||
int hotkey = 0;
|
||||
|
||||
/* Allocate dummy head node for class list. */
|
||||
classes_head = grub_zalloc (sizeof (struct grub_menu_entry_class));
|
||||
|
@ -237,6 +249,32 @@ grub_normal_add_menu_entry (int argc, const char **args,
|
|||
|
||||
continue;
|
||||
}
|
||||
else if (grub_strcmp(arg, "hotkey") == 0)
|
||||
{
|
||||
unsigned j;
|
||||
|
||||
i++;
|
||||
if (args[i][1] == 0)
|
||||
{
|
||||
hotkey = args[i][0];
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 0; j < ARRAY_SIZE (hotkey_aliases); j++)
|
||||
if (grub_strcmp (args[i], hotkey_aliases[j].name) == 0)
|
||||
{
|
||||
hotkey = hotkey_aliases[j].key;
|
||||
break;
|
||||
}
|
||||
|
||||
if (j < ARRAY_SIZE (hotkey_aliases))
|
||||
continue;
|
||||
|
||||
failed = 1;
|
||||
grub_error (GRUB_ERR_MENU,
|
||||
"Invalid hotkey: '%s'.", args[i]);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Handle invalid argument. */
|
||||
|
@ -293,6 +331,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
|
|||
}
|
||||
|
||||
(*last)->title = menutitle;
|
||||
(*last)->hotkey = hotkey;
|
||||
(*last)->classes = classes_head;
|
||||
if (users)
|
||||
(*last)->restricted = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue