Index: /trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard-new.c
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard-new.c	(revision 6862)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard-new.c	(revision 6863)
@@ -60,6 +60,24 @@
 #include <stdarg.h>
 #include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
 
 static unsigned keyc2scan[256];
+static int log_kb_1 = 0;
+static int log_kb_2 = 0;
+
+#define LOG_KB_1(a) \
+do { \
+    if (log_kb_1) { \
+        printf a; \
+    } \
+} while (0)
+
+#define LOG_KB_2(a) \
+do { \
+    if (log_kb_2) { \
+        printf a; \
+    } \
+} while (0)
 
 /* Keyboard layout tables for guessing the current keyboard layout. */
@@ -145,5 +163,5 @@
         determine the direction that the keycodes are running in. */
     int pkey = -1;
-    TRACE("Attempting to match against \"%s\"\n", main_key_tab[current].comment);
+    LOG_KB_2(("Attempting to match against \"%s\"\n", main_key_tab[current].comment));
     for (keyc = min_keycode; keyc <= max_keycode; keyc++) {
       if (0 != ckey[keyc][0]) {
@@ -189,12 +207,11 @@
               str[0] = ckey[keyc][0];
           }
-          TRACE_(key)("mismatch for keycode %d, keysym \"%s\" (0x%.2hx 0x%.2hx)\n",
-                       keyc, str, ckey[keyc][0], ckey[keyc][1]);
+          LOG_KB_2(("Mismatch for keycode %d, keysym \"%s\" (0x%.2hx 0x%.2hx)\n",
+                       keyc, str, ckey[keyc][0], ckey[keyc][1]));
 #endif /* DEBUG defined */
 	}
       }
     }
-    TRACE("matches=%d, seq=%d\n",
-	   match, seq);
+    LOG_KB_2(("Matches=%d, seq=%d\n", match, seq));
     if (   (match > max_score)
 	|| ((match == max_score) && (seq > max_seq))
@@ -207,6 +224,6 @@
   }
   /* we're done, report results if necessary */
-  TRACE("detected layout is \"%s\", matches=%d, seq=%d\n",
-        main_key_tab[kbd_layout].comment, max_score, max_seq);
+  LOG_KB_1(("Detected layout is \"%s\", matches=%d, seq=%d\n",
+        main_key_tab[kbd_layout].comment, max_score, max_seq));
   return kbd_layout;
 }
@@ -232,4 +249,12 @@
     unsigned matches = 0, entries = 0;
 
+    /* Should we log to standard output? */
+    if (NULL != getenv("LOG_KB_PRIMARY")) {
+        log_kb_1 = 1;
+    }
+    if (NULL != getenv("LOG_KB_SECONDARY")) {
+        log_kb_1 = 1;
+        log_kb_2 = 1;
+    }
     XDisplayKeycodes(display, &min_keycode, &max_keycode);
 
@@ -279,5 +304,4 @@
 		++matches;
 	      }
-#ifdef DEBUG
               if (0 == scan) {
                 /* print spaces instead of \0's */
@@ -289,8 +313,18 @@
                     str[1] = shifted;
                 }
-                TRACE_(key)("No match found for keycode %d, keysym \"%s\" (0x%x 0x%x)\n",
-                             keyc, str, unshifted, shifted);
-            }
-#endif /* DEBUG defined */
+                LOG_KB_1(("No match found for keycode %d, keysym \"%s\" (0x%x 0x%x)\n",
+                             keyc, str, unshifted, shifted));
+              } else if ((keyc > 8) && (keyc < 97) && (keyc - scan != 8)) {
+                /* print spaces instead of \0's */
+                char str[3] = "  ";
+                if ((unshifted > 32) && (unshifted < 127)) {
+                    str[0] = unshifted;
+                }
+                if ((shifted > 32) && (shifted < 127)) {
+                    str[1] = shifted;
+                }
+                LOG_KB_1(("Warning - keycode %d, keysym \"%s\" (0x%x 0x%x) was matched to scancode %d\n",
+                             keyc, str, unshifted, shifted, scan));
+              }
 	    }
         }
@@ -305,5 +339,5 @@
         }
     }
-    TRACE("Finished mapping keyboard, matches=%d, entries=%d\n", matches, entries);
+    LOG_KB_1(("Finished mapping keyboard, matches=%d, entries=%d\n", matches, entries));
     if (matches != entries)
     {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard.h	(revision 6862)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/linux/keyboard.h	(revision 6863)
@@ -22,6 +22,6 @@
  */
 
-#ifndef __H_KEYBOARD_OUTOFWINE
-#define __H_KEYBOARD_OUTOFWINE
+#ifndef __H_KEYBOARD
+#define __H_KEYBOARD
 
 #include <X11/Xlib.h>
@@ -42,25 +42,3 @@
 #endif
 
-/* debug macros */
-#if 0 && defined(DEBUG)
-# include <stdio.h>
-# define noop printf
-#else
-#ifdef __cplusplus
-inline static void noop(char *, ...)
-#else
-inline static void noop(char *arg, ...)
-#endif
-{
-}
-#endif
-
-#define TRACE noop
-/* #define TRACE printf */
-#define TRACE_(a) noop
-/* #define TRACE_(ch) printf */
-#define TRACE_ON(a) 0
-#define WARN noop
-#define ERR noop
-
-#endif /* __H_KEYBOARD_OUTOFWINE */
+#endif /* __H_KEYBOARD */
