📄 qapplication_x11.cpp
字号:
if (qt_is_gui_used) { X11->defaultScreen = DefaultScreen(X11->display); X11->screenCount = ScreenCount(X11->display); X11->screens = new QX11InfoData[X11->screenCount]; for (int s = 0; s < X11->screenCount; s++) { QX11InfoData *screen = X11->screens + s; screen->ref = 1; // ensures it doesn't get deleted screen->screen = s; screen->dpiX = (DisplayWidth(X11->display, s) * 254 + DisplayWidthMM(X11->display, s)*5) / (DisplayWidthMM(X11->display, s)*10); screen->dpiY = (DisplayHeight(X11->display, s) * 254 + DisplayHeightMM(X11->display, s)*5) / (DisplayHeightMM(X11->display, s)*10); } QColormap::initialize(); // Support protocols X11->xdndSetup(); // Finally create all atoms qt_x11_create_intern_atoms(); // look for broken window managers qt_detect_broken_window_manager(); // initialize NET lists qt_get_net_supported(); qt_get_net_virtual_roots();#ifndef QT_NO_XRANDR // See if XRandR is supported on the connected display if (XQueryExtension(X11->display, "RANDR", &X11->xrandr_major, &X11->xrandr_eventbase, &X11->xrandr_errorbase) && XRRQueryExtension(X11->display, &X11->xrandr_eventbase, &X11->xrandr_errorbase)) { // XRandR is supported X11->use_xrandr = true; }#endif // QT_NO_XRANDR#ifndef QT_NO_XRENDER // See if XRender is supported on the connected display if (XQueryExtension(X11->display, "RENDER", &X11->xrender_major, &X11->xrender_eventbase, &X11->xrender_errorbase) && XRenderQueryExtension(X11->display, &X11->xrender_eventbase, &X11->xrender_errorbase)) { // XRender is supported, let's see if we have a PictFormat for the // default visual XRenderPictFormat *format = XRenderFindVisualFormat(X11->display, (Visual *) QX11Info::appVisual(X11->defaultScreen)); // Check the version as well - we need v0.4 or higher int major = 0; int minor = 0; XRenderQueryVersion(X11->display, &major, &minor); if (qgetenv("QT_X11_NO_XRENDER").isNull()) X11->use_xrender = (major >= 0 && minor >= 5) && (format != 0); }#endif // QT_NO_XRENDER#ifndef QT_NO_XKB // If XKB is detected, set the GrabsUseXKBState option so input method // compositions continue to work (ie. deadkeys) unsigned int state = XkbPCF_GrabsUseXKBStateMask; (void) XkbSetPerClientControls(X11->display, state, &state);#endif X11->has_fontconfig = false;#if !defined(QT_NO_FONTCONFIG) if (qgetenv("QT_X11_NO_FONTCONFIG").isNull()) X11->has_fontconfig = FcInit(); int dpi = 0; getXDefault("Xft", FC_DPI, &dpi); if (dpi) { for (int s = 0; s < ScreenCount(X11->display); ++s) { QX11Info::setAppDpiX(s, dpi); QX11Info::setAppDpiY(s, dpi); } } X11->fc_scale = 1.; getXDefault("Xft", FC_SCALE, &X11->fc_scale); for (int s = 0; s < ScreenCount(X11->display); ++s) { int subpixel = FC_RGBA_UNKNOWN;#if RENDER_MAJOR > 0 || RENDER_MINOR >= 6 if (X11->use_xrender) { int rsp = XRenderQuerySubpixelOrder(X11->display, s); switch (rsp) { default: case SubPixelUnknown: subpixel = FC_RGBA_UNKNOWN; break; case SubPixelHorizontalRGB: subpixel = FC_RGBA_RGB; break; case SubPixelHorizontalBGR: subpixel = FC_RGBA_BGR; break; case SubPixelVerticalRGB: subpixel = FC_RGBA_VRGB; break; case SubPixelVerticalBGR: subpixel = FC_RGBA_VBGR; break; case SubPixelNone: subpixel = FC_RGBA_NONE; break; } }#endif getXDefault("Xft", FC_RGBA, &subpixel); X11->screens[s].subpixel = subpixel; } X11->fc_antialias = true; getXDefault("Xft", FC_ANTIALIAS, &X11->fc_antialias);#ifdef FC_HINT_STYLE getXDefault("Xft", FC_HINT_STYLE, &X11->fc_hint_style);#endif#if 0 // ###### these are implemented by Xft, not sure we need them getXDefault("Xft", FC_AUTOHINT, &X11->fc_autohint); getXDefault("Xft", FC_HINTING, &X11->fc_autohint); getXDefault("Xft", FC_MINSPACE, &X11->fc_autohint);#endif#endif // QT_NO_XRENDER // look at the modifier mapping, and get the correct masks for alt/meta // find the alt/meta masks XModifierKeymap *map = XGetModifierMapping(X11->display); // get the first and last keycode int first_keycode = 8, last_keycode = 255; XDisplayKeycodes(X11->display, &first_keycode, &last_keycode); // only need keysyms_per_keycode int keysyms_per_keycode = 1; KeySym *keys = XGetKeyboardMapping(X11->display, first_keycode, last_keycode - first_keycode, &keysyms_per_keycode); if (keys) XFree(keys); 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 < keysyms_per_keycode); const long mask = 1 << maskIndex; if (qt_alt_mask == 0 && qt_meta_mask != mask && qt_super_mask != mask && qt_hyper_mask != mask && (sym == XK_Alt_L || sym == XK_Alt_R)) { qt_alt_mask = mask; } if (qt_meta_mask == 0 && qt_alt_mask != mask && qt_super_mask != mask && qt_hyper_mask != mask && (sym == XK_Meta_L || sym == XK_Meta_R)) { qt_meta_mask = mask; } if (qt_super_mask == 0 && qt_alt_mask != mask && qt_meta_mask != mask && qt_hyper_mask != mask && (sym == XK_Super_L || sym == XK_Super_R)) { qt_super_mask = mask; } if (qt_hyper_mask == 0 && qt_alt_mask != mask && qt_meta_mask != mask && qt_super_mask != mask && (sym == XK_Hyper_L || sym == XK_Hyper_R)) { qt_hyper_mask = mask; } } mapIndex++; } } // 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; } } // now look for mode_switch in qt_alt_mask and qt_meta_mask - if it is // present in one or both, then we set qt_mode_switch_remove_mask. // see QETWidget::translateKeyEventInternal for an explanation // of why this is needed mapIndex = 0; for (maskIndex = 0; maskIndex < 8; maskIndex++) { if (qt_alt_mask != (1 << maskIndex) && qt_meta_mask != (1 << maskIndex)) { for (i = 0; i < map->max_keypermod; i++) mapIndex++; continue; } for (i = 0; i < map->max_keypermod; i++) { if (map->modifiermap[mapIndex]) { KeySym sym = XKeycodeToKeysym(X11->display, map->modifiermap[mapIndex], 0); if (sym == XK_Mode_switch) { qt_mode_switch_remove_mask |= 1 << maskIndex; } } mapIndex++; } } XFreeModifiermap(map); } else { // assume defaults qt_alt_mask = Mod1Mask; qt_meta_mask = Mod4Mask; // leave qt_super_mask and qt_hyper_mask set to zero qt_mode_switch_remove_mask = 0; } // Misc. initialization#if 0 //disabled for now.. QSegfaultHandler::initialize(priv->argv, priv->argc);#endif QFont::initialize(); QCursorData::initialize(); } if(qt_is_gui_used) { qApp->setObjectName(QString::fromLocal8Bit(appName)); int screen; for (screen = 0; screen < X11->screenCount; ++screen) { XSelectInput(X11->display, QX11Info::appRootWindow(screen), KeymapStateMask | EnterWindowMask | LeaveWindowMask | PropertyChangeMask);#ifndef QT_NO_XRANDR if (X11->use_xrandr) XRRSelectInput(X11->display, QX11Info::appRootWindow(screen), True);#endif // QT_NO_XRANDR } } if (qt_is_gui_used) { qt_set_input_encoding(); qt_set_x11_resources(appFont, appFGCol, appBGCol, appBTNCol); // be smart about the size of the default font. most X servers have helvetica // 12 point available at 2 resolutions: // 75dpi (12 pixels) and 100dpi (17 pixels). // At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17 // pixel font is a closer match than a 12 pixel font int ptsz = (X11->use_xrender ? 9 : (int) (((QX11Info::appDpiY() >= 95 ? 17. : 12.) * 72. / (float) QX11Info::appDpiY()) + 0.5)); if (!qt_app_has_font) { QFont f(X11->has_fontconfig ? QLatin1String("Sans Serif") : QLatin1String("Helvetica"), ptsz); QApplication::setFont(f); }#if !defined (QT_NO_TABLET) if (isXInputSupported(X11->display)) { int ndev, i, j; bool gotStylus, gotEraser; XDeviceInfo *devices, *devs; XInputClassInfo *ip; XAnyClassPtr any; XValuatorInfoPtr v; XAxisInfoPtr a; XDevice *dev;#if !defined(Q_OS_IRIX) // XFree86 divides a stylus and eraser into 2 devices, so we must do for both... const QString XFREENAMESTYLUS = QLatin1String("stylus"); const QString XFREENAMEPEN = QLatin1String("pen"); const QString XFREENAMEERASER = QLatin1String("eraser");#endif devices = XListInputDevices(X11->display, &ndev); if (!devices) { qWarning("Failed to get list of devices"); ndev = -1; } QTabletEvent::TabletDevice deviceType; dev = 0; for (devs = devices, i = 0; i < ndev; i++, devs++) { gotStylus = false; gotEraser = false; QString devName = QString::fromLocal8Bit(devs->name).toLower();#if defined(Q_OS_IRIX) if (devName == QLatin1String(WACOM_NAME)) { deviceType = QTabletEvent::Stylus; gotStylus = true; }#else if (devName.startsWith(XFREENAMEPEN) || devName.startsWith(XFREENAMESTYLUS)) { deviceType = QTabletEvent::Stylus; gotStylus = true; } else if (devName.startsWith(XFREENAMEERASER)) { deviceType = QTabletEvent::XFreeEraser; gotEraser = true; }#endif if (gotStylus || gotEraser) { dev = XOpenDevice(X11->display, devs->id); if (!dev) { qWarning("Failed to open device"); continue; } QTabletDeviceData device_data; device_data.deviceType = deviceType; device_data.eventCount = 0; device_data.device = dev; device_data.xinput_motion = -1; device_data.xinput_key_press = -1; device_data.xinput_key_release = -1; device_data.xinput_button_press = -1; device_data.xinput_button_release = -1; if (dev->num_classes > 0) { for (ip = dev->classes, j = 0; j < devs->num_classes; ip++, j++) { switch (ip->input_class) { case KeyClass: DeviceKeyPress(dev, device_data.xinput_key_press, device_data.eventList[device_data.eventCount]); ++device_data.eventCount; DeviceKeyRelease(dev, device_data.xinput_key_release, device_data.eventList[device_data.eventCount]); ++device_data.eventCount; break; case ButtonClass: DeviceButtonPress(dev, device_data.xinput_button_press,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -