src/gui/kernel/qapplication.cpp File Reference

#include "qabstracteventdispatcher.h"
#include "qaccessible.h"
#include "qapplication.h"
#include "qclipboard.h"
#include "qcursor.h"
#include "qdesktopwidget.h"
#include "qdir.h"
#include "qevent.h"
#include "qfile.h"
#include "qfileinfo.h"
#include "qhash.h"
#include "qset.h"
#include "qlayout.h"
#include "qsessionmanager.h"
#include "qstyle.h"
#include "qstylefactory.h"
#include "qtextcodec.h"
#include "qtranslator.h"
#include "qvariant.h"
#include "qwidget.h"
#include "qdnd_p.h"
#include "qcolormap.h"
#include "qdebug.h"
#include "private/qstylesheetstyle_p.h"
#include "private/qstyle_p.h"
#include "qmessagebox.h"
#include "qinputcontext.h"
#include "qkeymapper_p.h"
#include <private/qt_x11_p.h>
#include "qinputcontextfactory.h"
#include <qthread.h>
#include <private/qthread_p.h>
#include <private/qfont_p.h>
#include <stdlib.h>
#include "qapplication_p.h"
#include "qwidget_p.h"
#include "moc_qapplication.cpp"

Include dependency graph for qapplication.cpp:

Go to the source code of this file.

Typedefs

typedef QHash< QByteArray,
QPalette
PaletteHash
typedef QHash< QByteArray,
QFont
FontHash

Functions

void qt_call_post_routines ()
void qt_init (QApplicationPrivate *priv, int type, Display *display=0, Qt::HANDLE visual=0, Qt::HANDLE colormap=0)
void qt_cleanup ()
PaletteHashqt_app_palettes_hash ()
FontHashqt_app_fonts_hash ()
static bool qt_detectRTLLanguage ()
Q_GUI_EXPORT bool qt_tryModalHelper (QWidget *widget, QWidget **rettop)

Variables

QApplication::Type qt_appType = QApplication::Tty
bool qt_app_has_font = false
bool qt_is_gui_used
bool Q_GUI_EXPORT qt_tab_all_widgets = true
bool qt_in_tab_key_event = false
int qt_antialiasing_threshold = -1
static int drag_time = 500
static int drag_distance = 4
static Qt::LayoutDirection layout_direction = Qt::LeftToRight
bool qt_tabletChokeMouse = false
static bool force_reverse = false
QDesktopWidgetqt_desktopWidget = 0
QClipboardqt_clipboard = 0
QWidgetListqt_modal_stack = 0
static int aargc = 1
static char * aargv [] = { (char*)"unknown", 0 }


Typedef Documentation

typedef QHash<QByteArray, QFont> FontHash

Definition at line 410 of file qapplication.cpp.

typedef QHash<QByteArray, QPalette> PaletteHash

Definition at line 403 of file qapplication.cpp.


Function Documentation

FontHash* qt_app_fonts_hash (  ) 

Definition at line 412 of file qapplication.cpp.

Referenced by QComboMenuDelegate::getStyleOption(), QDockWidgetPrivate::relayout(), and QMessageBox::setInformativeText().

00413 {
00414     return app_fonts();
00415 }

PaletteHash* qt_app_palettes_hash (  ) 

Definition at line 405 of file qapplication.cpp.

00406 {
00407     return app_palettes();
00408 }

void qt_call_post_routines (  ) 

Definition at line 116 of file qcoreapplication.cpp.

References QList< T >::isEmpty(), and QList< T >::takeFirst().

Referenced by QApplication::~QApplication(), and QCoreApplication::~QCoreApplication().

00117 {
00118     QVFuncList *list = postRList();
00119     if (!list)
00120         return;
00121     while (!list->isEmpty())
00122         (list->takeFirst())();
00123 }

Here is the call graph for this function:

void qt_cleanup (  ) 

Definition at line 1991 of file qapplication_x11.cpp.

References app_save_rootinfo, appClass, QList< T >::at(), QCursorData::cleanup(), QColormap::cleanup(), QFont::cleanup(), QPixmapCache::clear(), QApplicationPrivate::inputContext, original_x_errhandler, original_xio_errhandler, qt_save_rootinfo(), qt_tablet_devices(), QList< T >::size(), and X11.

Referenced by QApplication::~QApplication().

01992 {
01993     if (app_save_rootinfo)                        // root window must keep state
01994         qt_save_rootinfo();
01995 
01996     if (qt_is_gui_used) {
01997         QPixmapCache::clear();
01998         QCursorData::cleanup();
01999         QFont::cleanup();
02000         QColormap::cleanup();
02001     }
02002 
02003 #ifndef QT_NO_XRENDER
02004     for (int i = 0; i < X11->solid_fill_count; ++i) {
02005         if (X11->solid_fills[i].picture)
02006             XRenderFreePicture(X11->display, X11->solid_fills[i].picture);
02007     }
02008     for (int i = 0; i < X11->pattern_fill_count; ++i) {
02009         if (X11->pattern_fills[i].picture)
02010             XRenderFreePicture(X11->display, X11->pattern_fills[i].picture);
02011     }
02012 #endif
02013 #if !defined (QT_NO_TABLET)
02014     QTabletDeviceDataList *devices = qt_tablet_devices();
02015     for (int i = 0; i < devices->size(); ++i)
02016         XCloseDevice(X11->display, (XDevice*)devices->at(i).device);
02017 #endif
02018 
02019 #if !defined(QT_NO_IM)
02020     delete QApplicationPrivate::inputContext;
02021     QApplicationPrivate::inputContext = 0;
02022 #endif
02023 
02024     // Reset the error handlers
02025     XSetErrorHandler(original_x_errhandler);
02026     XSetIOErrorHandler(original_xio_errhandler);
02027 
02028     if (qt_is_gui_used && !X11->foreignDisplay)
02029         XCloseDisplay(X11->display);                // close X display
02030     X11->display = 0;
02031 
02032     delete [] X11->screens;
02033 
02034     if (X11->foreignDisplay) {
02035         delete [] (char *)appName;
02036         appName = 0;
02037     }
02038 
02039     delete [] (char *)appClass;
02040     appClass = 0;
02041 
02042     if (X11->net_supported_list)
02043         delete [] X11->net_supported_list;
02044     X11->net_supported_list = 0;
02045 
02046     if (X11->net_virtual_root_list)
02047         delete [] X11->net_virtual_root_list;
02048     X11->net_virtual_root_list = 0;
02049 
02050     delete X11;
02051     X11 = 0;
02052 }

Here is the call graph for this function:

static bool qt_detectRTLLanguage (  )  [static]

Definition at line 1936 of file qapplication.cpp.

References force_reverse.

01937 {
01938     return force_reverse ^
01939         QApplication::tr("QT_LAYOUT_DIRECTION",
01940                          "Translate this string to the string 'LTR' in left-to-right"
01941                          " languages or to 'RTL' in right-to-left languages (such as Hebrew"
01942                          " and Arabic) to get proper widget layout.") == QLatin1String("RTL");
01943 }

void qt_init ( QApplicationPrivate priv,
int  type,
Display display = 0,
Qt::HANDLE  visual = 0,
Qt::HANDLE  colormap = 0 
)

Definition at line 1229 of file qapplication_x11.cpp.

References appClass, appName, p, priv(), QByteArray::qstrdup(), and X11.

01231 {
01232     X11 = new QX11Data;
01233     X11->display = display;
01234     X11->displayName = 0;
01235     X11->foreignDisplay = (display != 0);
01236     X11->focus_model = -1;
01237 
01238     // RANDR
01239     X11->use_xrandr = false;
01240     X11->xrandr_major = 0;
01241     X11->xrandr_eventbase = 0;
01242     X11->xrandr_errorbase = 0;
01243 
01244     // RENDER
01245     X11->use_xrender = false;
01246     X11->xrender_major = 0;
01247     X11->xrender_version = 0;
01248 
01249     // XFIXES
01250     X11->use_xfixes = false;
01251     X11->xfixes_major = 0;
01252     X11->xfixes_eventbase = 0;
01253     X11->xfixes_errorbase = 0;
01254 
01255     // XInputExtension
01256     X11->use_xinput = false;
01257     X11->xinput_major = 0;
01258     X11->xinput_eventbase = 0;
01259     X11->xinput_errorbase = 0;
01260 
01261     X11->sip_serial = 0;
01262     X11->net_supported_list = 0;
01263     X11->net_virtual_root_list = 0;
01264     X11->wm_client_leader = 0;
01265     X11->screens = 0;
01266     X11->screenCount = 0;
01267     X11->time = CurrentTime;
01268     X11->userTime = CurrentTime;
01269     X11->ignore_badwindow = false;
01270     X11->seen_badwindow = false;
01271 
01272     X11->motifdnd_active = false;
01273 
01274     X11->default_im = QLatin1String("imsw-multi");
01275     priv->inputContext = 0;
01276 
01277     // colormap control
01278     X11->visual_class = -1;
01279     X11->visual_id = -1;
01280     X11->color_count = 0;
01281     X11->custom_cmap = false;
01282 
01283     // outside visual/colormap
01284     X11->visual = reinterpret_cast<Visual *>(visual);
01285     X11->colormap = colormap;
01286 
01287 #ifndef QT_NO_XRENDER
01288     memset(X11->solid_fills, 0, sizeof(X11->solid_fills));
01289     for (int i = 0; i < X11->solid_fill_count; ++i)
01290         X11->solid_fills[i].screen = -1;
01291     memset(X11->pattern_fills, 0, sizeof(X11->pattern_fills));
01292     for (int i = 0; i < X11->pattern_fill_count; ++i)
01293         X11->pattern_fills[i].screen = -1;
01294 #endif
01295 
01296     X11->startupId = 0;
01297 
01298     int argc = priv->argc;
01299     char **argv = priv->argv;
01300 
01301     if (X11->display) {
01302         // Qt part of other application
01303 
01304         // Set application name and class
01305         appName = qstrdup("Qt-subapplication");
01306         char *app_class = 0;
01307         if (argv) {
01308             const char* p = strrchr(argv[0], '/');
01309             app_class = qstrdup(p ? p + 1 : argv[0]);
01310             if (app_class[0])
01311                 app_class[0] = toupper(app_class[0]);
01312         }
01313         appClass = app_class;
01314     } else {
01315         // Qt controls everything (default)
01316 
01317         // Set application name and class
01318         char *app_class = 0;
01319         if (argv && argv[0]) {
01320             const char *p = strrchr(argv[0], '/');
01321             appName = p ? p + 1 : argv[0];
01322             app_class = qstrdup(appName);
01323             if (app_class[0])
01324                 app_class[0] = toupper(app_class[0]);
01325         }
01326         appClass = app_class;
01327     }
01328 
01329     // Install default error handlers
01330     original_x_errhandler = XSetErrorHandler(qt_x_errhandler);
01331     original_xio_errhandler = XSetIOErrorHandler(qt_xio_errhandler);
01332 
01333     // Get command line params
01334     int j = argc ? 1 : 0;
01335     for (int i=1; i<argc; i++) {
01336         if (argv[i] && *argv[i] != '-') {
01337             argv[j++] = argv[i];
01338             continue;
01339         }
01340         QByteArray arg(argv[i]);
01341         if (arg == "-display") {
01342             if (++i < argc && !X11->display)
01343                 X11->displayName = argv[i];
01344         } else if (arg == "-fn" || arg == "-font") {
01345             if (++i < argc)
01346                 appFont = argv[i];
01347         } else if (arg == "-bg" || arg == "-background") {
01348             if (++i < argc)
01349                 appBGCol = argv[i];
01350         } else if (arg == "-btn" || arg == "-button") {
01351             if (++i < argc)
01352                 appBTNCol = argv[i];
01353         } else if (arg == "-fg" || arg == "-foreground") {
01354             if (++i < argc)
01355                 appFGCol = argv[i];
01356         } else if (arg == "-name") {
01357             if (++i < argc)
01358                 appName = argv[i];
01359         } else if (arg == "-title") {
01360             if (++i < argc)
01361                 mwTitle = argv[i];
01362         } else if (arg == "-geometry") {
01363             if (++i < argc)
01364                 mwGeometry = argv[i];
01365         } else if (arg == "-im") {
01366             if (++i < argc)
01367                 qt_ximServer = argv[i];
01368 #if 0
01369         } else if (arg == "-noxim") {
01370             noxim=true;
01371 #endif
01372         } else if (arg == "-ncols") {   // xv and netscape use this name
01373             if (++i < argc)
01374                 X11->color_count = qMax(0,atoi(argv[i]));
01375         } else if (arg == "-visual") {  // xv and netscape use this name
01376             if (++i < argc && !X11->visual) {
01377                 QString s = QString::fromLocal8Bit(argv[i]).toLower();
01378                 if (s == QLatin1String("staticgray"))
01379                     X11->visual_class = StaticGray;
01380                 else if (s == QLatin1String("grayscale"))
01381                     X11->visual_class = XGrayScale;
01382                 else if (s == QLatin1String("staticcolor"))
01383                     X11->visual_class = StaticColor;
01384                 else if (s == QLatin1String("pseudocolor"))
01385                     X11->visual_class = PseudoColor;
01386                 else if (s == QLatin1String("truecolor"))
01387                     X11->visual_class = TrueColor;
01388                 else if (s == QLatin1String("directcolor"))
01389                     X11->visual_class = DirectColor;
01390                 else
01391                     X11->visual_id = static_cast<int>(strtol(argv[i], 0, 0));
01392             }
01393 #ifndef QT_NO_XIM
01394         } else if (arg == "-inputstyle") {
01395             if (++i < argc) {
01396                 QString s = QString::fromLocal8Bit(argv[i]).toLower();
01397                 if (s == QLatin1String("onthespot"))
01398                     qt_xim_preferred_style = XIMPreeditCallbacks |
01399                                              XIMStatusNothing;
01400                 else if (s == QLatin1String("overthespot"))
01401                     qt_xim_preferred_style = XIMPreeditPosition |
01402                                              XIMStatusNothing;
01403                 else if (s == QLatin1String("offthespot"))
01404                     qt_xim_preferred_style = XIMPreeditArea |
01405                                              XIMStatusArea;
01406                 else if (s == QLatin1String("root"))
01407                     qt_xim_preferred_style = XIMPreeditNothing |
01408                                              XIMStatusNothing;
01409             }
01410 #endif
01411         } else if (arg == "-cmap") {    // xv uses this name
01412             if (!X11->colormap)
01413                 X11->custom_cmap = true;
01414         }
01415 #if defined(QT_DEBUG)
01416         else if (arg == "-sync")
01417             appSync = !appSync;
01418         else if (arg == "-nograb")
01419             appNoGrab = !appNoGrab;
01420         else if (arg == "-dograb")
01421             appDoGrab = !appDoGrab;
01422 #endif
01423         else
01424             argv[j++] = argv[i];
01425     }
01426 
01427     priv->argc = j;
01428 
01429 #if defined(QT_DEBUG) && defined(Q_OS_LINUX)
01430     if (!appNoGrab && !appDoGrab) {
01431         QString s;
01432         s.sprintf("/proc/%d/cmdline", getppid());
01433         QFile f(s);
01434         if (f.open(QIODevice::ReadOnly)) {
01435             s.clear();
01436             char c;
01437             while (f.getChar(&c) && c) {
01438                 if (c == '/')
01439                     s.clear();
01440                 else
01441                     s += QLatin1Char(c);
01442             }
01443             if (s == QLatin1String("gdb")) {
01444                 appNoGrab = true;
01445                 qDebug("Qt: gdb: -nograb added to command-line options.\n"
01446                        "\t Use the -dograb option to enforce grabbing.");
01447             }
01448             f.close();
01449         }
01450     }
01451 #endif
01452 
01453     // Connect to X server
01454     if (qt_is_gui_used && !X11->display) {
01455         if ((X11->display = XOpenDisplay(X11->displayName)) == 0) {
01456             qWarning("%s: cannot connect to X server %s", appName,
01457                      XDisplayName(X11->displayName));
01458             QApplicationPrivate::reset_instance_pointer();
01459             exit(1);
01460         }
01461 
01462         if (appSync)                                // if "-sync" argument
01463             XSynchronize(X11->display, true);
01464     }
01465 
01466     // Common code, regardless of whether display is foreign.
01467 
01468     // Get X parameters
01469 
01470     if (qt_is_gui_used) {
01471         X11->defaultScreen = DefaultScreen(X11->display);
01472         X11->screenCount = ScreenCount(X11->display);
01473 
01474         X11->screens = new QX11InfoData[X11->screenCount];
01475 
01476         for (int s = 0; s < X11->screenCount; s++) {
01477             QX11InfoData *screen = X11->screens + s;
01478             screen->ref = 1; // ensures it doesn't get deleted
01479             screen->screen = s;
01480             screen->dpiX = (DisplayWidth(X11->display, s) * 254 + DisplayWidthMM(X11->display, s)*5)
01481                            / (DisplayWidthMM(X11->display, s)*10);
01482             screen->dpiY = (DisplayHeight(X11->display, s) * 254 + DisplayHeightMM(X11->display, s)*5)
01483                            / (DisplayHeightMM(X11->display, s)*10);
01484         }
01485 
01486         QColormap::initialize();
01487 
01488         // Support protocols
01489         X11->xdndSetup();
01490 
01491         // Finally create all atoms
01492         qt_x11_create_intern_atoms();
01493 
01494         // look for broken window managers
01495         qt_detect_broken_window_manager();
01496 
01497         // initialize NET lists
01498         qt_get_net_supported();
01499         qt_get_net_virtual_roots();
01500 
01501 #ifndef QT_NO_XRANDR
01502         // See if XRandR is supported on the connected display
01503         if (XQueryExtension(X11->display, "RANDR", &X11->xrandr_major,
01504                             &X11->xrandr_eventbase, &X11->xrandr_errorbase)
01505             && XRRQueryExtension(X11->display, &X11->xrandr_eventbase, &X11->xrandr_errorbase)) {
01506             // XRandR is supported
01507             X11->use_xrandr = true;
01508         }
01509 #endif // QT_NO_XRANDR
01510 
01511 #ifndef QT_NO_XRENDER
01512         int xrender_eventbase,  xrender_errorbase;
01513         // See if XRender is supported on the connected display
01514         if (XQueryExtension(X11->display, "RENDER", &X11->xrender_major,
01515                             &xrender_eventbase, &xrender_errorbase)
01516             && XRenderQueryExtension(X11->display, &xrender_eventbase,
01517                                      &xrender_errorbase)) {
01518             // XRender is supported, let's see if we have a PictFormat for the
01519             // default visual
01520             XRenderPictFormat *format =
01521                 XRenderFindVisualFormat(X11->display,
01522                                         (Visual *) QX11Info::appVisual(X11->defaultScreen));
01523             // Check the version as well - we need v0.4 or higher
01524             int major = 0;
01525             int minor = 0;
01526             XRenderQueryVersion(X11->display, &major, &minor);
01527             if (qgetenv("QT_X11_NO_XRENDER").isNull() && format != 0) {
01528                 X11->use_xrender = (major >= 0 && minor >= 5);
01529                 X11->xrender_version = major*100+minor;
01530                 // workaround for broken XServer on Ubuntu Breezy (6.8 compiled with 7.0
01531                 // protocol headers)
01532                 if (X11->xrender_version == 10
01533                     && VendorRelease(X11->display) < 60900000
01534                     && QByteArray(ServerVendor(X11->display)).contains("X.Org"))
01535                     X11->xrender_version = 9;
01536             }
01537         }
01538 #endif // QT_NO_XRENDER
01539 
01540 #ifndef QT_NO_XFIXES
01541         // See if Xfixes is supported on the connected display
01542         if (XQueryExtension(X11->display, "XFIXES", &X11->xfixes_major,
01543                             &X11->xfixes_eventbase, &X11->xfixes_errorbase)
01544             && XFixesQueryExtension(X11->display, &X11->xfixes_eventbase,
01545                                     &X11->xfixes_errorbase)) {
01546             // Xfixes is supported.
01547             // Note: the XFixes protocol version is negotiated using QueryVersion.
01548             // We supply the highest version we support, the X server replies with
01549             // the highest version it supports, but no higher than the version we
01550             // asked for. The version sent back is the protocol version the X server
01551             // will use to talk us. If this call is removed, the behavior of the
01552             // X server when it receives an XFixes request is undefined.
01553             int major = 3;
01554             int minor = 0;
01555             XFixesQueryVersion(X11->display, &major, &minor);
01556             X11->use_xfixes = (major >= 2);
01557             X11->xfixes_major = major;
01558         }
01559 #endif // QT_NO_XFIXES
01560 
01561         X11->has_fontconfig = false;
01562 #if !defined(QT_NO_FONTCONFIG)
01563         if (qgetenv("QT_X11_NO_FONTCONFIG").isNull())
01564             X11->has_fontconfig = FcInit();
01565 
01566         int dpi = 0;
01567         getXDefault("Xft", FC_DPI, &dpi);
01568         if (dpi) {
01569             for (int s = 0; s < ScreenCount(X11->display); ++s) {
01570                 QX11Info::setAppDpiX(s, dpi);
01571                 QX11Info::setAppDpiY(s, dpi);
01572             }
01573         }
01574         X11->fc_scale = 1.;
01575         getXDefault("Xft", FC_SCALE, &X11->fc_scale);
01576         for (int s = 0; s < ScreenCount(X11->display); ++s) {
01577             int subpixel = FC_RGBA_UNKNOWN;
01578 #if RENDER_MAJOR > 0 || RENDER_MINOR >= 6
01579             if (X11->use_xrender) {
01580                 int rsp = XRenderQuerySubpixelOrder(X11->display, s);
01581                 switch (rsp) {
01582                 default:
01583                 case SubPixelUnknown:
01584                     subpixel = FC_RGBA_UNKNOWN;
01585                     break;
01586                 case SubPixelHorizontalRGB:
01587                     subpixel = FC_RGBA_RGB;
01588                     break;
01589                 case SubPixelHorizontalBGR:
01590                     subpixel = FC_RGBA_BGR;
01591                     break;
01592                 case SubPixelVerticalRGB:
01593                     subpixel = FC_RGBA_VRGB;
01594                     break;
01595                 case SubPixelVerticalBGR:
01596                     subpixel = FC_RGBA_VBGR;
01597                     break;
01598                 case SubPixelNone:
01599                     subpixel = FC_RGBA_NONE;
01600                     break;
01601                 }
01602             }
01603 #endif
01604             getXDefault("Xft", FC_RGBA, &subpixel);
01605             X11->screens[s].subpixel = subpixel;
01606         }
01607         X11->fc_antialias = true;
01608         getXDefault("Xft", FC_ANTIALIAS, &X11->fc_antialias);
01609 #ifdef FC_HINT_STYLE
01610         getXDefault("Xft", FC_HINT_STYLE, &X11->fc_hint_style);
01611 #endif
01612 #if 0
01613         // ###### these are implemented by Xft, not sure we need them
01614         getXDefault("Xft", FC_AUTOHINT, &X11->fc_autohint);
01615         getXDefault("Xft", FC_HINTING, &X11->fc_autohint);
01616         getXDefault("Xft", FC_MINSPACE, &X11->fc_autohint);
01617 #endif
01618 #endif // QT_NO_XRENDER
01619 
01620         // initialize key mapper
01621         QKeyMapper::changeKeyboard();
01622 
01623 #ifndef QT_NO_XKB
01624         if (qt_keymapper_private()->useXKB) {
01625             // If XKB is detected, set the GrabsUseXKBState option so input method
01626             // compositions continue to work (ie. deadkeys)
01627             unsigned int state = XkbPCF_GrabsUseXKBStateMask;
01628             (void) XkbSetPerClientControls(X11->display, state, &state);
01629         }
01630 #endif // QT_NO_XKB
01631 
01632         // Misc. initialization
01633 #if 0 //disabled for now..
01634         QSegfaultHandler::initialize(priv->argv, priv->argc);
01635 #endif
01636         QFont::initialize();
01637         QCursorData::initialize();
01638     }
01639 
01640     if(qt_is_gui_used) {
01641         qApp->setObjectName(QString::fromLocal8Bit(appName));
01642 
01643         int screen;
01644         for (screen = 0; screen < X11->screenCount; ++screen) {
01645             XSelectInput(X11->display, QX11Info::appRootWindow(screen),
01646                          KeymapStateMask | EnterWindowMask | LeaveWindowMask | PropertyChangeMask);
01647 
01648 #ifndef QT_NO_XRANDR
01649             if (X11->use_xrandr)
01650                 XRRSelectInput(X11->display, QX11Info::appRootWindow(screen), True);
01651 #endif // QT_NO_XRANDR
01652         }
01653     }
01654 
01655     if (qt_is_gui_used) {
01656         // Attempt to determine the current running X11 Desktop Enviornment
01657         // Use dbus if/when we can, but fall back to using windowManagerName() for now
01658 
01659         X11->desktopEnvironment = DE_UNKNOWN;
01660 
01661         // See if the current window manager is using the freedesktop.org spec to give its name
01662         Window windowManagerWindow = XNone;
01663         Atom typeReturned;
01664         int formatReturned;
01665         unsigned long nitemsReturned;
01666         unsigned long unused;
01667         unsigned char *data = 0;
01668         if (XGetWindowProperty(QX11Info::display(), QX11Info::appRootWindow(),
01669                            ATOM(_NET_SUPPORTING_WM_CHECK),
01670                            0, 1024, False, XA_WINDOW, &typeReturned,
01671                            &formatReturned, &nitemsReturned, &unused, &data)
01672               == Success) {
01673             if (typeReturned == XA_WINDOW && formatReturned == 32)
01674                 windowManagerWindow = *((Window*) data);
01675             if (data)
01676                 XFree(data);
01677 
01678             if (windowManagerWindow != XNone) {
01679                 QString wmName;
01680                 Atom utf8atom = ATOM(UTF8_STRING);
01681                 if (XGetWindowProperty(QX11Info::display(), windowManagerWindow, ATOM(_NET_WM_NAME),
01682                                        0, 1024, False, utf8atom, &typeReturned,
01683                                        &formatReturned, &nitemsReturned, &unused, &data)
01684                     == Success) {
01685                     if (typeReturned == utf8atom && formatReturned == 8)
01686                         wmName = QString::fromUtf8((const char*)data);
01687                     if (data)
01688                         XFree(data);
01689                     if (wmName == QLatin1String("KWin"))
01690                         X11->desktopEnvironment = DE_KDE;
01691                     if (wmName == QLatin1String("Metacity"))
01692                         X11->desktopEnvironment = DE_GNOME;
01693                 }
01694             }
01695         }
01696 
01697         // Running a different/newer/older window manager?  Try some other things
01698         if (X11->desktopEnvironment == DE_UNKNOWN){
01699             Atom type;
01700             int format;
01701             unsigned long length, after;
01702             uchar *data = 0;
01703 
01704             if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(DTWM_IS_RUNNING),
01705                                    0, 1, False, AnyPropertyType, &type, &format, &length,
01706                                    &after, &data) == Success && length) {
01707                 // DTWM is running, meaning most likely CDE is running...
01708                 X11->desktopEnvironment = DE_CDE;
01709             } else if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
01710                                           ATOM(GNOME_BACKGROUND_PROPERTIES), 0, 1, False, AnyPropertyType,
01711                                           &type, &format, &length, &after, &data) == Success && length) {
01712                 X11->desktopEnvironment = DE_GNOME;
01713             } else if ((XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(KDE_FULL_SESSION),
01714                                            0, 1, False, AnyPropertyType, &type, &format, &length, &after, &data) == Success
01715                         && length)
01716                        || (XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(KWIN_RUNNING),
01717                                               0, 1, False, AnyPropertyType, &type, &format, &length,
01718                                               &after, &data) == Success
01719                            && length)
01720                        || (XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(KWM_RUNNING),
01721                                               0, 1, False, AnyPropertyType, &type, &format, &length,
01722                                               &after, &data) == Success && length)) {
01723                 X11->desktopEnvironment = DE_KDE;
01724             }
01725             if (data)
01726                 XFree((char *)data);
01727         }
01728 
01729         qt_set_input_encoding();
01730 
01731         qt_set_x11_resources(appFont, appFGCol, appBGCol, appBTNCol);
01732 
01733         // be smart about the size of the default font. most X servers have helvetica
01734         // 12 point available at 2 resolutions:
01735         //     75dpi (12 pixels) and 100dpi (17 pixels).
01736         // At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17
01737         // pixel font is a closer match than a 12 pixel font
01738         int ptsz = (X11->use_xrender
01739                     ? 9
01740                     : (int) (((QX11Info::appDpiY() >= 95 ? 17. : 12.) *
01741                               72. / (float) QX11Info::appDpiY()) + 0.5));
01742 
01743         if (!qt_app_has_font) {
01744             QFont f(X11->has_fontconfig ? QLatin1String("Sans Serif") : QLatin1String("Helvetica"),
01745                     ptsz);
01746             QApplication::setFont(f);
01747         }
01748 
01749 #if !defined (QT_NO_TABLET)
01750         if (isXInputSupported(X11->display)) {
01751             int ndev,
01752                 i,
01753                 j;
01754             bool gotStylus,
01755                 gotEraser;
01756             XDeviceInfo *devices, *devs;
01757             XInputClassInfo *ip;
01758             XAnyClassPtr any;
01759             XValuatorInfoPtr v;
01760             XAxisInfoPtr a;
01761             XDevice *dev;
01762 
01763 #if !defined(Q_OS_IRIX)
01764             // XFree86 divides a stylus and eraser into 2 devices, so we must do for both...
01765             const QString XFREENAMESTYLUS = QLatin1String("stylus");
01766             const QString XFREENAMEPEN = QLatin1String("pen");
01767             const QString XFREENAMEERASER = QLatin1String("eraser");
01768 #endif
01769 
01770             devices = XListInputDevices(X11->display, &ndev);
01771             if (!devices) {
01772                 qWarning("QApplication: Failed to get list of devices");
01773                 ndev = -1;
01774             }
01775             QTabletEvent::TabletDevice deviceType;
01776             dev = 0;
01777             for (devs = devices, i = 0; i < ndev; i++, devs++) {
01778                 gotStylus = false;
01779                 gotEraser = false;
01780 
01781                 QString devName = QString::fromLocal8Bit(devs->name).toLower();
01782 #if defined(Q_OS_IRIX)
01783                 if (devName == QLatin1String(WACOM_NAME)) {
01784                     deviceType = QTabletEvent::Stylus;
01785                     gotStylus = true;
01786                 }
01787 #else
01788                 if (devName.startsWith(XFREENAMEPEN)
01789                     || devName.startsWith(XFREENAMESTYLUS)) {
01790                     deviceType = QTabletEvent::Stylus;
01791                     gotStylus = true;
01792                 } else if (devName.startsWith(XFREENAMEERASER)) {
01793                     deviceType = QTabletEvent::XFreeEraser;
01794                     gotEraser = true;
01795                 }
01796 #endif
01797 
01798                 if (gotStylus || gotEraser) {
01799                     dev = XOpenDevice(X11->display, devs->id);
01800 
01801                     if (!dev)
01802                         continue;
01803 
01804                     QTabletDeviceData device_data;
01805                     device_data.deviceType = deviceType;
01806                     device_data.eventCount = 0;
01807                     device_data.device = dev;
01808                     device_data.xinput_motion = -1;
01809                     device_data.xinput_key_press = -1;
01810                     device_data.xinput_key_release = -1;
01811                     device_data.xinput_button_press = -1;
01812                     device_data.xinput_button_release = -1;
01813                     device_data.xinput_proximity_in = -1;
01814                     device_data.xinput_proximity_out = -1;
01815 
01816                     if (dev->num_classes > 0) {
01817                         for (ip = dev->classes, j = 0; j < devs->num_classes;
01818                              ip++, j++) {
01819                             switch (ip->input_class) {
01820                             case KeyClass:
01821                                 DeviceKeyPress(dev, device_data.xinput_key_press,
01822                                                device_data.eventList[device_data.eventCount]);
01823                                 if (device_data.eventList[device_data.eventCount])
01824                                     ++device_data.eventCount;
01825                                 DeviceKeyRelease(dev, device_data.xinput_key_release,
01826                                                  device_data.eventList[device_data.eventCount]);
01827                                 if (device_data.eventList[device_data.eventCount])
01828                                     ++device_data.eventCount;
01829                                 break;
01830                             case ButtonClass:
01831                                 DeviceButtonPress(dev, device_data.xinput_button_press,
01832                                                   device_data.eventList[device_data.eventCount]);
01833                                 if (device_data.eventList[device_data.eventCount])
01834                                     ++device_data.eventCount;
01835                                 DeviceButtonRelease(dev, device_data.xinput_button_release,
01836                                                     device_data.eventList[device_data.eventCount]);
01837                                 if (device_data.eventList[device_data.eventCount])
01838                                     ++device_data.eventCount;
01839                                 break;
01840                             case ValuatorClass:
01841                                 // I'm only going to be interested in motion when the
01842                                 // stylus is already down anyway!
01843                                 DeviceMotionNotify(dev, device_data.xinput_motion,
01844                                                    device_data.eventList[device_data.eventCount]);
01845                                 if (device_data.eventList[device_data.eventCount])
01846                                     ++device_data.eventCount;
01847                                 ProximityIn(dev, device_data.xinput_proximity_in, device_data.eventList[device_data.eventCount]);
01848                                 if (device_data.eventList[device_data.eventCount])
01849                                     ++device_data.eventCount;
01850                                 ProximityOut(dev, device_data.xinput_proximity_out, device_data.eventList[device_data.eventCount]);
01851                                 if (device_data.eventList[device_data.eventCount])
01852                                     ++device_data.eventCount;
01853                             default:
01854                                 break;
01855                             }
01856                         }
01857                     }
01858 
01859                     // get the min/max value for pressure!
01860                     any = (XAnyClassPtr) (devs->inputclassinfo);
01861                     for (j = 0; j < devs->num_classes; j++) {
01862                         if (any->c_class == ValuatorClass) {
01863                             v = (XValuatorInfoPtr) any;
01864                             a = (XAxisInfoPtr) ((char *) v +
01865                                                 sizeof (XValuatorInfo));
01866 #if defined (Q_OS_IRIX)
01867                             // I'm not exaclty wild about this, but the
01868                             // dimensions of the tablet are more relevant here
01869                             // than the min and max values from the axis
01870                             // (actually it seems to be 2/3 or what is in the
01871                             // axis.  So we'll try to parse it from this
01872                             // string. --tws
01873                             char returnString[SGIDeviceRtrnLen];
01874                             int tmp;
01875                             if (XSGIMiscQueryExtension(X11->display, &tmp, &tmp)
01876                                 && XSGIDeviceQuery(X11->display, devs->id,
01877                                                    "dimensions", returnString)) {
01878                                 QString str = QLatin1String(returnString);
01879                                 int comma = str.indexOf(',');
01880                                 device_data.minX = 0;
01881                                 device_data.minY = 0;
01882                                 device_data.maxX = str.left(comma).toInt();
01883                                 device_data.maxY = str.mid(comma + 1).toInt();
01884                             } else {
01885                                 device_data.minX = a[WAC_XCOORD_I].min_value;
01886                                 device_data.maxX = a[WAC_XCOORD_I].max_value;
01887                                 device_data.minY = a[WAC_YCOORD_I].min_value;
01888                                 device_data.maxY = a[WAC_YCOORD_I].max_value;
01889                             }
01890                             device_data.minPressure = a[WAC_PRESSURE_I].min_value;
01891                             device_data.maxPressure = a[WAC_PRESSURE_I].max_value;
01892                             device_data.minTanPressure = a[WAC_TAN_PRESSURE_I].min_value;
01893                             device_data.maxTanPressure = a[WAC_TAN_PRESSURE_I].max_value;
01894                             device_data.minZ = a[WAC_ZCOORD_I].min_value;
01895                             device_data.maxZ = a[WAC_ZCOORD_I].max_value;
01896 #else
01897                             device_data.minX = a[0].min_value;
01898                             device_data.maxX = a[0].max_value;
01899                             device_data.minY = a[1].min_value;
01900                             device_data.maxY = a[1].max_value;
01901                             device_data.minPressure = a[2].min_value;
01902                             device_data.maxPressure = a[2].max_value;
01903                             device_data.minTanPressure = 0;
01904                             device_data.maxTanPressure = 0;
01905                             device_data.minZ = 0;
01906                             device_data.maxZ = 0;
01907 #endif
01908 
01909                             // got the max pressure no need to go further...
01910                             break;
01911                         }
01912                         any = (XAnyClassPtr) ((char *) any + any->length);
01913                     } // end of for loop
01914 
01915                     tablet_devices()->append(device_data);
01916                 } // if (gotStylus || gotEraser)
01917             }
01918             XFreeDeviceList(devices);
01919         }
01920 #endif // QT_NO_TABLET
01921 
01922         X11->startupId = getenv("DESKTOP_STARTUP_ID");
01923         putenv(strdup("DESKTOP_STARTUP_ID="));
01924 
01925    } else {
01926         // read some non-GUI settings when not using the X server...
01927 
01928         if (QApplication::desktopSettingsAware()) {
01929             QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
01930             settings.beginGroup(QLatin1String("Qt"));
01931 
01932             // read library (ie. plugin) path list
01933             QString libpathkey = QString(QLatin1String("%1.%2/libraryPath"))
01934                                  .arg(QT_VERSION >> 16)
01935                                  .arg((QT_VERSION & 0xff00) >> 8);
01936             QStringList pathlist =
01937                 settings.value(libpathkey).toString().split(QLatin1Char(':'));
01938             if (! pathlist.isEmpty()) {
01939                 QStringList::ConstIterator it = pathlist.constBegin();
01940                 while (it != pathlist.constEnd())
01941                     QApplication::addLibraryPath(*it++);
01942             }
01943 
01944             QString defaultcodec = settings.value(QLatin1String("defaultCodec"),
01945                                                   QVariant(QLatin1String("none"))).toString();
01946             if (defaultcodec != QLatin1String("none")) {
01947                 QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1());
01948                 if (codec)
01949                     QTextCodec::setCodecForTr(codec);
01950             }
01951 
01952             settings.endGroup(); // Qt
01953         }
01954     }
01955 }

Here is the call graph for this function:

Q_GUI_EXPORT bool qt_tryModalHelper ( QWidget widget,
QWidget **  rettop 
)

Definition at line 2236 of file qapplication.cpp.

References QApplicationPrivate::tryModalHelper().

02237 {
02238     return QApplicationPrivate::tryModalHelper(widget, rettop);
02239 }

Here is the call graph for this function:


Variable Documentation

int aargc = 1 [static]

Definition at line 675 of file qapplication.cpp.

char* aargv[] = { (char*)"unknown", 0 } [static]

Definition at line 676 of file qapplication.cpp.

int drag_distance = 4 [static]

Definition at line 380 of file qapplication.cpp.

Referenced by QApplication::setStartDragDistance(), QApplication::startDragDistance(), and QApplication::~QApplication().

int drag_time = 500 [static]

Definition at line 379 of file qapplication.cpp.

Referenced by QApplication::setStartDragTime(), QApplication::startDragTime(), and QApplication::~QApplication().

bool force_reverse = false [static]

Definition at line 398 of file qapplication.cpp.

Referenced by QApplicationPrivate::process_cmdline(), and qt_detectRTLLanguage().

Qt::LayoutDirection layout_direction = Qt::LeftToRight [static]

Definition at line 381 of file qapplication.cpp.

Referenced by QApplication::layoutDirection(), qt_format_text(), QApplication::setLayoutDirection(), and QApplication::~QApplication().

int qt_antialiasing_threshold = -1

Definition at line 378 of file qapplication.cpp.

bool qt_app_has_font = false

Definition at line 363 of file qapplication.cpp.

Referenced by qt_set_x11_resources(), QApplication::setFont(), and QApplication::~QApplication().

QApplication::Type qt_appType = QApplication::Tty

Definition at line 76 of file qapplication.cpp.

Referenced by QApplicationPrivate::initialize(), QApplicationPrivate::QApplicationPrivate(), and QApplication::type().

QClipboard* qt_clipboard = 0

Definition at line 421 of file qapplication.cpp.

Referenced by QApplication::clipboard(), and QApplication::~QApplication().

QDesktopWidget* qt_desktopWidget = 0

Definition at line 419 of file qapplication.cpp.

Referenced by QApplication::desktop(), and QApplication::~QApplication().

bool qt_in_tab_key_event = false

Definition at line 377 of file qapplication.cpp.

Referenced by QApplicationPrivate::focusNextPrevChild_helper(), QApplication::notify(), and QApplicationPrivate::setFocusWidget().

bool qt_is_gui_used

Definition at line 375 of file qapplication.cpp.

Referenced by QApplicationPrivate::process_cmdline(), qt_defaultDpi(), QApplication::style(), and QApplication::~QApplication().

QWidgetList* qt_modal_stack = 0

Definition at line 423 of file qapplication.cpp.

Referenced by QApplication::activeModalWidget(), QApplicationPrivate::enterModal_sys(), QApplicationPrivate::isBlockedByModal(), and QApplicationPrivate::leaveModal_sys().

bool Q_GUI_EXPORT qt_tab_all_widgets = true

Definition at line 376 of file qapplication.cpp.

Referenced by QApplicationPrivate::focusNextPrevChild_helper(), and QX11EmbedWidgetPrivate::getFocusWidget().

bool qt_tabletChokeMouse = false

Definition at line 397 of file qapplication.cpp.

Referenced by QApplication::notify(), and QETWidget::translateMouseEvent().


Generated on Thu Mar 15 13:24:55 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1