* include/grub/menu_viewer.h (grub_menu_viewer_init): New prototype.

(grub_menu_viewer_should_return): Likewise.
	* normal/main.c (GRUB_MOD_INIT (normal)): Call grub_menu_viewer_init.
	* normal/menu_text.c (run_menu): Enable menu switching.
	* normal/menu_viewer.c (should_return): New variable.
	(menu_viewer_changed): Likewise.
	(grub_menu_viewer_show_menu): Handle menu viewer changes.
	(grub_menu_viewer_should_return): New function.
	(menuviewer_write_hook): Likewise.
	(grub_menu_viewer_init): Likewise.
This commit is contained in:
Colin D Bennett 2009-11-20 14:51:01 +01:00 committed by Vladimir 'phcoder' Serbinenko
parent ac3b7128d6
commit cbf97a87d9
5 changed files with 58 additions and 5 deletions

View file

@ -6,4 +6,14 @@
New prototype. New prototype.
* normal/menu.c (grub_menu_get_default_entry_index): New function. * normal/menu.c (grub_menu_get_default_entry_index): New function.
* normal/menu_text.c (run_menu): Use grub_menu_get_default_entry_index. * normal/menu_text.c (run_menu): Use grub_menu_get_default_entry_index.
* include/grub/menu_viewer.h (grub_menu_viewer_init): New prototype.
(grub_menu_viewer_should_return): Likewise.
* normal/main.c (GRUB_MOD_INIT (normal)): Call grub_menu_viewer_init.
* normal/menu_text.c (run_menu): Enable menu switching.
* normal/menu_viewer.c (should_return): New variable.
(menu_viewer_changed): Likewise.
(grub_menu_viewer_show_menu): Handle menu viewer changes.
(grub_menu_viewer_should_return): New function.
(menuviewer_write_hook): Likewise.
(grub_menu_viewer_init): Likewise.

View file

@ -36,8 +36,13 @@ struct grub_menu_viewer
}; };
typedef struct grub_menu_viewer *grub_menu_viewer_t; typedef struct grub_menu_viewer *grub_menu_viewer_t;
void grub_menu_viewer_init (void);
void grub_menu_viewer_register (grub_menu_viewer_t viewer); void grub_menu_viewer_register (grub_menu_viewer_t viewer);
grub_err_t grub_menu_viewer_show_menu (grub_menu_t menu, int nested); grub_err_t grub_menu_viewer_show_menu (grub_menu_t menu, int nested);
/* Return nonzero iff the menu viewer should clean up and return ASAP. */
int grub_menu_viewer_should_return (void);
#endif /* GRUB_MENU_VIEWER_HEADER */ #endif /* GRUB_MENU_VIEWER_HEADER */

View file

@ -584,6 +584,8 @@ GRUB_MOD_INIT(normal)
/* Preserve hooks after context changes. */ /* Preserve hooks after context changes. */
grub_env_export ("color_normal"); grub_env_export ("color_normal");
grub_env_export ("color_highlight"); grub_env_export ("color_highlight");
grub_menu_viewer_init ();
} }
GRUB_MOD_FINI(normal) GRUB_MOD_FINI(normal)

View file

@ -300,7 +300,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
if (timeout > 0) if (timeout > 0)
print_timeout (timeout, offset, 0); print_timeout (timeout, offset, 0);
while (1) while (! grub_menu_viewer_should_return ())
{ {
int c; int c;
timeout = grub_menu_get_timeout (); timeout = grub_menu_get_timeout ();
@ -473,6 +473,10 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
goto refresh; goto refresh;
case 't':
grub_env_set ("menuviewer", "gfxmenu");
goto refresh;
default: default:
break; break;
} }
@ -481,7 +485,8 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
} }
} }
/* Never reach here. */ /* Exit menu without activating an item. This occurs if the user presses
* 't', switching to the graphical menu viewer. */
return -1; return -1;
} }

View file

@ -26,6 +26,9 @@
/* The list of menu viewers. */ /* The list of menu viewers. */
static grub_menu_viewer_t menu_viewer_list; static grub_menu_viewer_t menu_viewer_list;
static int should_return;
static int menu_viewer_changed;
void void
grub_menu_viewer_register (grub_menu_viewer_t viewer) grub_menu_viewer_register (grub_menu_viewer_t viewer)
{ {
@ -55,16 +58,23 @@ static grub_menu_viewer_t get_current_menu_viewer (void)
grub_err_t grub_err_t
grub_menu_viewer_show_menu (grub_menu_t menu, int nested) grub_menu_viewer_show_menu (grub_menu_t menu, int nested)
{ {
grub_menu_viewer_t cur = get_current_menu_viewer ();
grub_err_t err1, err2; grub_err_t err1, err2;
if (!cur)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "No menu viewer available.");
while (1) while (1)
{ {
grub_menu_viewer_t cur = get_current_menu_viewer ();
if (!cur)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "No menu viewer available.");
menu_viewer_changed = 0;
should_return = 0;
err1 = cur->show_menu (menu, nested); err1 = cur->show_menu (menu, nested);
grub_print_error (); grub_print_error ();
if (menu_viewer_changed)
continue;
err2 = grub_auth_check_authentication (NULL); err2 = grub_auth_check_authentication (NULL);
if (err2) if (err2)
{ {
@ -79,3 +89,24 @@ grub_menu_viewer_show_menu (grub_menu_t menu, int nested)
return err1; return err1;
} }
int
grub_menu_viewer_should_return (void)
{
return should_return;
}
static char *
menuviewer_write_hook (struct grub_env_var *var __attribute__ ((unused)),
const char *val)
{
menu_viewer_changed = 1;
should_return = 1;
return grub_strdup (val);
}
void
grub_menu_viewer_init (void)
{
grub_register_variable_hook ("menuviewer", 0, menuviewer_write_hook);
}