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
|
@ -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>
|
2010-05-01 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* kern/i386/coreboot/init.c (grub_machine_init): Call
|
* kern/i386/coreboot/init.c (grub_machine_init): Call
|
||||||
|
|
|
@ -47,6 +47,8 @@ struct grub_menu_entry
|
||||||
/* The sourcecode of the menu entry, used by the editor. */
|
/* The sourcecode of the menu entry, used by the editor. */
|
||||||
const char *sourcecode;
|
const char *sourcecode;
|
||||||
|
|
||||||
|
int hotkey;
|
||||||
|
|
||||||
/* The next element. */
|
/* The next element. */
|
||||||
struct grub_menu_entry *next;
|
struct grub_menu_entry *next;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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
|
/* 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
|
variable data slot `menu'). As the configuration file is read, the script
|
||||||
parser calls this when a menu entry is to be created. */
|
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_head; /* Dummy head node for list. */
|
||||||
struct grub_menu_entry_class *classes_tail;
|
struct grub_menu_entry_class *classes_tail;
|
||||||
char *users = NULL;
|
char *users = NULL;
|
||||||
|
int hotkey = 0;
|
||||||
|
|
||||||
/* Allocate dummy head node for class list. */
|
/* Allocate dummy head node for class list. */
|
||||||
classes_head = grub_zalloc (sizeof (struct grub_menu_entry_class));
|
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;
|
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
|
else
|
||||||
{
|
{
|
||||||
/* Handle invalid argument. */
|
/* Handle invalid argument. */
|
||||||
|
@ -293,6 +331,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
|
||||||
}
|
}
|
||||||
|
|
||||||
(*last)->title = menutitle;
|
(*last)->title = menutitle;
|
||||||
|
(*last)->hotkey = hotkey;
|
||||||
(*last)->classes = classes_head;
|
(*last)->classes = classes_head;
|
||||||
if (users)
|
if (users)
|
||||||
(*last)->restricted = 1;
|
(*last)->restricted = 1;
|
||||||
|
|
|
@ -478,6 +478,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
|
||||||
goto refresh;
|
goto refresh;
|
||||||
|
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue