VirtualBox

Changeset 32874 in vbox for trunk/src/VBox/Frontends/Common


Ignore:
Timestamp:
Oct 1, 2010 4:50:10 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
66352
Message:

FE/Common/VBoxKeyboard: try to use XKB to determine the keyboard layout as well, and by default

Location:
trunk/src/VBox/Frontends/Common/VBoxKeyboard
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/Common/VBoxKeyboard/keyboard-tables.h

    r30787 r32874  
    237237};
    238238
     239#include "xkbtoscan.h"
     240
    239241#endif /* !___VBox_keyboard_tables_h */
    240242
  • trunk/src/VBox/Frontends/Common/VBoxKeyboard/keyboard.c

    r30787 r32874  
    4242#include <X11/Xatom.h>
    4343#include <X11/keysym.h>
     44#include <X11/XKBlib.h>
    4445#include <X11/Xlib.h>
    4546#include <X11/Xresource.h>
     
    545546
    546547/**
     548 * Checks for the XKB extension, and if it is found initialises the X11 keycode
     549 * to XT scan code mapping by looking at the XKB names for each keycode.
     550 */
     551static unsigned
     552X11DRV_InitKeyboardByXkb(Display *pDisplay)
     553{
     554    int major = XkbMajorVersion, minor = XkbMinorVersion;
     555    XkbDescPtr pKBDesc;
     556    if (!XkbLibraryVersion(&major, &minor))
     557        return 0;
     558    if (!XkbQueryExtension(pDisplay, NULL, NULL, &major, &minor, NULL))
     559        return 0;
     560    pKBDesc = XkbGetKeyboard(pDisplay, XkbAllComponentsMask, XkbUseCoreKbd);
     561    if (!pKBDesc)
     562        return 0;
     563    if (XkbGetNames(pDisplay, XkbKeyNamesMask, pKBDesc) != Success)
     564        return 0;
     565    {
     566        unsigned i, j;
     567
     568        memset(keyc2scan, 0, sizeof(keyc2scan));
     569        for (i = pKBDesc->min_key_code; i < pKBDesc->max_key_code; ++i)
     570            for (j = 0; j < sizeof(xkbMap) / sizeof(xkbMap[0]); ++j)
     571                if (!memcmp(xkbMap[j].cszName,
     572                            &pKBDesc->names->keys->name[i * XKB_NAME_SIZE],
     573                            XKB_NAME_SIZE))
     574                {
     575                    keyc2scan[i] = xkbMap[j].uScan;
     576                    break;
     577                }
     578    }
     579    XkbFreeNames(pKBDesc, XkbKeyNamesMask, True);
     580    XkbFreeKeyboard(pKBDesc, XkbAllComponentsMask, True);
     581    return 1;
     582}
     583
     584/**
    547585 * Initialise the X11 keyboard driver by finding which X11 keycodes correspond
    548586 * to which PC scan codes.  If the keyboard being used is not a PC keyboard,
     
    567605 * @param   byTypeOK         diagnostic - set to one if detection by type
    568606 *                           succeeded, and to 0 otherwise
     607 * @param   byXkbOK          diagnostic - set to one if detection using XKB
     608 *                           succeeded, and to 0 otherwise
    569609 * @param   remapScancode    array of tuples that remap the keycode (first
    570610 *                           part) to a scancode (second part)
    571611 */
    572 unsigned X11DRV_InitKeyboard(Display *display, unsigned *byLayoutOK, unsigned *byTypeOK, int (*remapScancodes)[2])
    573 {
    574     unsigned byLayout;
    575     unsigned byType;
     612unsigned X11DRV_InitKeyboard(Display *display, unsigned *byLayoutOK,
     613                             unsigned *byTypeOK, unsigned *byXkbOK,
     614                             int (*remapScancodes)[2])
     615{
     616    unsigned byLayout, byType, byXkb;
    576617
    577618    byLayout = X11DRV_InitKeyboardByLayout(display);
     
    582623    if (byTypeOK)
    583624        *byTypeOK = byType;
     625
     626    byXkb = X11DRV_InitKeyboardByXkb(display);
     627    if (byXkbOK)
     628        *byXkbOK = byXkb;
    584629
    585630    /* Remap keycodes after initialization. Remapping stops after an
Note: See TracChangeset for help on using the changeset viewer.

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