]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/grub-core/gfxmenu/gfxmenu.c
keep up with 1.0.67 (#1464)
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / grub-core / gfxmenu / gfxmenu.c
1 /* gfxmenu.c - Graphical menu interface controller. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2008 Free Software Foundation, Inc.
5 *
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <grub/types.h>
21 #include <grub/misc.h>
22 #include <grub/mm.h>
23 #include <grub/err.h>
24 #include <grub/dl.h>
25 #include <grub/command.h>
26 #include <grub/video.h>
27 #include <grub/gfxterm.h>
28 #include <grub/bitmap.h>
29 #include <grub/bitmap_scale.h>
30 #include <grub/term.h>
31 #include <grub/env.h>
32 #include <grub/normal.h>
33 #include <grub/gfxwidgets.h>
34 #include <grub/menu.h>
35 #include <grub/menu_viewer.h>
36 #include <grub/gfxmenu_model.h>
37 #include <grub/gfxmenu_view.h>
38 #include <grub/time.h>
39 #include <grub/env.h>
40 #include <grub/i18n.h>
41
42 GRUB_MOD_LICENSE ("GPLv3+");
43
44 extern int g_ventoy_menu_refresh;
45
46 static grub_gfxmenu_view_t cached_view;
47
48 static void
49 grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused)))
50 {
51 }
52
53 /* FIXME: Previously 't' changed to text menu is it necessary? */
54 static grub_err_t
55 grub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
56 {
57 int force_refresh = 0;
58 grub_gfxmenu_view_t view = NULL;
59 const char *theme_path;
60 char *full_theme_path = 0;
61 struct grub_menu_viewer *instance;
62 grub_err_t err;
63 struct grub_video_mode_info mode_info;
64
65 theme_path = grub_env_get ("theme");
66 if (! theme_path)
67 return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
68 "theme");
69
70 err = grub_video_get_info (&mode_info);
71 if (err)
72 return err;
73
74 instance = grub_zalloc (sizeof (*instance));
75 if (!instance)
76 return grub_errno;
77
78 if (theme_path[0] != '/' && theme_path[0] != '(')
79 {
80 const char *prefix;
81 prefix = grub_env_get ("prefix");
82 full_theme_path = grub_xasprintf ("%s/themes/%s",
83 prefix,
84 theme_path);
85 }
86
87 if (g_ventoy_menu_refresh)
88 {
89 g_ventoy_menu_refresh = 0;
90 force_refresh = 1;
91 }
92
93 if (force_refresh ||
94 !cached_view || grub_strcmp (cached_view->theme_path,
95 full_theme_path ? : theme_path) != 0
96 || cached_view->screen.width != mode_info.width
97 || cached_view->screen.height != mode_info.height)
98 {
99 grub_gfxmenu_view_destroy (cached_view);
100 /* Create the view. */
101 cached_view = grub_gfxmenu_view_new (full_theme_path ? : theme_path,
102 mode_info.width,
103 mode_info.height);
104 }
105 grub_free (full_theme_path);
106
107 if (! cached_view)
108 {
109 grub_free (instance);
110 return grub_errno;
111 }
112
113 view = cached_view;
114
115 view->double_repaint = (mode_info.mode_type
116 & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)
117 && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP);
118 view->selected = entry;
119 view->menu = menu;
120 view->nested = nested;
121 view->first_timeout = -1;
122
123 grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
124 if (view->double_repaint)
125 {
126 grub_video_swap_buffers ();
127 grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
128 }
129
130 grub_gfxmenu_view_draw (view);
131
132 instance->data = view;
133 instance->set_chosen_entry = grub_gfxmenu_set_chosen_entry;
134 instance->fini = grub_gfxmenu_viewer_fini;
135 instance->print_timeout = grub_gfxmenu_print_timeout;
136 instance->clear_timeout = grub_gfxmenu_clear_timeout;
137
138 grub_menu_register_viewer (instance);
139
140 return GRUB_ERR_NONE;
141 }
142
143 GRUB_MOD_INIT (gfxmenu)
144 {
145 struct grub_term_output *term;
146
147 FOR_ACTIVE_TERM_OUTPUTS(term)
148 if (grub_gfxmenu_try_hook && term->fullscreen)
149 {
150 term->fullscreen ();
151 break;
152 }
153
154 grub_gfxmenu_try_hook = grub_gfxmenu_try;
155 }
156
157 GRUB_MOD_FINI (gfxmenu)
158 {
159 grub_gfxmenu_view_destroy (cached_view);
160 grub_gfxmenu_try_hook = NULL;
161 }