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:
Vladimir 'phcoder' Serbinenko 2010-05-01 19:33:17 +02:00
commit c5ac9b32ac
4 changed files with 62 additions and 0 deletions

View File

@ -1,3 +1,12 @@
2010-05-01 Vladimir Serbinenko <phcoder@gmail.com>
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.
2010-05-01 Vladimir Serbinenko <phcoder@gmail.com>
* kern/i386/coreboot/init.c (grub_machine_init): Call

View File

@ -47,6 +47,8 @@ struct grub_menu_entry
/* The sourcecode of the menu entry, used by the editor. */
const char *sourcecode;
int hotkey;
/* The next element. */
struct grub_menu_entry *next;
};

View File

@ -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;

View File

@ -478,6 +478,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
goto refresh;
default:
{
grub_menu_entry_t entry;
int i;
for (i = 0, entry = menu->entry_list; i < menu->size;
i++, entry = entry->next)
if (entry->hotkey == c)
{
menu_fini ();
*auto_boot = 0;
return i;
}
}
break;
}
}