📄 qapplication_x11.cpp
字号:
? new QEventDispatcherX11(q) : new QEventDispatcherUNIX(q));}/***************************************************************************** Default X error handlers *****************************************************************************/#if defined(Q_C_CALLBACKS)extern "C" {#endifstatic int (*original_x_errhandler)(Display *dpy, XErrorEvent *);static int (*original_xio_errhandler)(Display *dpy);static int qt_x_errhandler(Display *dpy, XErrorEvent *err){ if (err->error_code == BadWindow) { X11->seen_badwindow = true; if (err->request_code == 25 /* X_SendEvent */ && X11->xdndHandleBadwindow()) return 0; if (X11->ignore_badwindow) return 0; } else if (err->error_code == BadMatch && err->request_code == 42 /* X_SetInputFocus */) { return 0; } char errstr[256]; XGetErrorText( dpy, err->error_code, errstr, 256 ); char buffer[256]; char request_str[256]; qsnprintf(buffer, 256, "%d", err->request_code); XGetErrorDatabaseText(dpy, "XRequest", buffer, "", request_str, 256); if (err->request_code < 128) { // X error for a normal protocol request qWarning( "X Error: %s %d\n" " Major opcode: %d (%s)\n" " Resource id: 0x%lx", errstr, err->error_code, err->request_code, request_str, err->resourceid ); } else { // X error for an extension request const char *extensionName = 0; if (err->request_code == X11->xrender_major) extensionName = "RENDER"; else if (err->request_code == X11->xrandr_major) extensionName = "RANDR"; else if (err->request_code == X11->xinput_major) extensionName = "XInputExtension"; char minor_str[256]; if (extensionName) { qsnprintf(buffer, 256, "%s.%d", extensionName, err->minor_code); XGetErrorDatabaseText(dpy, "XRequest", buffer, "", minor_str, 256); } else { extensionName = "Uknown extension"; qsnprintf(minor_str, 256, "Unknown request"); } qWarning( "X Error: %s %d\n" " Extension: %d (%s)\n" " Minor opcode: %d (%s)\n" " Resource id: 0x%lx", errstr, err->error_code, err->request_code, extensionName, err->minor_code, minor_str, err->resourceid ); } // ### we really should distinguish between severe, non-severe and // ### application specific errors return 0;}static int qt_xio_errhandler(Display *){ qWarning("%s: Fatal IO error: client killed", appName); QApplicationPrivate::reset_instance_pointer(); exit(1); //### give the application a chance for a proper shutdown instead, //### exit(1) doesn't help. return 0;}#if defined(Q_C_CALLBACKS)}#endifstatic void qt_x11_create_intern_atoms(){ const char *names[QX11Data::NAtoms]; const char *ptr = x11_atomnames; int i = 0; while (*ptr) { names[i++] = ptr; while (*ptr) ++ptr; ++ptr; } Q_ASSERT(i == QX11Data::NPredefinedAtoms); QByteArray settings_atom_name("_QT_SETTINGS_TIMESTAMP_"); settings_atom_name += XDisplayName(X11->displayName); names[i++] = settings_atom_name; Q_ASSERT(i == QX11Data::NAtoms);#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 6) XInternAtoms(X11->display, (char **)names, i, False, X11->atoms);#else for (i = 0; i < QX11Data::NAtoms; ++i) X11->atoms[i] = XInternAtom(X11->display, (char *)names[i], False);#endif}Q_GUI_EXPORT void qt_x11_apply_settings_in_all_apps(){ QByteArray stamp; QDataStream s(&stamp, QIODevice::WriteOnly); s << QDateTime::currentDateTime(); XChangeProperty(QX11Info::display(), QX11Info::appRootWindow(0), ATOM(_QT_SETTINGS_TIMESTAMP), ATOM(_QT_SETTINGS_TIMESTAMP), 8, PropModeReplace, (unsigned char *)stamp.data(), stamp.size());}/*! \internal apply the settings to the application*/bool QApplicationPrivate::x11_apply_settings(){ QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("Qt")); /* Qt settings. This is now they are written into the datastream. Palette / * - QPalette font - QFont libraryPath - QStringList style - QString doubleClickInterval - int keyboardInputInterval - int cursorFlashTime - int wheelScrollLines - int colorSpec - QString defaultCodec - QString globalStrut/width - int globalStrut/height - int GUIEffects - QStringList Font Substitutions/ * - QStringList Font Substitutions/... - QStringList */ QStringList strlist; int i; QPalette pal(Qt::black); int groupCount = 0; strlist = settings.value(QLatin1String("Palette/active")).toStringList(); if (strlist.count() == QPalette::NColorRoles) { ++groupCount; for (i = 0; i < QPalette::NColorRoles; i++) pal.setColor(QPalette::Active, (QPalette::ColorRole) i, QColor(strlist[i])); } strlist = settings.value(QLatin1String("Palette/inactive")).toStringList(); if (strlist.count() == QPalette::NColorRoles) { ++groupCount; for (i = 0; i < QPalette::NColorRoles; i++) pal.setColor(QPalette::Inactive, (QPalette::ColorRole) i, QColor(strlist[i])); } strlist = settings.value(QLatin1String("Palette/disabled")).toStringList(); if (strlist.count() == QPalette::NColorRoles) { ++groupCount; for (i = 0; i < QPalette::NColorRoles; i++) pal.setColor(QPalette::Disabled, (QPalette::ColorRole) i, QColor(strlist[i])); } if (groupCount == QPalette::NColorGroups) QApplicationPrivate::setSystemPalette(pal); if (!qt_app_has_font && !appFont) { QFont font(QApplication::font()); QString str = settings.value(QLatin1String("font")).toString(); if (!str.isEmpty()) { font.fromString(str); if (font != QApplication::font()) QApplication::setFont(font); } } // read library (ie. plugin) path list QString libpathkey = QString(QLatin1String("%1.%2/libraryPath")) .arg(QT_VERSION >> 16) .arg((QT_VERSION & 0xff00) >> 8); QStringList pathlist = settings.value(libpathkey).toString().split(QLatin1Char(':')); if (! pathlist.isEmpty()) { QStringList::ConstIterator it = pathlist.begin(); while (it != pathlist.end()) QApplication::addLibraryPath(*it++); } // read new QStyle QString stylename = settings.value(QLatin1String("style")).toString(); if (QCoreApplication::startingUp()) { if (!stylename.isEmpty() && !QApplicationPrivate::styleOverride) QApplicationPrivate::styleOverride = new QString(stylename); } else { QApplication::setStyle(stylename); } int num = settings.value(QLatin1String("doubleClickInterval"), QApplication::doubleClickInterval()).toInt(); QApplication::setDoubleClickInterval(num); num = settings.value(QLatin1String("cursorFlashTime"), QApplication::cursorFlashTime()).toInt(); QApplication::setCursorFlashTime(num); num = settings.value(QLatin1String("wheelScrollLines"), QApplication::wheelScrollLines()).toInt(); QApplication::setWheelScrollLines(num); QString colorspec = settings.value(QLatin1String("colorSpec"), QVariant(QLatin1String("default"))).toString(); if (colorspec == QLatin1String("normal")) QApplication::setColorSpec(QApplication::NormalColor); else if (colorspec == QLatin1String("custom")) QApplication::setColorSpec(QApplication::CustomColor); else if (colorspec == QLatin1String("many")) QApplication::setColorSpec(QApplication::ManyColor); else if (colorspec != QLatin1String("default")) colorspec = QLatin1String("default"); QString defaultcodec = settings.value(QLatin1String("defaultCodec"), QVariant(QLatin1String("none"))).toString(); if (defaultcodec != QLatin1String("none")) { QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1()); if (codec) QTextCodec::setCodecForTr(codec); } int w = settings.value(QLatin1String("globalStrut/width")).toInt(); int h = settings.value(QLatin1String("globalStrut/height")).toInt(); QSize strut(w, h); if (strut.isValid()) QApplication::setGlobalStrut(strut); QStringList effects = settings.value(QLatin1String("GUIEffects")).toStringList(); QApplication::setEffectEnabled(Qt::UI_General, effects.contains(QLatin1String("general"))); QApplication::setEffectEnabled(Qt::UI_AnimateMenu, effects.contains(QLatin1String("animatemenu"))); QApplication::setEffectEnabled(Qt::UI_FadeMenu, effects.contains(QLatin1String("fademenu"))); QApplication::setEffectEnabled(Qt::UI_AnimateCombo, effects.contains(QLatin1String("animatecombo"))); QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, effects.contains(QLatin1String("animatetooltip"))); QApplication::setEffectEnabled(Qt::UI_FadeTooltip, effects.contains(QLatin1String("fadetooltip"))); QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, effects.contains(QLatin1String("animatetoolbox"))); settings.beginGroup(QLatin1String("Font Substitutions")); QStringList fontsubs = settings.childKeys(); if (!fontsubs.isEmpty()) { QStringList::Iterator it = fontsubs.begin(); for (; it != fontsubs.end(); ++it) { QString fam = *it; QStringList subs = settings.value(fam).toStringList(); QFont::insertSubstitutions(fam, subs); } } settings.endGroup(); qt_broken_wm = settings.value(QLatin1String("brokenWindowManager"), qt_broken_wm).toBool(); qt_use_rtl_extensions = settings.value(QLatin1String("useRtlExtensions"), false).toBool(); qt_reuse_double_buffer = settings.value(QLatin1String("reuseDoubleBuffer"), true).toBool();#ifndef QT_NO_XIM if (qt_xim_preferred_style == 0) { QString ximInputStyle = settings.value(QLatin1String("XIMInputStyle"), QVariant(QLatin1String("on the spot"))).toString().toLower(); if (ximInputStyle == QLatin1String("on the spot")) qt_xim_preferred_style = XIMPreeditCallbacks | XIMStatusNothing; else if (ximInputStyle == QLatin1String("over the spot")) qt_xim_preferred_style = XIMPreeditPosition | XIMStatusNothing; else if (ximInputStyle == QLatin1String("off the spot")) qt_xim_preferred_style = XIMPreeditArea | XIMStatusArea; else if (ximInputStyle == QLatin1String("root")) qt_xim_preferred_style = XIMPreeditNothing | XIMStatusNothing; }#endif QStringList inputMethods = QInputContextFactory::keys(); if (inputMethods.size() > 2 && inputMethods.contains(QLatin1String("imsw-multi"))) { X11->default_im = QLatin1String("imsw-multi"); } else { X11->default_im = settings.value(QLatin1String("DefaultInputMethod"), QLatin1String("xim")).toString(); } settings.endGroup(); // Qt return true;}/*! \internal Resets the QApplication::instance() pointer to zero*/void QApplicationPrivate::reset_instance_pointer(){ QApplication::self = 0; }// read the _QT_INPUT_ENCODING property and apply the settings to// the applicationstatic void qt_set_input_encoding(){ Atom type; int format; ulong nitems, after = 1; const char *data = 0; int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_QT_INPUT_ENCODING), 0, 1024, False, XA_STRING, &type, &format, &nitems, &after, (unsigned char**)&data); if (e != Success || !nitems || type == XNone) { // Always use the locale codec, since we have no examples of non-local // XIMs, and since we cannot get a sensible answer about the encoding // from the XIM. qt_input_mapper = QTextCodec::codecForLocale(); } else { if (!qstricmp(data, "locale")) qt_input_mapper = QTextCodec::codecForLocale(); else qt_input_mapper = QTextCodec::codecForName(data); // make sure we have an input codec
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -