2N/A/* gfxmenu.c - Graphical menu interface controller. */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2008 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/types.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/mm.h>
2N/A#include <grub/err.h>
2N/A#include <grub/dl.h>
2N/A#include <grub/command.h>
2N/A#include <grub/video.h>
2N/A#include <grub/gfxterm.h>
2N/A#include <grub/bitmap.h>
2N/A#include <grub/bitmap_scale.h>
2N/A#include <grub/term.h>
2N/A#include <grub/env.h>
2N/A#include <grub/normal.h>
2N/A#include <grub/gfxwidgets.h>
2N/A#include <grub/menu.h>
2N/A#include <grub/menu_viewer.h>
2N/A#include <grub/gfxmenu_model.h>
2N/A#include <grub/gfxmenu_view.h>
2N/A#include <grub/time.h>
2N/A
2N/AGRUB_MOD_LICENSE ("GPLv3+");
2N/A
2N/Astatic grub_gfxmenu_view_t cached_view;
2N/A
2N/Astatic void
2N/Agrub_gfxmenu_viewer_fini (void *data __attribute__ ((unused)))
2N/A{
2N/A}
2N/A
2N/A/* FIXME: Previously 't' changed to text menu is it necessary? */
2N/Astatic grub_err_t
2N/Agrub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
2N/A{
2N/A grub_gfxmenu_view_t view = NULL;
2N/A const char *theme_path;
2N/A struct grub_menu_viewer *instance;
2N/A grub_err_t err;
2N/A struct grub_video_mode_info mode_info;
2N/A
2N/A theme_path = grub_env_get ("theme");
2N/A if (! theme_path)
2N/A return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified");
2N/A
2N/A instance = grub_zalloc (sizeof (*instance));
2N/A if (!instance)
2N/A return grub_errno;
2N/A
2N/A err = grub_video_get_info (&mode_info);
2N/A if (err)
2N/A return err;
2N/A
2N/A if (!cached_view || grub_strcmp (cached_view->theme_path, theme_path) != 0
2N/A || cached_view->screen.width != mode_info.width
2N/A || cached_view->screen.height != mode_info.height)
2N/A {
2N/A grub_free (cached_view);
2N/A /* Create the view. */
2N/A cached_view = grub_gfxmenu_view_new (theme_path, mode_info.width,
2N/A mode_info.height);
2N/A }
2N/A
2N/A if (! cached_view)
2N/A {
2N/A grub_free (instance);
2N/A return grub_errno;
2N/A }
2N/A
2N/A view = cached_view;
2N/A
2N/A view->double_repaint = (mode_info.mode_type
2N/A & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)
2N/A && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP);
2N/A view->selected = entry;
2N/A view->menu = menu;
2N/A view->nested = nested;
2N/A view->first_timeout = -1;
2N/A
2N/A grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
2N/A if (view->double_repaint)
2N/A {
2N/A grub_video_swap_buffers ();
2N/A grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
2N/A }
2N/A
2N/A grub_gfxmenu_view_draw (view);
2N/A
2N/A instance->data = view;
2N/A instance->set_chosen_entry = grub_gfxmenu_set_chosen_entry;
2N/A instance->fini = grub_gfxmenu_viewer_fini;
2N/A instance->print_timeout = grub_gfxmenu_print_timeout;
2N/A instance->clear_timeout = grub_gfxmenu_clear_timeout;
2N/A
2N/A grub_menu_register_viewer (instance);
2N/A
2N/A return GRUB_ERR_NONE;
2N/A}
2N/A
2N/AGRUB_MOD_INIT (gfxmenu)
2N/A{
2N/A struct grub_term_output *term;
2N/A
2N/A FOR_ACTIVE_TERM_OUTPUTS(term)
2N/A if (grub_gfxmenu_try_hook && grub_strcmp (term->name, "gfxterm") == 0)
2N/A {
2N/A grub_gfxterm_fullscreen ();
2N/A break;
2N/A }
2N/A
2N/A grub_gfxmenu_try_hook = grub_gfxmenu_try;
2N/A}
2N/A
2N/AGRUB_MOD_FINI (gfxmenu)
2N/A{
2N/A grub_gfxmenu_view_destroy (cached_view);
2N/A grub_gfxmenu_try_hook = NULL;
2N/A}