Skip to contentSkip to conversation

Hotkey support

PATCH New Vladimir 'phcoder' Serbinenko 1 participant 1 message Aug 24, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Hotkey support

This patch allows to boot entry with a single keypress

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
ChangeLog +9 -0
index 1efb882..afb1bec 100644
@@ -1,5 +1,14 @@
 2009-08-24  Vladimir Serbinenko  <[email protected]>
 
+	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.
+
+2009-08-24  Vladimir Serbinenko  <[email protected]>
+
 	Rename *_partition_map to part_*
 
 	* partmap/acorn.c (grub_acorn_partition_map): Set name to 'part_acorn'.
include/grub/menu.h +2 -0
index 3bd25e8..fc3ccdd 100644
@@ -41,6 +41,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;
 };
normal/main.c +39 -0
index 66d8418..52feb80 100644
@@ -149,6 +149,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.  */
@@ -164,6 +175,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
   int i;
   struct grub_menu_entry_class *classes_head;  /* Dummy head node for list.  */
   struct grub_menu_entry_class *classes_tail;
+  int hotkey = 0;
 
   /* Allocate dummy head node for class list.  */
   classes_head = grub_zalloc (sizeof (struct grub_menu_entry_class));
@@ -218,6 +230,32 @@ grub_normal_add_menu_entry (int argc, const char **args,
 	      classes_tail = new_class;
 	      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.  */
@@ -274,6 +312,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
     }
 
   (*last)->title = menutitle;
+  (*last)->hotkey = hotkey;
   (*last)->classes = classes_head;
   (*last)->sourcecode = menusourcecode;
 
normal/menu_text.c +12 -0
index e0d96c4..698be65 100644
@@ -500,6 +500,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)
+		    {
+		      grub_setcursor (1);
+		      *auto_boot = 0;
+		      return i;
+		    }
+	      }
 	      break;
 	    }