VirtualBox

Changeset 12495 in vbox for trunk/src


Ignore:
Timestamp:
Sep 16, 2008 3:43:14 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt: X11 keyboard: look up keys which don't change in different layouts on the fly

Location:
trunk/src/VBox/Frontends/VirtualBox4/src/linux
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/src/linux/XKeyboard-new.cpp

    r9991 r12495  
    9292    XDisplayKeycodes(display, &minKey, &maxKey);
    9393    for (int i = minKey; i < maxKey; ++i)
    94         scanToKeycode[X11DRV_KeyEvent(i)] = i;
     94        scanToKeycode[X11DRV_KeyEvent(display, i)] = i;
    9595    LogRel(("\""));
    9696    printKey(display, scanToKeycode[0x29]); /* `~ */
     
    149149    for (unsigned i = 0; i < 256; ++i)
    150150    {
    151         LogRel(("0x%x", X11DRV_KeyEvent(i)));
     151        LogRel(("0x%x", X11DRV_KeyEvent(display, i)));
    152152        if (i < 255)
    153153            LogRel((", "));
     
    218218{
    219219    // call the WINE event handler
    220     return X11DRV_KeyEvent(event->xkey.keycode);
     220    return X11DRV_KeyEvent(event->xkey.display, event->xkey.keycode);
    221221}
    222222
  • trunk/src/VBox/Frontends/VirtualBox4/src/linux/keyboard-new.c

    r12410 r12495  
    9595
    9696/**
    97   * Translate a keycode in a key event to a scan code, using the lookup table
    98   * which we constructed earlier or a well-known mapping from our mapping
    99   * table.
     97  * Translate a keycode in a key event to a scan code.  If the keycode maps
     98  * to a key symbol which is in the same place on all PC keyboards, look it
     99  * up by symbol in one of our hard-coded translation tables.  It it maps to
     100  * a symbol which can be in a different place on different PC keyboards, look
     101  * it up by keycode using either the lookup table which we constructed
     102  * earlier, or using a hard-coded table if we know what type of keyboard is
     103  * in use.
    100104  *
    101105  * @returns the scan code number, with 0x100 added for extended scan codes
     
    103107  */
    104108
    105 unsigned X11DRV_KeyEvent(KeyCode code)
     109unsigned X11DRV_KeyEvent(Display *display, KeyCode code)
    106110{
    107     unsigned key;
    108     if (use_builtin_table != 0)
    109         key = main_keyboard_type_scans[builtin_table_number][code];
    110     else
    111         key = keyc2scan[code];
    112     return key;
     111    unsigned scan;
     112    KeySym keysym = XKeycodeToKeysym(display, code, 0);
     113    scan = 0;
     114    if (keysym)  /* otherwise, keycode not used */
     115    {
     116        if ((keysym >> 8) == 0xFF)          /* non-character key */
     117            scan = nonchar_key_scan[keysym & 0xff];
     118        else if ((keysym >> 8) == 0x1008FF) /* XFree86 vendor keys */
     119            scan = xfree86_vendor_key_scan[keysym & 0xff];
     120        else if ((keysym >> 8) == 0x1005FF) /* Sun keys */
     121            scan = sun_key_scan[keysym & 0xff];
     122        else if (keysym == 0x20)            /* Spacebar */
     123            scan = 0x39;
     124        else if (keysym == 0xFE03)          /* ISO level3 shift, aka AltGr */
     125            scan = 0x138;
     126        else if (use_builtin_table != 0)
     127            scan = main_keyboard_type_scans[builtin_table_number][code];
     128        else
     129            scan = keyc2scan[code];
     130    }
     131    return scan;
    113132}
    114133
     
    304323        if (keysym)  /* otherwise, keycode not used */
    305324        {
    306             if ((keysym >> 8) == 0xFF)         /* non-character key */
    307             {
    308                 scan = nonchar_key_scan[keysym & 0xff];
    309                 /* set extended bit when necessary */
    310             } else if ((keysym >> 8) == 0x1008FF) { /* XFree86 vendor keys */
    311 /* VirtualBox FIX - multimedia/internet keys */
    312                 scan = xfree86_vendor_key_scan[keysym & 0xff];
    313             } else if ((keysym >> 8) == 0x1005FF) { /* Sun keys */
    314                 scan = sun_key_scan[keysym & 0xff];
    315             } else if (keysym == 0x20) {                 /* Spacebar */
    316                 scan = 0x39;
    317 /* VirtualBox FIX - AltGr support */
    318             } else if (keysym == 0xFE03) {               /* ISO level3 shift, aka AltGr */
    319                 scan = 0x138;
    320             } else {
     325          /* Skip over keysyms which we look up on the fly */
     326          if (   (0xFF != (keysym >> 8))     /* Non-character key */
     327              && (0x1008FF != (keysym >> 8)) /* XFree86 vendor keys */
     328              && (0x1005FF != (keysym >> 8)) /* Sun keys */
     329              && (0x20 != keysym)            /* Spacebar */
     330              && (0xFE03 != keysym)          /* ISO level3 shift, aka AltGr */
     331             ) {
    321332              unsigned found = 0;
    322333
     
    335346                /* got it */
    336347                scan = main_key_scan[keyn - 1];
    337                 if (keyn != 48) /* don't count the 102nd key */
     348                /* We keep track of the number of keys that we found a
     349                 * match for to see if the layout is optimal or not.
     350                 * We ignore the 102nd key though (key number 48), since
     351                 * not all keyboards have it. */
     352                if (keyn != 48)
    338353                    ++matches;
    339354              }
  • trunk/src/VBox/Frontends/VirtualBox4/src/linux/keyboard.h

    r11982 r12495  
    4545#ifdef VBOX_HAVE_VISIBILITY_HIDDEN
    4646extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK);
    47 extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_KeyEvent(KeyCode code);
     47extern CCALL __attribute__((visibility("default"))) unsigned X11DRV_KeyEvent(Display *dpy, KeyCode code);
    4848#else
    4949extern CCALL unsigned X11DRV_InitKeyboard(Display *dpy, unsigned *byLayoutOK, unsigned *byTypeOK);
    50 extern CCALL unsigned X11DRV_KeyEvent(KeyCode code);
     50extern CCALL unsigned X11DRV_KeyEvent(Display *dpy, KeyCode code);
    5151#endif
    5252
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