gfxmenu.c 3.7 KB

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