📄 qapplication_x11.cpp
字号:
if(!qt_input_mapper) qt_input_mapper = QTextCodec::codecForName("ISO 8859-1"); } if (qt_input_mapper && qt_input_mapper->mibEnum() == 11) // 8859-8 qt_input_mapper = QTextCodec::codecForName("ISO 8859-8-I"); if(data) XFree((char *)data);}// set font, foreground and background from x11 resources. The// arguments may override the resource settings.static void qt_set_x11_resources(const char* font = 0, const char* fg = 0, const char* bg = 0, const char* button = 0){ QString resFont, resFG, resBG, resEF, sysFont; QApplication::setEffectEnabled(Qt::UI_General, false); QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); QApplication::setEffectEnabled(Qt::UI_FadeMenu, false); QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false); QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, false); QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false); QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, false); bool paletteAlreadySet = false; if (QApplication::desktopSettingsAware()) { // first, read from settings QApplicationPrivate::x11_apply_settings(); // the call to QApplication::style() below creates the system // palette, which breaks the logic after the RESOURCE_MANAGER // loop... so I have to save this value to be able to use it later paletteAlreadySet = (QApplicationPrivate::sys_pal != 0); QString style = QApplication::style()->metaObject()->className(); if (style == QLatin1String("QWindowsStyle") || style == QLatin1String("QMotifStyle") || style == QLatin1String("QCDEStyle")) { // ### Only plain styles currently work fine with RESOURCE_MANAGER // provided palette entries. For now, we apply this code to only // our own plain styles, until we can get complex styles to work // properly. We might also introduce a style hint for this. // second, parse the RESOURCE_MANAGER property int format; ulong nitems, after = 1; QString res; long offset = 0; Atom type = XNone; while (after > 0) { uchar *data = 0; XGetWindowProperty(X11->display, QX11Info::appRootWindow(0), ATOM(RESOURCE_MANAGER), offset, 8192, False, AnyPropertyType, &type, &format, &nitems, &after, &data); if (type == XA_STRING) res += QString::fromLatin1((char*)data); else res += QString::fromLocal8Bit((char*)data); offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048 if (data) XFree((char *)data); } QString key, value; int l = 0, r; QString apn = QString::fromLocal8Bit(appName); QString apc = QString::fromLocal8Bit(appClass); int apnl = apn.length(); int apcl = apc.length(); int resl = res.length(); while (l < resl) { r = res.indexOf(QLatin1Char('\n'), l); if (r < 0) r = resl; while (::isSpace(res.at(l))) l++; bool mine = false; QChar sc = res.at(l + 1); if (res.at(l) == QLatin1Char('*') && (sc == QLatin1Char('f') || sc == QLatin1Char('b') || sc == QLatin1Char('g') || sc == QLatin1Char('F') || sc == QLatin1Char('B') || sc == QLatin1Char('G') || sc == QLatin1Char('s') || sc == QLatin1Char('S'))) { // OPTIMIZED, since we only want "*[fbgs].." QString item = res.mid(l, r - l).simplified(); int i = item.indexOf(QLatin1Char(':')); key = item.left(i).trimmed().mid(1).toLower(); value = item.right(item.length() - i - 1).trimmed(); mine = true; } else if (apnl && res.at(l) == apn.at(0) || (appClass && apcl && res.at(l) == apc.at(0))) { if (res.mid(l,apnl) == apn && (res.at(l+apnl) == QLatin1Char('.') || res.at(l+apnl) == QLatin1Char('*'))) { QString item = res.mid(l, r - l).simplified(); int i = item.indexOf(QLatin1Char(':')); key = item.left(i).trimmed().mid(apnl+1).toLower(); value = item.right(item.length() - i - 1).trimmed(); mine = true; } else if (res.mid(l,apcl) == apc && (res.at(l+apcl) == QLatin1Char('.') || res.at(l+apcl) == QLatin1Char('*'))) { QString item = res.mid(l, r - l).simplified(); int i = item.indexOf(QLatin1Char(':')); key = item.left(i).trimmed().mid(apcl+1).toLower(); value = item.right(item.length() - i - 1).trimmed(); mine = true; } } if (mine) { if (!font && key == QLatin1String("systemfont")) sysFont = value.left(value.lastIndexOf(QLatin1Char(':'))); if (!font && key == QLatin1String("font")) resFont = value; else if (!paletteAlreadySet && !fg && key == QLatin1String("foreground")) resFG = value; else if (!paletteAlreadySet && !bg && key == QLatin1String("background")) resBG = value; else if (key == QLatin1String("guieffects")) resEF = value; // NOTE: if you add more, change the [fbg] stuff above } l = r + 1; } } } if (!sysFont.isEmpty()) resFont = sysFont; if (resFont.isEmpty()) resFont = QString::fromLocal8Bit(font); if (resFG.isEmpty()) resFG = QString::fromLocal8Bit(fg); if (resBG.isEmpty()) resBG = QString::fromLocal8Bit(bg); if (!qt_app_has_font && !resFont.isEmpty()) { // set application font QFont fnt; fnt.setRawName(resFont); // the font we get may actually be an alias for another font, // so we reset the application font to the real font info. if (! fnt.exactMatch()) { QFontInfo fontinfo(fnt); fnt.setFamily(fontinfo.family()); fnt.setRawMode(fontinfo.rawMode()); if (! fnt.rawMode()) { fnt.setItalic(fontinfo.italic()); fnt.setWeight(fontinfo.weight()); fnt.setUnderline(fontinfo.underline()); fnt.setStrikeOut(fontinfo.strikeOut()); fnt.setStyleHint(fontinfo.styleHint()); if (fnt.pointSize() <= 0 && fnt.pixelSize() <= 0) { // size is all wrong... fix it qreal pointSize = fontinfo.pixelSize() * 72. / (float) QX11Info::appDpiY(); if (pointSize <= 0) pointSize = 12; fnt.setPointSize(qRound(pointSize)); } } } if (fnt != QApplication::font()) { QApplication::setFont(fnt); } } if ((button || !resBG.isEmpty() || !resFG.isEmpty())) {// set app colors (void) QApplication::style(); // trigger creation of application style and system palettes QColor btn; QColor bg; QColor fg; if (!resBG.isEmpty()) bg = QColor(QString(resBG)); else bg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Background); if (!resFG.isEmpty()) fg = QColor(QString(resFG)); else fg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Foreground); if (button) btn = QColor(button); else if (!resBG.isEmpty()) btn = bg; else btn = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Button); int h,s,v; fg.getHsv(&h,&s,&v); QColor base = Qt::white; bool bright_mode = false; if (v >= 255-50) { base = btn.dark(150); bright_mode = true; } QPalette pal(fg, btn, btn.light(), btn.dark(), btn.dark(150), fg, Qt::white, base, bg); if (bright_mode) { pal.setColor(QPalette::HighlightedText, base); pal.setColor(QPalette::Highlight, Qt::white); } else { pal.setColor(QPalette::HighlightedText, Qt::white); pal.setColor(QPalette::Highlight, Qt::darkBlue); } QColor disabled((fg.red() + btn.red()) / 2, (fg.green() + btn.green())/ 2, (fg.blue() + btn.blue()) / 2); pal.setColorGroup(QPalette::Disabled, disabled, btn, btn.light(125), btn.dark(), btn.dark(150), disabled, Qt::white, Qt::white, bg); if (bright_mode) { pal.setColor(QPalette::Disabled, QPalette::HighlightedText, base); pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::white); } else { pal.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::white); pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::darkBlue); } QApplicationPrivate::setSystemPalette(pal); } if (!resEF.isEmpty()) { QStringList effects = resEF.split(QLatin1Char(' ')); 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"))); }}static void qt_detect_broken_window_manager(){ Atom type; int format; ulong nitems, after; uchar *data = 0; // look for SGI's 4Dwm int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_SGI_DESKS_MANAGER), 0, 1, False, XA_WINDOW, &type, &format, &nitems, &after, &data); if (data) XFree(data); if (e == Success && type == XA_WINDOW && format == 32 && nitems == 1 && after == 0) { // detected SGI 4Dwm qt_broken_wm = true; }}// update the supported arraystatic void qt_get_net_supported(){ Atom type; int format; long offset = 0; unsigned long nitems, after; unsigned char *data = 0; int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_NET_SUPPORTED), 0, 0, False, XA_ATOM, &type, &format, &nitems, &after, &data); if (data) XFree(data); if (X11->net_supported_list) delete [] X11->net_supported_list; X11->net_supported_list = 0; if (e == Success && type == XA_ATOM && format == 32) { QBuffer ts; ts.open(QIODevice::WriteOnly); while (after > 0) { XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_NET_SUPPORTED), offset, 1024, False, XA_ATOM, &type, &format, &nitems, &after, &data); if (type == XA_ATOM && format == 32) { ts.write(reinterpret_cast<char *>(data), nitems * sizeof(long)); offset += nitems; } else after = 0; if (data) XFree(data); } // compute nitems QByteArray buffer(ts.buffer()); nitems = buffer.size() / sizeof(Atom); X11->net_supported_list = new Atom[nitems + 1]; Atom *a = (Atom *) buffer.data(); uint i; for (i = 0; i < nitems; i++) X11->net_supported_list[i] = a[i]; X11->net_supported_list[nitems] = 0; }}bool qt_net_supports(Atom atom){ if (! X11->net_supported_list) return false; bool supported = false; int i = 0; while (X11->net_supported_list[i] != 0) { if (X11->net_supported_list[i++] == atom) { supported = true; break; } } return supported;}// update the virtual roots arraystatic void qt_get_net_virtual_roots(){ if (X11->net_virtual_root_list) delete [] X11->net_virtual_root_list; X11->net_virtual_root_list = 0; if (!qt_net_supports(ATOM(_NET_VIRTUAL_ROOTS))) return; Atom type; int format; long offset = 0; unsigned long nitems, after; unsigned char *data; int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_NET_VIRTUAL_ROOTS), 0, 0, False, XA_ATOM, &type, &format, &nitems, &after, &data); if (data) XFree(data); if (e == Success && type == XA_ATOM && format == 32) { QBuffer ts; ts.open(QIODevice::WriteOnly); while (after > 0) { XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_NET_VIRTUAL_ROOTS), offset, 1024,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -