⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qkeymapper_x11.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    // translate the key again using each permutation of consumedModifiers    for (int i = 1; i < numPerms; ++i) {        uint val = 0;        for (int j = 0; j < num1Bits; ++j) {            if (i & (1 << j))                val |= (1 << pos1Bits[j]);        }        if ((xmodifiers & val) != val)            continue;        KeySym sym;        uint mods;        if (!qt_XTranslateKey(&coreDesc, xkeycode, val, &mods, &sym))            continue;        // translate sym -> code        Qt::KeyboardModifiers modifiers = 0;        int code = -1;        chars.clear();        count = 0;        // mask out the modifiers needed to translate keycode        text = translateKeySym(sym, xmodifiers & ~val, code, modifiers, chars, count);        if (code == -1) {            if (text.isEmpty())                continue;            code = text.at(0).unicode();        }        if (code && code < 0xfffe)            code = QChar(code).toUpper().unicode();        if (code == baseCode)            continue;        result += (code | modifiers);    }#if 0    qDebug() << "possibleKeysCore()" << hex << result;#endif    return result;}// for parsing the _XKB_RULES_NAMES propertyenum {    RulesFileIndex = 0,    ModelIndex = 1,    LayoutIndex = 2,    VariantIndex = 3,    OptionsIndex = 4};void QKeyMapperPrivate::clearMappings(){#ifndef QT_NO_XKB    if (useXKB) {        // try to determine the layout name and input direction by reading the _XKB_RULES_NAMES property off        // the root window        QByteArray layoutName;        QByteArray variantName;        Atom type = XNone;        int format = 0;        ulong nitems = 0;        ulong bytesAfter = 0;        uchar *data = 0;        if (XGetWindowProperty(X11->display, RootWindow(X11->display, 0), ATOM(_XKB_RULES_NAMES), 0, 1024,                               false, XA_STRING, &type, &format, &nitems, &bytesAfter, &data) == Success            && type == XA_STRING && format == 8 && nitems > 2) {            /*              index 0 == rules file name              index 1 == model name              index 2 == layout name              index 3 == variant name              index 4 == options            */            char *names[5] = { 0, 0, 0, 0, 0 };            char *p = reinterpret_cast<char *>(data), *end = p + nitems;            int i = 0;            do {                names[i++] = p;                p += qstrlen(p) + 1;            } while (p < end);            layoutName = QByteArray::fromRawData(names[2], qstrlen(names[2]));            variantName = QByteArray::fromRawData(names[3], qstrlen(names[3]));        }        // ### ???        // if (keyboardLayoutName.isEmpty())        //     qWarning("Qt: unable to determine keyboard layout, please talk to qt-bugs@trolltech.com"); ?        getLocaleAndDirection(&keyboardInputLocale,                              &keyboardInputDirection,                              layoutName,                              variantName);#if 0        qDebug() << "keyboard input locale ="                 << keyboardInputLocale.name()                 << "direction ="                 << keyboardInputDirection;#endif        if (data)            XFree(data);    } else#endif // QT_NO_XKB        {            if (coreDesc.keysyms)                XFree(coreDesc.keysyms);            coreDesc.min_keycode = 8;            coreDesc.max_keycode = 255;            XDisplayKeycodes(X11->display, &coreDesc.min_keycode, &coreDesc.max_keycode);            coreDesc.keysyms_per_keycode = 0;            coreDesc.keysyms = XGetKeyboardMapping(X11->display,                                                   coreDesc.min_keycode,                                                   coreDesc.max_keycode - coreDesc.min_keycode,                                                   &coreDesc.keysyms_per_keycode);#if 0            qDebug() << "min_keycode =" << coreDesc.min_keycode;            qDebug() << "max_keycode =" << coreDesc.max_keycode;            qDebug() << "keysyms_per_keycode =" << coreDesc.keysyms_per_keycode;            qDebug() << "keysyms =" << coreDesc.keysyms;#endif            // ### cannot get/guess the locale with the core protocol            keyboardInputLocale = QLocale::c();            // ### could examine group 0 for RTL keys            keyboardInputDirection = Qt::LeftToRight;        }    // set default modifier masks    qt_alt_mask = Mod1Mask;    qt_meta_mask = Mod4Mask;    qt_super_mask = 0;    qt_hyper_mask = 0;    qt_mode_switch_mask = 0;    // look at the modifier mapping, and get the correct masks for alt, meta, super, hyper, and mode_switch#ifndef QT_NO_XKB    if (useXKB) {        XkbDescPtr xkbDesc = XkbGetMap(X11->display, XkbAllClientInfoMask, XkbUseCoreKbd);        for (int i = xkbDesc->min_key_code; i < xkbDesc->max_key_code; ++i) {            const uint mask = xkbDesc->map->modmap ? xkbDesc->map->modmap[i] : 0;            if (mask == 0) {                // key is not bound to a modifier                continue;            }            for (int j = 0; j < XkbKeyGroupsWidth(xkbDesc, i); ++j) {                KeySym keySym = XkbKeySym(xkbDesc, i, j);                if (keySym == NoSymbol)                    continue;                SETMASK(keySym, mask);            }        }        XkbFreeKeyboard(xkbDesc, XkbAllComponentsMask, true);    } else#endif // QT_NO_XKB        {            coreDesc.lock_meaning = NoSymbol;            XModifierKeymap *map = XGetModifierMapping(X11->display);            if (map) {                int i, maskIndex = 0, mapIndex = 0;                for (maskIndex = 0; maskIndex < 8; maskIndex++) {                    for (i = 0; i < map->max_keypermod; i++) {                        if (map->modifiermap[mapIndex]) {                            KeySym sym;                            int x = 0;                            do {                                sym = XKeycodeToKeysym(X11->display, map->modifiermap[mapIndex], x++);                            } while (sym == NoSymbol && x < coreDesc.keysyms_per_keycode);                            const uchar mask = 1 << maskIndex;                            SETMASK(sym, mask);                        }                        mapIndex++;                    }                }                // determine the meaning of the Lock modifier                for (i = 0; i < map->max_keypermod; ++i) {                    for (int x = 0; x < coreDesc.keysyms_per_keycode; ++x) {                        KeySym sym = XKeycodeToKeysym(X11->display, map->modifiermap[LockMapIndex], x);                        if (sym == XK_Caps_Lock || sym == XK_ISO_Lock) {                            coreDesc.lock_meaning = XK_Caps_Lock;                            break;                        } else if (sym == XK_Shift_Lock) {                            coreDesc.lock_meaning = XK_Shift_Lock;                        }                    }                }                XFreeModifiermap(map);            }            // for qt_XTranslateKey()            coreDesc.num_lock = qt_num_lock_mask;            coreDesc.mode_switch = qt_mode_switch_mask;#if 0            qDebug() << "lock_meaning =" << coreDesc.lock_meaning;            qDebug() << "num_lock =" << coreDesc.num_lock;            qDebug() << "mode_switch =" << coreDesc.mode_switch;#endif        }    // if we don't have a meta key (or it's hidden behind alt), use super or hyper to generate    // Qt::Key_Meta and Qt::MetaModifier, since most newer XFree86/Xorg installations map the Windows    // key to Super    if (qt_meta_mask == 0 || qt_meta_mask == qt_alt_mask) {        // no meta keys... s,meta,super,        qt_meta_mask = qt_super_mask;        if (qt_meta_mask == 0 || qt_meta_mask == qt_alt_mask) {            // no super keys either? guess we'll use hyper then            qt_meta_mask = qt_hyper_mask;        }    }#if 0    qDebug() << "qt_alt_mask =" << hex << qt_alt_mask;    qDebug() << "qt_meta_mask =" << hex << qt_meta_mask;    qDebug() << "qt_super_mask =" << hex << qt_super_mask;    qDebug() << "qt_hyper_mask =" << hex << qt_hyper_mask;    qDebug() << "qt_mode_switch_mask =" << hex << qt_mode_switch_mask;    qDebug() << "qt_num_lock_mask =" << hex << qt_num_lock_mask;#endif}extern bool qt_sm_blockUserInput;//// Keyboard event translation//#ifndef XK_ISO_Left_Tab#define XK_ISO_Left_Tab         0xFE20#endif#ifndef XK_dead_hook#define XK_dead_hook            0xFE61#endif#ifndef XK_dead_horn#define XK_dead_horn            0xFE62#endif#ifndef XK_Codeinput#define XK_Codeinput            0xFF37#endif#ifndef XK_Kanji_Bangou#define XK_Kanji_Bangou         0xFF37 /* same as codeinput */#endif// Fix old X libraries#ifndef XK_KP_Home#define XK_KP_Home              0xFF95#endif#ifndef XK_KP_Left#define XK_KP_Left              0xFF96#endif#ifndef XK_KP_Up#define XK_KP_Up                0xFF97#endif#ifndef XK_KP_Right#define XK_KP_Right             0xFF98#endif#ifndef XK_KP_Down#define XK_KP_Down              0xFF99#endif#ifndef XK_KP_Prior#define XK_KP_Prior             0xFF9A#endif#ifndef XK_KP_Next#define XK_KP_Next              0xFF9B#endif#ifndef XK_KP_End#define XK_KP_End               0xFF9C#endif#ifndef XK_KP_Insert#define XK_KP_Insert            0xFF9E#endif#ifndef XK_KP_Delete#define XK_KP_Delete            0xFF9F#endif// the next lines are taken from XFree > 4.0 (X11/XF86keysyms.h), defining some special// multimedia keys. They are included here as not every system has them.#define XF86XK_Standby          0x1008FF10#define XF86XK_AudioLowerVolume 0x1008FF11#define XF86XK_AudioMute        0x1008FF12#define XF86XK_AudioRaiseVolume 0x1008FF13#define XF86XK_AudioPlay        0x1008FF14#define XF86XK_AudioStop        0x1008FF15#define XF86XK_AudioPrev        0x1008FF16#define XF86XK_AudioNext        0x1008FF17#define XF86XK_HomePage         0x1008FF18#define XF86XK_Calculator       0x1008FF1D#define XF86XK_Mail             0x1008FF19#define XF86XK_Start            0x1008FF1A#define XF86XK_Search           0x1008FF1B#define XF86XK_AudioRecord      0x1008FF1C#define XF86XK_Back             0x1008FF26#define XF86XK_Forward          0x1008FF27#define XF86XK_Stop             0x1008FF28#define XF86XK_Refresh          0x1008FF29#define XF86XK_Favorites        0x1008FF30#define XF86XK_AudioPause       0x1008FF31#define XF86XK_AudioMedia       0x1008FF32#define XF86XK_MyComputer       0x1008FF33#define XF86XK_OpenURL          0x1008FF38#define XF86XK_Launch0          0x1008FF40#define XF86XK_Launch1          0x1008FF41#define XF86XK_Launch2          0x1008FF42#define XF86XK_Launch3          0x1008FF43#define XF86XK_Launch4          0x1008FF44#define XF86XK_Launch5          0x1008FF45#define XF86XK_Launch6          0x1008FF46#define XF86XK_Launch7          0x1008FF47#define XF86XK_Launch8          0x1008FF48#define XF86XK_Launch9          0x1008FF49#define XF86XK_LaunchA          0x1008FF4A#define XF86XK_LaunchB          0x1008FF4B#define XF86XK_LaunchC          0x1008FF4C#define XF86XK_LaunchD          0x1008FF4D#define XF86XK_LaunchE          0x1008FF4E#define XF86XK_LaunchF          0x1008FF4F// end of XF86keysyms.h// keyboard mapping tablestatic const unsigned int KeyTbl[] = {    // misc keys    XK_Escape,                  Qt::Key_Escape,    XK_Tab,                     Qt::Key_Tab,    XK_ISO_Left_Tab,            Qt::Key_Backtab,    XK_BackSpace,               Qt::Key_Backspace,    XK_Return,                  Qt::Key_Return,    XK_Insert,                  Qt::Key_Insert,    XK_Delete,                  Qt::Key_Delete,    XK_Clear,                   Qt::Key_Delete,    XK_Pause,                   Qt::Key_Pause,    XK_Print,                   Qt::Key_Print,    0x1005FF60,                 Qt::Key_SysReq,         // hardcoded Sun SysReq    0x1007ff00,                 Qt::Key_SysReq,         // hardcoded X386 SysReq    // cursor movement    XK_Home,                    Qt::Key_Home,    XK_End,                     Qt::Key_End,    XK_Left,                    Qt::Key_Left,    XK_Up,                      Qt::Key_Up,    XK_Right,                   Qt::Key_Right,    XK_Down,                    Qt::Key_Down,    XK_Prior,                   Qt::Key_PageUp,    XK_Next,                    Qt::Key_PageDown,    // modifiers    XK_Shift_L,                 Qt::Key_Shift,    XK_Shift_R,                 Qt::Key_Shift,    XK_Shift_Lock,              Qt::Key_Shift,    XK_Control_L,               Qt::Key_Control,    XK_Control_R,               Qt::Key_Control,    XK_Meta_L,                  Qt::Key_Meta,    XK_Meta_R,                  Qt::Key_Meta,    XK_Alt_L,                   Qt::Key_Alt,    XK_Alt_R,                   Qt::Key_Alt,    XK_Caps_Lock,               Qt::Key_CapsLock,    XK_Num_Lock,                Qt::Key_NumLock,    XK_Scroll_Lock,             Qt::Key_ScrollLock,    XK_Super_L,                 Qt::Key_Super_L,    XK_Super_R,                 Qt::Key_Super_R,    XK_Menu,                    Qt::Key_Menu,    XK_Hyper_L,                 Qt::Key_Hyper_L,    XK_Hyper_R,                 Qt::Key_Hyper_R,    XK_Help,                    Qt::Key_Help,    0x1000FF74,                 Qt::Key_Backtab,        // hardcoded HP backtab    0x1005FF10,                 Qt::Key_F11,            // hardcoded Sun F36 (labeled F11)    0x1005FF11,                 Qt::Key_F12,            // hardcoded Sun F37 (labeled F12)    // numeric and function keypad keys    XK_KP_Space,                Qt::Key_Space,    XK_KP_Tab,                  Qt::Key_Tab,    XK_KP_Enter,                Qt::Key_Enter,    //XK_KP_F1,                 Qt::Key_F1,    //XK_KP_F2,                 Qt::Key_F2,    //XK_KP_F3,                 Qt::Key_F3,    //XK_KP_F4,                 Qt::Key_F4,    XK_KP_Home,                 Qt::Key_Home,    XK_KP_Left,                 Qt::Key_Left,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -