VirtualBox

Changeset 21711 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 17, 2009 8:49:59 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt: allow users to specify their own scan code mappings on X11 hosts, thanks to user therp on virtualbox.org (see #2302)

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobalSettings.h

    r15664 r21711  
    4747    QString languageId;
    4848    QString maxGuestRes;
     49    QString remapScancodes;
    4950    bool trayIconEnabled;
    5051    bool dockPreviewEnabled;
     
    6364    Q_PROPERTY (QString languageId READ languageId WRITE setLanguageId)
    6465    Q_PROPERTY (QString maxGuestRes READ maxGuestRes WRITE setMaxGuestRes)
     66    Q_PROPERTY (QString remapScancodes READ remapScancodes WRITE setRemapScancodes)
    6567    Q_PROPERTY (bool trayIconEnabled READ trayIconEnabled WRITE setTrayIconEnabled)
    6668    Q_PROPERTY (bool dockPreviewEnabled READ dockPreviewEnabled WRITE setDockPreviewEnabled)
     
    106108        mData()->maxGuestRes = aMaxGuestRes;
    107109    }
     110
     111    QString remapScancodes() const { return data()->remapScancodes; }
     112    void setRemapScancodes (const QString &aRemapScancodes)
     113    {
     114        mData()->remapScancodes = aRemapScancodes;
     115    }
     116
    108117
    109118    bool trayIconEnabled() const { return data()->trayIconEnabled; }
  • trunk/src/VBox/Frontends/VirtualBox/include/XKeyboard.h

    r8155 r21711  
    2424#define __XKeyboard_h__
    2525
     26#include <QString>
     27
    2628// initialize the X keyboard subsystem
    27 bool initXKeyboard(Display *dpy);
     29void initMappedX11Keyboard(Display *pDisplay, QString remapScancodes);
    2830// our custom keyboard handler
    2931unsigned handleXKeyEvent(XEvent *event);
  • trunk/src/VBox/Frontends/VirtualBox/src/QIHotKeyEdit.cpp

    r19066 r21711  
    2323#include "QIHotKeyEdit.h"
    2424#include "VBoxDefs.h"
     25#include "VBoxGlobal.h"
    2526
    2627/* Qt includes */
     
    119120#ifdef Q_WS_X11
    120121    /* Initialize the X keyboard subsystem */
    121     initXKeyboard (QX11Info::display());
     122    initMappedX11Keyboard(QX11Info::display(),
     123            vboxGlobal().settings().publicProperty ("GUI/RemapScancodes"));
    122124#endif
    123125
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r21520 r21711  
    797797#ifdef Q_WS_X11
    798798    /* initialize the X keyboard subsystem */
    799     initXKeyboard (QX11Info::display());
     799    initMappedX11Keyboard(QX11Info::display(),
     800            vboxGlobal().settings().publicProperty ("GUI/RemapScancodes"));
    800801#endif
    801802
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobalSettings.cpp

    r20977 r21711  
    6060    languageId  = QString::null;
    6161    maxGuestRes = "auto";
     62    remapScancodes = QString::null;
    6263    trayIconEnabled = false;
    6364    dockPreviewEnabled = true;
     
    7172    languageId  = that.languageId;
    7273    maxGuestRes = that.maxGuestRes;
     74    remapScancodes = that.remapScancodes;
    7375    trayIconEnabled = that.trayIconEnabled;
    7476    dockPreviewEnabled = that.dockPreviewEnabled;
     
    8789         languageId  == that.languageId &&
    8890         maxGuestRes == that.maxGuestRes &&
     91         remapScancodes == that.remapScancodes &&
    8992         trayIconEnabled == that.trayIconEnabled
    9093         && dockPreviewEnabled == that.dockPreviewEnabled
     
    115118    { "GUI/LanguageID",                            "languageId",         gVBoxLangIDRegExp, true },
    116119    { "GUI/MaxGuestResolution",                    "maxGuestRes",        "\\d*[1-9]\\d*,\\d*[1-9]\\d*|any|auto", true },
     120    { "GUI/RemapScancodes",                        "remapScancodes",     "(\\d+=\\d+,)*\\d+=\\d+", true },
    117121    { "GUI/TrayIcon/Enabled",                      "trayIconEnabled",    "true|false", true },
    118122#ifdef Q_WS_MAC
  • trunk/src/VBox/Frontends/VirtualBox/src/X11/XKeyboard-new.cpp

    r12500 r21711  
    2323#define LOG_GROUP LOG_GROUP_GUI
    2424
     25#include <QString>
     26#include <QStringList>
    2527#include <X11/Xlib.h>
    2628#include <X11/keysym.h>
     
    187189 * mappings.
    188190 */
    189 bool initXKeyboard(Display *dpy)
    190 {
    191     X11DRV_InitKeyboard(dpy, &gfByLayoutOK, &gfByTypeOK);
     191bool initXKeyboard(Display *dpy, int (*remapScancodes)[2])
     192{
     193    X11DRV_InitKeyboard(dpy, &gfByLayoutOK, &gfByTypeOK, remapScancodes);
    192194    /* It will almost always work to some extent */
    193195    return true;
     
    203205    if ((1 == gfByLayoutOK) && (gfByTypeOK != 1))
    204206        dumpType(dpy);
    205     if ((gfByLayoutOK != 1) && (gfByTypeOK != 1))
     207    if ((gfByLayoutOK != 1) && (gfByTypeOK != 1)) {
    206208        LogRel(("Failed to recognize the keyboard mapping or to guess it based on\n"
    207209                "the keyboard layout.  It is very likely that some keys will not\n"
     
    210212                "about your keyboard type, its layout and other relevant\n"
    211213                "information such as whether you are using a remote X server or\n"
    212                 "something similar.\n"));
     214                "something similar. \n"));
     215        unsigned *keyc2scan=X11DRV_getKeyc2scan();
     216
     217        LogRel(("The keycode-to-scancode table is: %d=%d",0,keyc2scan[0]));
     218        for(int i=1; i<256; i++)
     219            LogRel((",%d=%d",i,keyc2scan[i]));
     220        LogRel(("\n"));
     221    }
    213222}
    214223
     
    234243    return 8;
    235244}
     245
     246/**
     247 * Initialize X11 keyboard including the remapping specified in the
     248 * global property GUI/RemapScancodes. This property is a string of
     249 * comma-seperated x=y pairs, where x is the X11 keycode and y is the
     250 * keyboard scancode that is emitted when the key attached to the X11
     251 * keycode is pressed.
     252 */
     253void initMappedX11Keyboard(Display *pDisplay, QString remapScancodes)
     254{
     255    int (*scancodes)[2] = NULL;
     256    int (*scancodesTail)[2] = NULL;
     257
     258    if(remapScancodes != QString::null) {
     259        QStringList tuples = remapScancodes.split(",", QString::SkipEmptyParts);
     260        scancodes = scancodesTail = new int [tuples.size()+1][2];
     261        for (int i = 0; i < tuples.size(); ++i) {
     262            QStringList keyc2scan = tuples.at(i).split("=");
     263            (*scancodesTail)[0] = keyc2scan.at(0).toUInt();
     264            (*scancodesTail)[1] = keyc2scan.at(1).toUInt();
     265            /* Do not advance on (ignore) identity mappings as this is
     266               the stop signal to initXKeyboard and friends */
     267            if((*scancodesTail)[0] != (*scancodesTail)[1])
     268                scancodesTail++;
     269        }
     270        (*scancodesTail)[0] = (*scancodesTail)[1] = 0;
     271    }
     272    /* initialize the X keyboard subsystem */
     273    initXKeyboard (pDisplay ,scancodes);
     274
     275    if(scancodes) delete scancodes;
     276}
  • trunk/src/VBox/Frontends/VirtualBox/src/X11/keyboard-new.c

    r16459 r21711  
    5555#include <stdio.h>
    5656
     57#define KEYC2SCAN_SIZE 256
     58
    5759/**
    5860 * Array containing the current mapping of keycodes to scan codes, detected
    5961 * using the keyboard layout algorithm in X11DRV_InitKeyboardByLayout.
    6062 */
    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;
     63static unsigned keyc2scan[KEYC2SCAN_SIZE];
    6964/** Whether to output basic debugging information to standard output */
    7065static int log_kb_1 = 0;
     
    126121    }
    127122    if (keysym != 0 && scan == 0)
    128     {
    129         if (use_builtin_table != 0)
    130             scan = main_keyboard_type_scans[builtin_table_number][code];
    131         else
    132123            scan = keyc2scan[code];
    133     }
     124
    134125    return scan;
    135126}
     
    440431           )
    441432            found = 1;
    442     use_builtin_table = found;
    443433    if (found != 0)
    444         builtin_table_number = i - 1;
     434        memcpy(keyc2scan, main_keyboard_type_scans[i - 1], KEYC2SCAN_SIZE);
    445435    return found;
    446436}
     
    464454 * @returns 1 if the layout found was optimal, 0 if it was not.  This is
    465455 *          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
    471  */
    472 unsigned X11DRV_InitKeyboard(Display *display, unsigned *byLayoutOK, unsigned *byTypeOK)
    473 {
    474     unsigned byLayout = X11DRV_InitKeyboardByLayout(display);
    475     unsigned byType   = X11DRV_InitKeyboardByType(display);
     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)
     463 */
     464unsigned X11DRV_InitKeyboard(Display *display, unsigned *byLayoutOK, unsigned *byTypeOK, int (*remapScancodes)[2])
     465{
     466    unsigned byLayout;
     467    unsigned byType;
     468
     469    byLayout = X11DRV_InitKeyboardByLayout(display);
    476470    *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
    478481    return (byLayout || byType) ? 1 : 0;
    479482}
     483
     484/**
     485 * Returns the keycode to scancode array
     486 */
     487unsigned *X11DRV_getKeyc2scan()
     488{
     489    return keyc2scan;
     490}
  • trunk/src/VBox/Frontends/VirtualBox/src/X11/keyboard.h

    r12498 r21711  
    4444#endif
    4545#ifdef VBOX_HAVE_VISIBILITY_HIDDEN
    46 extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK);
     46extern CCALL __attribute__((visibility("default"))) unsigned *X11DRV_getKeyc2scan();
     47extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK, int (*remapScancodes)[2]);
    4748extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_KeyEvent(Display *dpy, KeyCode code);
    4849#else
    49 extern CCALL unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK);
     50extern CCALL unsigned *X11DRV_getKeyc2scan();
     51extern CCALL unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK, int (*remapScancodes)[2]);
    5052extern CCALL unsigned X11DRV_KeyEvent(Display *dpy, KeyCode code);
    5153#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette