Ticket #2302: keyboard-scancode-remapper.diff
| File keyboard-scancode-remapper.diff, 13.2 KB (added by , 15 years ago) |
|---|
-
src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h
39 39 40 40 #ifdef Q_WS_X11 41 41 # include <sys/wait.h> 42 # include "XKeyboard.h" 42 43 #endif 43 44 44 45 class QAction; … … 1001 1002 bool mInverted; 1002 1003 }; 1003 1004 1005 #ifdef Q_WS_X11 1006 void initMappedX11Keyboard(); 1007 #endif 1008 1004 1009 #endif /* __VBoxGlobal_h__ */ -
src/VBox/Frontends/VirtualBox/include/XKeyboard.h
24 24 #define __XKeyboard_h__ 25 25 26 26 // initialize the X keyboard subsystem 27 bool initXKeyboard(Display *dpy );27 bool initXKeyboard(Display *dpy, int (*scancodes)[2]); 28 28 // our custom keyboard handler 29 29 unsigned handleXKeyEvent(XEvent *event); 30 30 // returns the number of keysyms per keycode (only valid after initXKeyboard()) -
src/VBox/Frontends/VirtualBox/include/VBoxGlobalSettings.h
46 46 QString guiFeatures; 47 47 QString languageId; 48 48 QString maxGuestRes; 49 QString remapScancodes; 49 50 bool trayIconEnabled; 50 51 bool dockPreviewEnabled; 51 52 … … 62 63 Q_PROPERTY (QString guiFeatures READ guiFeatures WRITE setGuiFeatures) 63 64 Q_PROPERTY (QString languageId READ languageId WRITE setLanguageId) 64 65 Q_PROPERTY (QString maxGuestRes READ maxGuestRes WRITE setMaxGuestRes) 66 Q_PROPERTY (QString remapScancodes READ remapScancodes WRITE setRemapScancodes) 65 67 Q_PROPERTY (bool trayIconEnabled READ trayIconEnabled WRITE setTrayIconEnabled) 66 68 Q_PROPERTY (bool dockPreviewEnabled READ dockPreviewEnabled WRITE setDockPreviewEnabled) 67 69 … … 106 108 mData()->maxGuestRes = aMaxGuestRes; 107 109 } 108 110 111 QString remapScancodes() const { return data()->remapScancodes; } 112 void setRemapScancodes (const QString &aRemapScancodes) 113 { 114 mData()->remapScancodes = aRemapScancodes; 115 } 116 117 109 118 bool trayIconEnabled() const { return data()->trayIconEnabled; } 110 119 void setTrayIconEnabled (bool enabled) 111 120 { -
src/VBox/Frontends/VirtualBox/src/VBoxGlobalSettings.cpp
59 59 guiFeatures = QString::null; 60 60 languageId = QString::null; 61 61 maxGuestRes = "auto"; 62 remapScancodes = QString::null; 62 63 trayIconEnabled = false; 63 64 dockPreviewEnabled = true; 64 65 } … … 70 71 guiFeatures = that.guiFeatures; 71 72 languageId = that.languageId; 72 73 maxGuestRes = that.maxGuestRes; 74 remapScancodes = that.remapScancodes; 73 75 trayIconEnabled = that.trayIconEnabled; 74 76 dockPreviewEnabled = that.dockPreviewEnabled; 75 77 } … … 86 88 guiFeatures == that.guiFeatures && 87 89 languageId == that.languageId && 88 90 maxGuestRes == that.maxGuestRes && 91 remapScancodes == that.remapScancodes && 89 92 trayIconEnabled == that.trayIconEnabled 90 93 && dockPreviewEnabled == that.dockPreviewEnabled 91 94 ); … … 114 117 { "GUI/Customizations", "guiFeatures", "\\S+", true }, 115 118 { "GUI/LanguageID", "languageId", gVBoxLangIDRegExp, true }, 116 119 { "GUI/MaxGuestResolution", "maxGuestRes", "\\d*[1-9]\\d*,\\d*[1-9]\\d*|any|auto", true }, 120 { "GUI/RemapScancodes", "remapScancodes", "(\\d+=\\d+,)*\\d+=\\d+", true }, 117 121 { "GUI/TrayIcon/Enabled", "trayIconEnabled", "true|false", true }, 118 122 #ifdef Q_WS_MAC 119 123 { VBoxDefs::GUI_RealtimeDockIconUpdateEnabled, "dockPreviewEnabled", "true|false", true } -
src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
810 810 811 811 #ifdef Q_WS_X11 812 812 /* initialize the X keyboard subsystem */ 813 init XKeyboard (QX11Info::display());813 initMappedX11Keyboard(); 814 814 #endif 815 815 816 816 ::memset (mPressedKeys, 0, sizeof (mPressedKeys)); -
src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
4941 4941 mAction->setText (text); 4942 4942 } 4943 4943 4944 #ifdef Q_WS_X11 4945 /** 4946 * Initialize X11 keyboard including the remapping specified in the 4947 * global property GUI/RemapScancodes. This property is a string of 4948 * comma-seperated x=y pairs, where x is the X11 keycode and y is the 4949 * keyboard scancode that is emitted when the key attached to the X11 4950 * keycode is pressed. 4951 */ 4952 void initMappedX11Keyboard() { 4953 int (*scancodes)[2] = NULL; 4954 int (*scancodesTail)[2] = NULL; 4955 QString remapScancodes = vboxGlobal().settings().publicProperty ("GUI/RemapScancodes"); 4956 4957 if(remapScancodes != QString::null) { 4958 QStringList tuples = remapScancodes.split(",", QString::SkipEmptyParts); 4959 scancodes = scancodesTail = new int [tuples.size()+1][2]; 4960 for (int i = 0; i < tuples.size(); ++i) { 4961 QStringList keyc2scan = tuples.at(i).split("="); 4962 (*scancodesTail)[0] = keyc2scan.at(0).toUInt(); 4963 (*scancodesTail)[1] = keyc2scan.at(1).toUInt(); 4964 /* Do not advance on (ignore) identity mappings as this is 4965 the stop signal to initXKeyboard and friends */ 4966 if((*scancodesTail)[0] != (*scancodesTail)[1]) 4967 scancodesTail++; 4968 } 4969 (*scancodesTail)[0] = (*scancodesTail)[1] = 0; 4970 } 4971 /* initialize the X keyboard subsystem */ 4972 initXKeyboard (QX11Info::display(),scancodes); 4973 4974 if(scancodes) delete scancodes; 4975 } 4976 #endif -
src/VBox/Frontends/VirtualBox/src/X11/XKeyboard-new.cpp
186 186 * X server, find the PC layout which is closest to it and remember the 187 187 * mappings. 188 188 */ 189 bool initXKeyboard(Display *dpy )189 bool initXKeyboard(Display *dpy, int (*remapScancodes)[2]) 190 190 { 191 X11DRV_InitKeyboard(dpy, &gfByLayoutOK, &gfByTypeOK );191 X11DRV_InitKeyboard(dpy, &gfByLayoutOK, &gfByTypeOK, remapScancodes); 192 192 /* It will almost always work to some extent */ 193 193 return true; 194 194 } … … 202 202 dumpLayout(dpy); 203 203 if ((1 == gfByLayoutOK) && (gfByTypeOK != 1)) 204 204 dumpType(dpy); 205 if ((gfByLayoutOK != 1) && (gfByTypeOK != 1)) 205 if ((gfByLayoutOK != 1) && (gfByTypeOK != 1)) { 206 206 LogRel(("Failed to recognize the keyboard mapping or to guess it based on\n" 207 207 "the keyboard layout. It is very likely that some keys will not\n" 208 208 "work correctly in the guest. If you would like to help us improve\n" 209 209 "the product, please submit a bug report, giving us information\n" 210 210 "about your keyboard type, its layout and other relevant\n" 211 211 "information such as whether you are using a remote X server or\n" 212 "something similar.\n")); 212 "something similar. \n")); 213 unsigned *keyc2scan=X11DRV_getKeyc2scan(); 214 215 LogRel(("The keycode-to-scancode table is: %d=%d",0,keyc2scan[0])); 216 for(int i=1; i<256; i++) 217 LogRel((",%d=%d",i,keyc2scan[i])); 218 LogRel(("\n")); 219 } 213 220 } 214 221 215 222 /* -
src/VBox/Frontends/VirtualBox/src/X11/keyboard.h
43 43 # define CCALL 44 44 #endif 45 45 #ifdef VBOX_HAVE_VISIBILITY_HIDDEN 46 extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK); 46 extern CCALL __attribute__((visibility("default"))) unsigned *X11DRV_getKeyc2scan(); 47 extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK, int (*remapScancodes)[2]); 47 48 extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_KeyEvent(Display *dpy, KeyCode code); 48 49 #else 49 extern CCALL unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK); 50 extern CCALL unsigned *X11DRV_getKeyc2scan(); 51 extern CCALL unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK, int (*remapScancodes)[2]); 50 52 extern CCALL unsigned X11DRV_KeyEvent(Display *dpy, KeyCode code); 51 53 #endif 52 54 -
src/VBox/Frontends/VirtualBox/src/X11/keyboard-new.c
54 54 #include <stdlib.h> 55 55 #include <stdio.h> 56 56 57 #define KEYC2SCAN_SIZE 256 58 57 59 /** 58 60 * Array containing the current mapping of keycodes to scan codes, detected 59 61 * using the keyboard layout algorithm in X11DRV_InitKeyboardByLayout. 60 62 */ 61 static unsigned keyc2scan[256]; 62 /** 63 * Whether a keyboard was detected with a well-known keycode to scan code 64 * mapping. 65 */ 66 static unsigned use_builtin_table = 0; 67 /** The index of the well-known keycode to scan code mapping in our table. */ 68 static unsigned builtin_table_number; 63 static unsigned keyc2scan[KEYC2SCAN_SIZE]; 69 64 /** Whether to output basic debugging information to standard output */ 70 65 static int log_kb_1 = 0; 71 66 /** Whether to output verbose debugging information to standard output */ … … 125 120 scan = 0x138; 126 121 } 127 122 if (keysym != 0 && scan == 0) 128 {129 if (use_builtin_table != 0)130 scan = main_keyboard_type_scans[builtin_table_number][code];131 else132 123 scan = keyc2scan[code]; 133 } 124 134 125 return scan; 135 126 } 136 127 … … 439 430 && (XKeysymToKeycode(display, XK_F8) == main_keyboard_type_list[i].f8) 440 431 ) 441 432 found = 1; 442 use_builtin_table = found;443 433 if (found != 0) 444 builtin_table_number = i - 1;434 memcpy(keyc2scan, main_keyboard_type_scans[i - 1], KEYC2SCAN_SIZE); 445 435 return found; 446 436 } 447 437 … … 463 453 * @warning not re-entrant 464 454 * @returns 1 if the layout found was optimal, 0 if it was not. This is 465 455 * for diagnostic purposes 466 * @param display a pointer to the X11 display 467 * @param byLayoutOK diagnostic - set to one if detection by layout 468 * succeeded, and to 0 otherwise 469 * @param byTypeOK diagnostic - set to one if detection by type 470 * succeeded, and to 0 otherwise 456 * @param display a pointer to the X11 display 457 * @param byLayoutOK diagnostic - set to one if detection by layout 458 * succeeded, and to 0 otherwise 459 * @param byTypeOK diagnostic - set to one if detection by type 460 * succeeded, and to 0 otherwise 461 * @param remapScancode array of tuples that remap the keycode (first 462 * part) to a scancode (second part) 471 463 */ 472 unsigned X11DRV_InitKeyboard(Display *display, unsigned *byLayoutOK, unsigned *byTypeOK )464 unsigned X11DRV_InitKeyboard(Display *display, unsigned *byLayoutOK, unsigned *byTypeOK, int (*remapScancodes)[2]) 473 465 { 474 unsigned byLayout = X11DRV_InitKeyboardByLayout(display); 475 unsigned byType = X11DRV_InitKeyboardByType(display); 466 unsigned byLayout; 467 unsigned byType; 468 469 byLayout = X11DRV_InitKeyboardByLayout(display); 476 470 *byLayoutOK = byLayout; 477 *byTypeOK = byType; 471 472 byType = X11DRV_InitKeyboardByType(display); 473 *byTypeOK = byType; 474 475 /* Remap keycodes after initialization. Remapping stops after an 476 identity mapping is seen */ 477 if(remapScancodes != NULL) 478 for(; (*remapScancodes)[0] != (*remapScancodes)[1]; remapScancodes++) 479 keyc2scan[(*remapScancodes)[0]] = (*remapScancodes)[1]; 480 478 481 return (byLayout || byType) ? 1 : 0; 479 482 } 483 484 /** 485 * Returns the keycode to scancode array 486 */ 487 unsigned *X11DRV_getKeyc2scan() 488 { 489 return keyc2scan; 490 } -
src/VBox/Frontends/VirtualBox/src/QIHotKeyEdit.cpp
22 22 23 23 #include "QIHotKeyEdit.h" 24 24 #include "VBoxDefs.h" 25 #include "VBoxGlobal.h" 25 26 26 27 /* Qt includes */ 27 28 #include <QApplication> … … 118 119 { 119 120 #ifdef Q_WS_X11 120 121 /* Initialize the X keyboard subsystem */ 121 init XKeyboard (QX11Info::display());122 initMappedX11Keyboard(); 122 123 #endif 123 124 124 125 clear();

