gfxmenu.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #include <grub/types.h>
  20. #include <grub/misc.h>
  21. #include <grub/mm.h>
  22. #include <grub/err.h>
  23. #include <grub/dl.h>
  24. #include <grub/command.h>
  25. #include <grub/video.h>
  26. #include <grub/gfxterm.h>
  27. #include <grub/bitmap.h>
  28. #include <grub/bitmap_scale.h>
  29. #include <grub/term.h>
  30. #include <grub/env.h>
  31. #include <grub/normal.h>
  32. #include <grub/gfxwidgets.h>
  33. #include <grub/menu.h>
  34. #include <grub/menu_viewer.h>
  35. #include <grub/gfxmenu_model.h>
  36. #include <grub/gfxmenu_view.h>
  37. #include <grub/time.h>
  38. #include <grub/i18n.h>
  39. GRUB_MOD_LICENSE ("GPLv3+");
  40. static grub_gfxmenu_view_t cached_view;
  41. static void
  42. grub_gfxmenu_viewer_fini (void *data __attribute__ ((unused)))
  43. {
  44. }
  45. /* FIXME: Previously 't' changed to text menu is it necessary? */
  46. static grub_err_t
  47. grub_gfxmenu_try (int entry, grub_menu_t menu, int nested)
  48. {
  49. grub_gfxmenu_view_t view = NULL;
  50. const char *theme_path;
  51. char *full_theme_path = 0;
  52. struct grub_menu_viewer *instance;
  53. grub_err_t err;
  54. struct grub_video_mode_info mode_info;
  55. theme_path = grub_env_get ("theme");
  56. if (! theme_path)
  57. return grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
  58. "theme");
  59. err = grub_video_get_info (&mode_info);
  60. if (err)
  61. return err;
  62. instance = grub_zalloc (sizeof (*instance));
  63. if (!instance)
  64. return grub_errno;
  65. if (theme_path[0] != '/' && theme_path[0] != '(')
  66. {
  67. const char *prefix;
  68. prefix = grub_env_get ("prefix");
  69. full_theme_path = grub_xasprintf ("%s/themes/%s",
  70. prefix,
  71. theme_path);
  72. }
  73. if (!cached_view || grub_strcmp (cached_view->theme_path,
  74. full_theme_path ? : theme_path) != 0
  75. || cached_view->screen.width != mode_info.width
  76. || cached_view->screen.height != mode_info.height)
  77. {
  78. grub_gfxmenu_view_destroy (cached_view);
  79. /* Create the view. */
  80. cached_view = grub_gfxmenu_view_new (full_theme_path ? : theme_path,
  81. mode_info.width,
  82. mode_info.height);
  83. }
  84. grub_free (full_theme_path);
  85. if (! cached_view)
  86. {
  87. grub_free (instance);
  88. return grub_errno;
  89. }
  90. view = cached_view;
  91. view->double_repaint = (mode_info.mode_type
  92. & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)
  93. && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP);
  94. view->selected = entry;
  95. view->menu = menu;
  96. view->nested = nested;
  97. view->first_timeout = -1;
  98. grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
  99. if (view->double_repaint)
  100. {
  101. grub_video_swap_buffers ();
  102. grub_video_set_viewport (0, 0, mode_info.width, mode_info.height);
  103. }
  104. grub_gfxmenu_view_draw (view);
  105. instance->data = view;
  106. instance->set_chosen_entry = grub_gfxmenu_set_chosen_entry;
  107. instance->fini = grub_gfxmenu_viewer_fini;
  108. instance->print_timeout = grub_gfxmenu_print_timeout;
  109. instance->clear_timeout = grub_gfxmenu_clear_timeout;
  110. grub_menu_register_viewer (instance);
  111. return GRUB_ERR_NONE;
  112. }
  113. GRUB_MOD_INIT (gfxmenu)
  114. {
  115. struct grub_term_output *term;
  116. FOR_ACTIVE_TERM_OUTPUTS(term)
  117. if (grub_gfxmenu_try_hook && term->fullscreen)
  118. {
  119. term->fullscreen ();
  120. break;
  121. }
  122. grub_gfxmenu_try_hook = grub_gfxmenu_try;
  123. }
  124. GRUB_MOD_FINI (gfxmenu)
  125. {
  126. grub_gfxmenu_view_destroy (cached_view);
  127. grub_gfxmenu_try_hook = NULL;
  128. }