Index: trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard.c
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard.c	(revision 4572)
+++ trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard.c	(revision 4574)
@@ -23,6 +23,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
-/* our master define to make this module usable outside wine */
-
+
+/* our master define to make this module usable outside of Wine */
 #define OUTOFWINE
 
@@ -136,9 +136,18 @@
  /* a    s    d    f    g    h    j    k    l    ;    '    \ */
    0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x2B,
+#ifndef OUTOFWINE
  /* \      z    x    c    v    b    n    m    ,    .    / */
    0x5e,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
    0x56, /* the 102nd key (actually to the right of l-shift) */
-};
-
+#else
+/* innotek FIX */
+ /* \      z    x    c    v    b    n    m    ,    .    / */
+   0x56,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
+   0x73, /* the extra key on the Brazilian keyboard. */
+#endif
+};
+
+#ifndef OUTOFWINE
+/* innotek FIX - a dvorak keyboard uses standard scan codes. */
 static const WORD main_key_scan_dvorak[MAIN_LEN] =
 {
@@ -153,5 +162,10 @@
    0x56 /* the 102nd key (actually to the right of l-shift) */
 };
-
+#endif
+
+#ifdef OUTOFWINE
+/* What is this supposed to be?  This is just the same as the qwerty layout, with one key
+   in a different place. */
+#endif
 static const WORD main_key_scan_qwerty_jp106[MAIN_LEN] =
 {
@@ -300,4 +314,17 @@
 };
 
+#ifdef OUTOFWINE
+/* innotek FIX */
+/*** United States keyboard layout (dvorak version with phantom key) */
+static const char main_key_US_dvorak_phantom[MAIN_LEN][4] =
+{
+ "`~","1!","2@","3#","4$","5%","6^","7&","8*","9(","0)","[{","]}",
+ "'\"",",<",".>","pP","yY","fF","gG","cC","rR","lL","/?","=+",
+ "aA","oO","eE","uU","iI","dD","hH","tT","nN","sS","-_","\\|",
+ ";:","qQ","jJ","kK","xX","bB","mM","wW","vV","zZ",
+ "<>" /* the phantom key */
+};
+#endif
+
 /*** British keyboard layout */
 static const char main_key_UK[MAIN_LEN][4] =
@@ -603,4 +630,5 @@
 static const char main_key_BE[MAIN_LEN][4] =
 {
+#ifndef OUTOFWINE
  "","&1|","é2@","\"3#","'4","(5","§6^","è7","!8","ç9{","à0}",")°","-_",
  "aA","zZ","eE¤","rR","tT","yY","uU","iI","oO","pP","^¨[","$*]",
@@ -608,4 +636,16 @@
  "wW","xX","cC","vV","bB","nN",",?",";.",":/","=+~",
  "<>\\"
+#else
+/* innotek FIX */
+/* I wonder how much of this Wine code has been properly tested?  There are many
+   seemingly duplicate layouts, and while many specify three or four keysyms per
+   key, the code choked on all keys in this layout containing more than two
+   keysyms.  I suspect that many of these maps only work by luck. */
+ "²³","&1","é2","\"3","'4","(5","§6","è7","!8","ç9","à0",")°","-_",
+ "aA","zZ","eE","rR","tT","yY","uU","iI","oO","pP","^¨","$*",
+ "qQ","sS","dD","fF","gG","hH","jJ","kK","lL","mM","ù%","µ£",
+ "wW","xX","cC","vV","bB","nN",",?",";.",":/","=+",
+ "<>"
+#endif
 };
 
@@ -718,4 +758,5 @@
 };
 
+#ifndef OUTOFWINE
 /*** US international keyboard layout (contributed by Gustavo Noronha (kov@debian.org)) */
 static const char main_key_US_intl[MAIN_LEN][4] =
@@ -726,4 +767,25 @@
   "zZ", "xX", "cC", "vV", "bB", "nN", "mM", ",<", ".>", "/?"
 };
+#else
+/* innotek FIX */
+/*** US international keyboard layout (contributed by Gustavo Noronha (kov@debian.org)) */
+static const char main_key_US_intl[MAIN_LEN][4] =
+{
+  "`~", "1!", "2@", "3#", "4$", "5%", "6^", "7&", "8*", "9(", "0)", "-_", "=+",
+  "qQ", "wW", "eE", "rR", "tT", "yY", "uU", "iI", "oO", "pP", "[{", "]}",
+  "aA", "sS", "dD", "fF", "gG", "hH", "jJ", "kK", "lL", ";:", "´¨",
+  "\\|", "zZ", "xX", "cC", "vV", "bB", "nN", "mM", ",<", ".>", "/?"
+};
+
+/*** US international keyboard layout with phantom key (contributed by Gustavo Noronha (kov@debian.org)) */
+static const char main_key_US_intl_phantom[MAIN_LEN][4] =
+{
+  "`~", "1!", "2@", "3#", "4$", "5%", "6^", "7&", "8*", "9(", "0)", "-_", "=+",
+  "qQ", "wW", "eE", "rR", "tT", "yY", "uU", "iI", "oO", "pP", "[{", "]}",
+  "aA", "sS", "dD", "fF", "gG", "hH", "jJ", "kK", "lL", ";:", "´¨",
+  "\\|", "zZ", "xX", "cC", "vV", "bB", "nN", "mM", ",<", ".>", "/?",
+  "<>" /* the phantom key */
+};
+#endif
 
 /*** Slovak keyboard layout (see cssk_ibm(sk_qwerty) in xkbsel)
@@ -923,6 +985,14 @@
  {0x0409, "United States keyboard layout", &main_key_US, &main_key_scan_qwerty, &main_key_vkey_qwerty},
  {0x0409, "United States keyboard layout (phantom key version)", &main_key_US_phantom, &main_key_scan_qwerty, &main_key_vkey_qwerty},
+#ifndef OUTOFWINE
  {0x0409, "United States keyboard layout (dvorak)", &main_key_US_dvorak, &main_key_scan_dvorak, &main_key_vkey_dvorak},
  {0x0409, "United States International keyboard layout", &main_key_US_intl, &main_key_scan_qwerty, &main_key_vkey_qwerty},
+#else
+/* innotek FIX */
+ {0x0409, "United States keyboard layout (dvorak)", &main_key_US_dvorak, &main_key_scan_qwerty, &main_key_vkey_dvorak},
+ {0x0409, "United States keyboard layout (dvorak, phantom key version)", &main_key_US_dvorak_phantom, &main_key_scan_qwerty, &main_key_vkey_dvorak},
+ {0x0409, "United States International keyboard layout", &main_key_US_intl, &main_key_scan_qwerty, &main_key_vkey_qwerty},
+ {0x0409, "United States International keyboard layout (phantom key version)", &main_key_US_intl_phantom, &main_key_scan_qwerty, &main_key_vkey_qwerty},
+#endif
  {0x0809, "British keyboard layout", &main_key_UK, &main_key_scan_qwerty, &main_key_vkey_qwerty},
  {0x0407, "German keyboard layout", &main_key_DE, &main_key_scan_qwerty, &main_key_vkey_qwertz},
@@ -1070,5 +1140,10 @@
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,              /* FF58 */
     /* misc keys */
-    /*?*/ 0, 0x137, /*?*/ 0, 0x152, 0x00, 0x00, 0x00, 0x15D,      /* FF60 */
+#ifdef OUTOFWINE
+/* innotek FIX */
+    /*?*/ 0, 0x137, /*?*/ 0, 0x152, 0x00, 0x00, 0x00, 0x15D,     /* FF60 */
+#else
+    /*?*/ 0, 0x137, /*?*/ 0, 0x152, 0x00, 0x00, 0x00, 0x00,      /* FF60 */
+#endif
     /*?*/ 0, /*?*/ 0, 0x38, 0x146, 0x00, 0x00, 0x00, 0x00,       /* FF68 */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,              /* FF70 */
@@ -1080,5 +1155,10 @@
     0x4D, 0x50, 0x49, 0x51, 0x4F, 0x4C, 0x52, 0x53,              /* FF98 */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,              /* FFA0 */
+#ifdef OUTOFWINE
+/* innotek FIX */
+    0x00, 0x00, 0x37, 0x4E, 0x53, 0x4A, 0x7e, 0x135,             /* FFA8 */
+#else
     0x00, 0x00, 0x37, 0x4E, 0x53, 0x4A, 0x53, 0x135,             /* FFA8 */
+#endif
     0x52, 0x4F, 0x50, 0x51, 0x4B, 0x4C, 0x4D, 0x47,              /* FFB0 */
     0x48, 0x49, 0x00, 0x00, 0x00, 0x00,                          /* FFB8 */
@@ -1091,9 +1171,15 @@
     /* modifier keys */
     0x00, 0x2A, 0x36, 0x1D, 0x11D, 0x3A, 0x00, 0x38,             /* FFE0 */
-    0x138, 0x38, 0x138, 0x15B, 0x15C, 0x00, 0x00, 0x00,            /* FFE8 */
+#ifdef OUTOFWINE
+/* innotek FIX */
+    0x138, 0x38, 0x138, 0x15B, 0x15C, 0x00, 0x00, 0x00,          /* FFE8 */
+#else
+    0x138, 0x38, 0x138, 0x00, 0x00, 0x00, 0x00, 0x00,            /* FFE8 */
+#endif
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,              /* FFF0 */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x153              /* FFF8 */
 };
 
+#ifndef OUTOFWINE
 static const WORD xfree86_vendor_key_vkey[256] =
 {
@@ -1135,4 +1221,59 @@
     0, 0, 0, 0, 0, 0, 0, 0                                      /* 1008FFF8 */
 };
+#else /* OUTOFWINE defined */
+/* innotek FIX */
+/* This list was put together using /usr/include/X11/XF86keysym.h and
+   http://www.win.tue.nl/~aeb/linux/kbd/scancodes-6.html.  It has not yet
+   been extensively tested.  The scancodes are those used by MicroSoft
+   keyboards. */
+static const WORD xfree86_vendor_key_scan[256] =
+{
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FF00 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FF08 */
+ /*    Vol-   Mute   Vol+   Play   Stop   Track- Track+ */
+    0, 0x12e, 0x120, 0x130, 0x122, 0x124, 0x110, 0x119,         /* 1008FF10 */
+ /* Home   E-mail    Search */
+    0x132, 0x16c, 0, 0x165, 0, 0, 0, 0,                         /* 1008FF18 */
+ /* Calndr PwrDown            Back   Forward */
+    0x115, 0x15e, 0, 0, 0, 0, 0x16a, 0x169,                     /* 1008FF20 */
+ /* Stop   Refresh Power Wake            Sleep */
+    0x168, 0x167, 0x15e, 0x163, 0, 0, 0, 0x15f,                 /* 1008FF28 */
+ /* Favrts Pause  Media  MyComp */
+    0x166, 0x122, 0x16d, 0x16b, 0, 0, 0, 0,                     /* 1008FF30 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FF38 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FF40 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FF48 */
+ /* AppL   AppR         Calc      Close  Copy */
+    0x109, 0x11e, 0, 0, 0x121, 0, 0x140, 0x118,                 /* 1008FF50 */
+ /* Cut          Docmnts Excel */
+    0x117, 0, 0, 0x105, 0x114, 0, 0, 0,                         /* 1008FF58 */
+ /*    LogOff */
+    0, 0x116, 0, 0, 0, 0, 0, 0,                                 /* 1008FF60 */
+ /*       OffcHm Open      Paste */
+    0, 0, 0x13c, 0x13f, 0, 0x10a, 0, 0,                         /* 1008FF68 */
+ /*       Reply  Refresh         Save */
+    0, 0, 0x141, 0x167, 0, 0, 0, 0x157,                         /* 1008FF70 */
+ /* ScrlUp ScrlDn    Send   Spell        TaskPane */
+    0x10b, 0x18b, 0, 0x143, 0x123, 0, 0, 0x13d,                 /* 1008FF78 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FF80 */
+ /*    Word */
+    0, 0x113, 0, 0, 0, 0, 0, 0,                                 /* 1008FF88 */
+ /* MailFwd MyPics MyMusic*/
+    0x142, 0x164, 0x13c, 0, 0, 0, 0, 0,                         /* 1008FF90 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FF98 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFA0 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFA8 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFB0 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFB8 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFC0 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFC8 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFD0 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFD8 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFE0 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFE8 */
+    0, 0, 0, 0, 0, 0, 0, 0,                                     /* 1008FFF0 */
+    0, 0, 0, 0, 0, 0, 0, 0                                      /* 1008FFF8 */
+};
+#endif /* OUTOFWINE defined */
 
 #ifndef OUTOFWINE
@@ -1520,4 +1661,12 @@
   int max_score = 0, ismatch = 0;
   char ckey[256][4];
+#ifdef OUTOFWINE
+/* innotek FIX */
+  /* The Wine algorithm is incapable of distinguishing the dvorak and the querty layout,
+     which have the same keys in a different sequence.  Based on the assumption that
+     scan codes are laid out more or less sequentially, we keep a track of how many
+     of our detected scan codes are out of order as an additional matching criterium. */
+  int misorder, last_match, least_misorder = 256;
+#endif
 
   syms = keysyms_per_keycode;
@@ -1561,4 +1710,9 @@
     lkey = main_key_tab[current].key;
     pkey = -1;
+#ifdef OUTOFWINE
+/* innotek FIX - dvorak layout */
+    last_match = 0;
+    misorder = 0;
+#endif
     for (keyc = min_keycode; keyc <= max_keycode; keyc++) {
       if (ckey[keyc][0]) {
@@ -1577,4 +1731,12 @@
 	  if (ok > 0) {
 	    score += ok;
+#ifdef OUTOFWINE
+/* innotek FIX - dvorak layout */
+	    if (key < last_match)
+	    {
+	      ++misorder;
+	    }
+	    last_match = key;
+#endif
 	    break;
 	  }
@@ -1597,8 +1759,18 @@
       }
     }
+#ifndef OUTOFWINE
     TRACE("matches=%d, mismatches=%d, seq=%d, score=%d\n",
 	   match, mismatch, seq, score);
     if ((score > max_score) ||
 	((score == max_score) && (seq > max_seq))) {
+#else
+/* innotek FIX - dvorak layout */
+    TRACE("matches=%d, mismatches=%d, seq=%d, score=%d, misorder = %d\n",
+	   match, mismatch, seq, score, misorder);
+    if ((score > max_score) ||
+	((score == max_score) && (seq > max_seq)) ||
+	((score == max_score) && (seq == max_seq) &&
+	 (misorder < least_misorder))) {
+#endif
       /* best match so far */
       kbd_layout = current;
@@ -1606,4 +1778,8 @@
       max_seq = seq;
       ismatch = !mismatch;
+#ifdef OUTOFWINE
+/* innotek FIX - dvorak layout */
+      least_misorder = misorder;
+#endif
     }
   }
@@ -1728,6 +1904,7 @@
 		vkey |= 0x100;
 #else
-                /* @michael: this needs to be investigated and improved on. */
-                scan = 0x100;
+/* innotek FIX - multimedia/internet keys */
+                /* @michael: this needs to be tested and completed some day. */
+                scan = xfree86_vendor_key_scan[keysym & 0xff];
 #endif
             } else if (keysym == 0x20) {                 /* Spacebar */
@@ -1737,4 +1914,5 @@
 		scan = 0x39;
 #ifdef OUTOFWINE
+/* innotek FIX - AltGr support */
             } else if (keysym == 0xFE03) {               /* ISO level3 shift, aka AltGr */
 		scan = 0x138;
Index: trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard_outofwine.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard_outofwine.h	(revision 4572)
+++ trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard_outofwine.h	(revision 4574)
@@ -70,7 +70,12 @@
 
 /* debug macros */
+#if 0
+# include <stdio.h>
+# define noop printf
+#else
 inline static void noop(char *arg, ...)
 {
 }
+#endif
 
 #define TRACE noop
