]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Support numpad
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 22 Aug 2010 00:17:14 +0000 (02:17 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 22 Aug 2010 00:17:14 +0000 (02:17 +0200)
commands/keylayouts.c
term/at_keyboard.c
term/usb_keyboard.c

index d2cb0e1e7530d56a79202aa9c9099430519be009..3442d42e71ba524aeca922cdf50b421333973118 100644 (file)
@@ -106,13 +106,61 @@ map_key_core (int code, int status, int *alt_gr_consumed)
     return grub_current_layout->keyboard_map[code];
 }
 
+static int
+map_high_key (int code, int status)
+{
+  int ret = 0;
+  if (status & (GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT))
+    ret |= GRUB_TERM_SHIFT;
+
+  if (code == 0xb5)
+    return '/';
+
+  if (code == 0xb7)
+    return '*';
+
+  if (code == 0x9c)
+    return '\n';
+
+  if (code < 0xc7 || code > 0xd3 || code == 0xca || code == 0xce
+      || code == 0xcc)
+    return ret;
+  /* GRUB keyboard codes are conveniently similar to AT codes.  */
+  return ret | GRUB_TERM_EXTENDED | (code & ~0x80);
+}
+
+static int
+map_num_key (int code, int state)
+{
+  const int map_arrows[]
+    = { GRUB_TERM_KEY_HOME, GRUB_TERM_KEY_UP, GRUB_TERM_KEY_PPAGE,
+       '-', GRUB_TERM_KEY_LEFT, GRUB_TERM_KEY_CENTER, GRUB_TERM_KEY_RIGHT, '+',
+       GRUB_TERM_KEY_END, GRUB_TERM_KEY_DOWN, GRUB_TERM_KEY_NPAGE,
+       GRUB_TERM_KEY_INSERT, GRUB_TERM_KEY_DC };
+  const int map_nums[]
+    = { '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'};
+
+  if (((state & GRUB_TERM_STATUS_NUM)
+       && !(state & (GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT)))
+      || ((state & GRUB_TERM_STATUS_NUM)
+       && !(state & (GRUB_TERM_STATUS_RSHIFT | GRUB_TERM_STATUS_LSHIFT))))
+    return map_nums [code - 0x47];
+  else
+    return map_arrows [code - 0x47];
+}
+
 unsigned
 grub_term_map_key (int code, int status)
 {
-  int alt_gr_consumed;
+  int alt_gr_consumed = 0;
   int key;
 
-  key = map_key_core (code, status, &alt_gr_consumed);
+  if (code >= 0x47 && code <= 0x53)
+    key = map_num_key (code, status);    
+  else if (code & 0x80)
+    key = map_high_key (code, status);
+  else
+    key = map_key_core (code, status, &alt_gr_consumed);
   
   if (key == 0 || key == GRUB_TERM_SHIFT)
     grub_dprintf ("atkeyb", "Unknown key 0x%x detected\n", code);
index 054dc9805b70b517a86c0d6ed3f17bdb525d360a..c98fc82550fd17f6251aad02c2eb8e3cf7d47819 100644 (file)
@@ -110,7 +110,6 @@ grub_keyboard_isr (grub_uint8_t key)
            at_keyboard_status &= ~GRUB_TERM_STATUS_LALT;
          break;
       }
-  extended_pending = (key == 0xe0);
 }
 
 /* If there is a raw key pending, return it; otherwise return -1.  */
@@ -118,13 +117,18 @@ static int
 grub_keyboard_getkey (void)
 {
   grub_uint8_t key;
+  grub_uint8_t ret;
   if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
     return -1;
   key = grub_inb (KEYBOARD_REG_DATA);
   /* FIXME */ grub_keyboard_isr (key);
+  ret = KEYBOARD_SCANCODE (key);
+  if (extended_pending)
+    ret |= 0x80;
+  extended_pending = (key == 0xe0);
   if (! KEYBOARD_ISMAKE (key))
     return -1;
-  return (KEYBOARD_SCANCODE (key));
+  return ret;
 }
 
 
index 3dfe5331bcbe27170e750d5102e1083403c02ee2..1082e62d058382823e9d7bd872ac2ffdb1dd3d9e 100644 (file)
@@ -69,20 +69,20 @@ static grub_uint8_t usb_to_at_map[128] =
   /* 0x42 */ 0x43 /* F9 */,         0x44 /* F10 */, 
   /* 0x44 */ 0x57 /* F11 */,        0x58 /* F12 */,
   /* 0x46 */ 0x00,                  0x00, 
-  /* 0x48 */ 0x00,                  0x52 /* Insert */, 
-  /* 0x4a */ 0x47 /* HOME */,       0x51 /* PPAGE */, 
-  /* 0x4c */ 0x53 /* DC */,         0x4f /* END */, 
-  /* 0x4e */ 0x49 /* NPAGE */,      0x4d /* RIGHT */, 
-  /* 0x50 */ 0x4b /* LEFT */,       0x50 /* DOWN */, 
-  /* 0x52 */ 0x48 /* UP */,         0x00, 
-  /* 0x54 */ 0x00,                  0x00
-  /* 0x56 */ 0x00,                  0x00
-  /* 0x58 */ 0x00,                  0x00
-  /* 0x5a */ 0x00,                  0x00
-  /* 0x5c */ 0x00,                  0x00
-  /* 0x5e */ 0x00,                  0x00
-  /* 0x60 */ 0x00,                  0x00
-  /* 0x62 */ 0x00,                  0x00
+  /* 0x48 */ 0x00,                  0xd2 /* Insert */, 
+  /* 0x4a */ 0xc7 /* HOME */,       0xd1 /* PPAGE */, 
+  /* 0x4c */ 0xd3 /* DC */,         0xcf /* END */, 
+  /* 0x4e */ 0xc9 /* NPAGE */,      0xcd /* RIGHT */, 
+  /* 0x50 */ 0xcb /* LEFT */,       0xd0 /* DOWN */, 
+  /* 0x52 */ 0xc8 /* UP */,         0x00, 
+  /* 0x54 */ 0xb5 /* Num / */,      0xb7 /* Num * */
+  /* 0x56 */ 0x4a /* Num - */,      0x4e /* Num + */
+  /* 0x58 */ 0x9c /* Num \n */,     0x4f /* Num 1 */
+  /* 0x5a */ 0x50 /* Num 2 */,      0x51 /* Num 3 */
+  /* 0x5c */ 0x4b /* Num 4 */,      0x4c /* Num 5 */
+  /* 0x5e */ 0x4d /* Num 6 */,      0x47 /* Num 7 */
+  /* 0x60 */ 0x48 /* Num 8 */,      0x49 /* Num 9 */
+  /* 0x62 */ 0x52 /* Num 0 */,      0x53 /* Num . */
   /* 0x64 */ 0x56 /* 102nd key. */, 0x00, 
   /* 0x66 */ 0x00,                  0x00, 
   /* 0x68 */ 0x00,                  0x00, 
@@ -428,7 +428,7 @@ grub_usb_keyboard_checkkey (struct grub_term_input *term)
       return -1;
     }
 
-  if (data[2] > ARRAY_SIZE (usb_to_at_map) || usb_to_at_map[data[2]] == 0)
+  if (data[2] >= ARRAY_SIZE (usb_to_at_map) || usb_to_at_map[data[2]] == 0)
     grub_printf ("Unknown key 0x%02x detected\n", data[2]);
   else
     {