]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Reimport hotkey support
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 29 Dec 2009 22:01:12 +0000 (23:01 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 29 Dec 2009 22:01:12 +0000 (23:01 +0100)
ChangeLog.hotkey [new file with mode: 0644]
include/grub/menu.h
normal/main.c
normal/menu.c

diff --git a/ChangeLog.hotkey b/ChangeLog.hotkey
new file mode 100644 (file)
index 0000000..1117b97
--- /dev/null
@@ -0,0 +1,9 @@
+2009-08-24  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Hotkey support
+
+       * include/grub/menu.h (grub_menu_entry): New field 'hotkey'.
+       * normal/main.c (hotkey_aliases): New variable.
+       (grub_normal_add_menu_entry): Parse "--hotkey".
+       * normal/menu_text.c (run_menu): Handle hotkeys.
+
index 78f461b928d268a2df9cb5002c1a4687c8ffa803..e5e5fb11074ad874a73b7be883368caeb04109af 100644 (file)
@@ -47,6 +47,8 @@ struct grub_menu_entry
   /* The sourcecode of the menu entry, used by the editor.  */
   const char *sourcecode;
 
+  int hotkey;
+
   /* The next element.  */
   struct grub_menu_entry *next;
 };
index 6d7a558f387279608ed30828772daf783455864a..fd1088a10f46936115181e0d76139fbf0647ef2a 100644 (file)
@@ -155,6 +155,17 @@ free_menu_entry_classes (struct grub_menu_entry_class *head)
     }
 }
 
+static struct
+{
+  char *name;
+  int key;
+} hotkey_aliases[] =
+  {
+    {"backspace", '\b'},
+    {"tab", '\t'},
+    {"delete", GRUB_TERM_DC}
+  };
+
 /* Add a menu entry to the current menu context (as given by the environment
    variable data slot `menu').  As the configuration file is read, the script
    parser calls this when a menu entry is to be created.  */
@@ -171,6 +182,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
   struct grub_menu_entry_class *classes_head;  /* Dummy head node for list.  */
   struct grub_menu_entry_class *classes_tail;
   char *users = NULL;
+  int hotkey = 0;
 
   /* Allocate dummy head node for class list.  */
   classes_head = grub_zalloc (sizeof (struct grub_menu_entry_class));
@@ -237,6 +249,32 @@ grub_normal_add_menu_entry (int argc, const char **args,
 
              continue;
            }
+         else if (grub_strcmp(arg, "hotkey") == 0)
+           {
+             unsigned j;
+
+             i++;
+             if (args[i][1] == 0)
+               {
+                 hotkey = args[i][0];
+                 continue;
+               }
+
+             for (j = 0; j < ARRAY_SIZE (hotkey_aliases); j++)
+               if (grub_strcmp (args[i], hotkey_aliases[j].name) == 0)
+                 {
+                   hotkey = hotkey_aliases[j].key;
+                   break;
+                 }
+
+             if (j < ARRAY_SIZE (hotkey_aliases))
+               continue;
+
+             failed = 1;
+             grub_error (GRUB_ERR_MENU,
+                         "Invalid hotkey: '%s'.", args[i]);
+             break;
+           }
          else
            {
              /* Handle invalid argument.  */
@@ -293,6 +331,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
     }
 
   (*last)->title = menutitle;
+  (*last)->hotkey = hotkey;
   (*last)->classes = classes_head;
   if (users)
     (*last)->restricted = 1;
index 850350edda9b9dbf44e5e786cc231c1635497b42..19e83831d02b293ffcd24641cd58757e8e462469 100644 (file)
@@ -232,9 +232,6 @@ menu_fini (void)
   viewers = NULL;
 }
 
-/* FIXME: allow text menu in parallel with gfxmenu.  */
-grub_err_t (*grub_gfxmenu_try_hook) (int entry, grub_menu_t menu,
-                                    int nested) = NULL;
 static void
 menu_init (int entry, grub_menu_t menu, int nested)
 {
@@ -479,6 +476,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
              goto refresh;
 
            default:
+             {
+               grub_menu_entry_t entry;
+               int i;
+               for (i = 0, entry = menu->entry_list; i < menu->size;
+                    i++, entry = entry->next)
+                 if (entry->hotkey == c)
+                   {
+                     menu_fini ();
+                     *auto_boot = 0;
+                     return i;
+                   }
+             }
              break;
            }
        }