~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/gfxmenu/gfxmenu.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-02-08 11:39:26 UTC
  • mfrom: (17.6.26 experimental)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 104.
  • Revision ID: james.westby@ubuntu.com-20110208113926-clfs90haboyk9zip
Tags: 1.99~rc1-2
* Merge 1.98+20100804-13 and 1.98+20100804-14, updating translations:
  - Kazakh (Baurzhan Muftakhidinov / Timur Birsh).
* mkconfig_skip_dmcrypt.patch: Refer to GRUB_PRELOAD_MODULES rather than
  suggesting people write a /etc/grub.d/01_modules script (thanks, Jordan
  Uggla).
* Handle empty dir passed to grub_find_root_device_from_mountinfo; fixes
  grub-mkrelpath on btrfs subvolumes (LP: #712029).
* Add rootflags=subvol=<name> if / is on a btrfs subvolume (LP: #712029).
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
40
grub_gfxmenu_view_t cached_view;
 
41
 
 
42
static void 
 
43
grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused)))
 
44
{
 
45
}
 
46
 
 
47
/* FIXME: Previously 't' changed to text menu is it necessary?  */
 
48
static grub_err_t
 
49
grub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
 
50
{
 
51
  grub_gfxmenu_view_t view = NULL;
 
52
  const char *theme_path;
 
53
  struct grub_menu_viewer *instance;
 
54
  grub_err_t err;
 
55
  struct grub_video_mode_info mode_info;
 
56
 
 
57
  theme_path = grub_env_get ("theme");
 
58
  if (! theme_path)
 
59
    {
 
60
      grub_error_push ();
 
61
      grub_gfxterm_fullscreen ();
 
62
      grub_error_pop ();
 
63
      return grub_error (GRUB_ERR_FILE_NOT_FOUND, "no theme specified");
 
64
    }
 
65
 
 
66
  instance = grub_zalloc (sizeof (*instance));
 
67
  if (!instance)
 
68
    {
 
69
      grub_error_push ();
 
70
      grub_gfxterm_fullscreen ();
 
71
      grub_error_pop ();
 
72
      return grub_errno;
 
73
    }
 
74
 
 
75
  err = grub_video_get_info (&mode_info);
 
76
  if (err)
 
77
    {
 
78
      grub_error_push ();
 
79
      grub_gfxterm_fullscreen ();
 
80
      grub_error_pop ();
 
81
      return err;
 
82
    }
 
83
 
 
84
  if (!cached_view || grub_strcmp (cached_view->theme_path, theme_path) != 0
 
85
      || cached_view->screen.width != mode_info.width
 
86
      || cached_view->screen.height != mode_info.height)
 
87
    {
 
88
      grub_free (cached_view);
 
89
      /* Create the view.  */
 
90
      cached_view = grub_gfxmenu_view_new (theme_path, mode_info.width,
 
91
                                           mode_info.height);
 
92
    }
 
93
 
 
94
  if (! cached_view)
 
95
    {
 
96
      grub_free (instance);
 
97
      grub_error_push ();
 
98
      grub_gfxterm_fullscreen ();
 
99
      grub_error_pop ();
 
100
      return grub_errno;
 
101
    }
 
102
 
 
103
  view = cached_view;
 
104
 
 
105
  view->double_repaint = (mode_info.mode_type
 
106
                          & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)
 
107
    && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP);
 
108
  view->selected = entry;
 
109
  view->menu = menu;
 
110
  view->nested = nested;
 
111
  view->first_timeout = -1;
 
112
 
 
113
  grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
 
114
  if (view->double_repaint)
 
115
    {
 
116
      grub_video_swap_buffers ();
 
117
      grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
 
118
    }
 
119
 
 
120
  grub_gfxmenu_view_draw (view);
 
121
 
 
122
  instance->data = view;
 
123
  instance->set_chosen_entry = grub_gfxmenu_set_chosen_entry;
 
124
  instance->fini = grub_gfxmenu_viewer_fini;
 
125
  instance->print_timeout = grub_gfxmenu_print_timeout;
 
126
  instance->clear_timeout = grub_gfxmenu_clear_timeout;
 
127
 
 
128
  grub_menu_register_viewer (instance);
 
129
 
 
130
  return GRUB_ERR_NONE;
 
131
}
 
132
 
 
133
GRUB_MOD_INIT (gfxmenu)
 
134
{
 
135
  struct grub_term_output *term;
 
136
 
 
137
  FOR_ACTIVE_TERM_OUTPUTS(term)
 
138
    if (grub_gfxmenu_try_hook && grub_strcmp (term->name, "gfxterm") == 0)
 
139
      {
 
140
        grub_gfxterm_fullscreen ();
 
141
        break;
 
142
      }
 
143
 
 
144
  grub_gfxmenu_try_hook = grub_gfxmenu_try;
 
145
}
 
146
 
 
147
GRUB_MOD_FINI (gfxmenu)
 
148
{
 
149
  grub_gfxmenu_view_destroy (cached_view);
 
150
  grub_gfxmenu_try_hook = NULL;
 
151
}