qapplication_qws.cpp
来自「QT 开发环境里面一个很重要的文件」· C++ 代码 · 共 2,229 行 · 第 1/5 页
CPP
2,229 行
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qglobal.h"#include "qcursor.h"#include "qapplication.h"#include "private/qapplication_p.h"#include "qwidget.h"#include "qbitarray.h"#include "qpainter.h"#include "qpixmapcache.h"#include "qdatetime.h"#include "qtextcodec.h"#include "qdatastream.h"#include "qbuffer.h"#include "qsocketnotifier.h"#include "qsessionmanager.h"#include "qclipboard.h"#include "qbitmap.h"#include "qwssocket_qws.h"#include "qtransportauth_qws.h"#include "private/qtransportauth_qws_p.h"#include "qwsevent_qws.h"#include "private/qwscommand_qws_p.h"#include "qwsproperty_qws.h"#include "qscreen_qws.h"#include "qcopchannel_qws.h"#include "private/qlock_p.h"#include "private/qwslock_p.h"//#include "qmemorymanager_qws.h"#include "qwsmanager_qws.h"//#include "qwsregionmanager_qws.h"#include "qwindowsystem_qws.h"#include "private/qwindowsystem_p.h"#include "qwsdisplay_qws.h"#include "private/qwsdisplay_qws_p.h"#include "private/qwsinputcontext_p.h"#include "qfile.h"#include "qhash.h"#include "qdesktopwidget.h"#include "qcolormap.h"#include "private/qcursor_p.h"#include "qsettings.h"#include "qdebug.h"#include "qeventdispatcher_qws_p.h"#include "private/qwidget_p.h"#include "private/qbackingstore_p.h"#include "private/qwindowsurface_qws_p.h"#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <locale.h>#include <errno.h>#include <fcntl.h>#include <sys/time.h>#include <sys/stat.h>#include <sys/types.h>#ifndef QT_NO_QWS_MULTIPROCESS#ifdef QT_NO_QSHM#include <sys/ipc.h>#include <sys/shm.h>#ifndef Q_OS_DARWIN# include <sys/sem.h>#endif#include <sys/socket.h>#else#include "private/qsharedmemory_p.h"#endif#endif#ifndef QT_NO_DIRECTPAINTERclass QDirectPainter;extern void qt_directpainter_region(QDirectPainter *dp, const QRegion &alloc, int type);#ifndef QT_NO_QWSEMBEDWIDGETextern void qt_directpainter_embedevent(QDirectPainter *dp, const QWSEmbedEvent *e);#endif#endif // QT_NO_DIRECTPAINTERconst int qwsSharedRamSize = 1 * 1024; // misc data, written by server, read by clientsextern QApplication::Type qt_appType;extern bool qt_app_has_font;//these used to be environment variables, they are initialized from//environment variables inbool qws_savefonts = false;bool qws_screen_is_interlaced=false; //### should be detectedbool qws_shared_memory = false;bool qws_sw_cursor = true;bool qws_accel = true; // ### never setQByteArray qws_display_spec(":0");Q_GUI_EXPORT int qws_display_id = 0;int qws_client_id = 0;QWidget *qt_pressGrab = 0;QWidget *qt_mouseGrb = 0;int *qt_last_x = 0;int *qt_last_y = 0;static int mouse_x_root = -1;static int mouse_y_root = -1;static int mouse_state = 0;int qt_servershmid = -1;bool qws_overrideCursor = false;#ifndef QT_NO_QWS_MANAGER#include "qdecorationfactory_qws.h"static QDecoration *qws_decoration = 0;#endif#if defined(QT_DEBUG)/*extern "C" void dumpmem(const char* m){ static int init=0; static int prev=0; FILE* f = fopen("/proc/meminfo","r"); // char line[100]; int total=0,used=0,free=0,shared=0,buffers=0,cached=0; fscanf(f,"%*[^M]Mem: %d %d %d %d %d %d",&total,&used,&free,&shared,&buffers,&cached); used -= buffers + cached; if (!init) { init=used; } else { printf("%40s: %+8d = %8d\n",m,used-init-prev,used-init); prev = used-init; } fclose(f);}*/#endif// Get the name of the directory where Qtopia Core temporary data should// live.QString qws_dataDir(){ QByteArray dataDir = QString("/tmp/qtembedded-%1").arg(qws_display_id).toLocal8Bit(); if (mkdir(dataDir, 0700)) { if (errno != EEXIST) { qFatal("Cannot create Qtopia Core data directory: %s", dataDir.constData()); } } struct stat buf; if (lstat(dataDir, &buf)) qFatal("stat failed for Qtopia Core data directory: %s", dataDir.constData()); if (!S_ISDIR(buf.st_mode)) qFatal("%s is not a directory", dataDir.constData()); if (buf.st_uid != getuid()) qFatal("Qtopia Core data directory is not owned by user %d", getuid()); if ((buf.st_mode & 0677) != 0600) qFatal("Qtopia Core data directory has incorrect permissions: %s", dataDir.constData()); dataDir += "/"; return QString(dataDir);}// Get the filename of the pipe Qtopia Core uses for server/client commsQ_GUI_EXPORT QString qws_qtePipeFilename(){ return (qws_dataDir() + QString(QTE_PIPE).arg(qws_display_id));}static void setMaxWindowRect(const QRect &rect){ const QList<QScreen*> subScreens = qt_screen->subScreens(); QScreen *screen = qt_screen; for (int i = 0; i < subScreens.size(); ++i) { if (subScreens.at(i)->region().contains(rect)) { screen = subScreens.at(i); break; } } const QSize devSize(screen->deviceWidth(), screen->deviceHeight()); QRect r = screen->mapFromDevice(rect, devSize); QApplicationPrivate *ap = QApplicationPrivate::instance(); ap->setMaxWindowRect(screen, r);}void QApplicationPrivate::setMaxWindowRect(const QScreen *screen, const QRect &rect){ if (maxWindowRects.value(screen) == rect) return; maxWindowRects[screen] = rect; // Re-resize any maximized windows QWidgetList l = QApplication::topLevelWidgets(); for (int i = 0; i < l.size(); ++i) { QWidget *w = l.at(i); QScreen *s = w->d_func()->getScreen(); if (w->isVisible() && w->isMaximized() && s == screen) { w->showNormal(); //#### flicker w->showMaximized(); } }}/***************************************************************************** Internal variables and functions *****************************************************************************/static QString appName; // application namestatic const char *appFont = 0; // application fontstatic const char *appBGCol = 0; // application bg colorstatic const char *appFGCol = 0; // application fg colorstatic const char *appBTNCol = 0; // application btn colorstatic const char *mwGeometry = 0; // main widget geometrystatic const char *mwTitle = 0; // main widget title//static bool mwIconic = false; // main widget iconifiedstatic bool app_do_modal = false; // modal modeQ_GUI_EXPORT QWSDisplay *qt_fbdpy = 0; // QWS `display'QLock *QWSDisplay::lock = 0;static int mouseButtonPressed = 0; // last mouse button pressedstatic int mouseButtonPressTime = 0; // when was a button pressedstatic short mouseXPos, mouseYPos; // mouse position in act windowextern QWidgetList *qt_modal_stack; // stack of modal widgetsstatic QWidget *popupButtonFocus = 0;static QWidget *popupOfPopupButtonFocus = 0;static bool popupCloseDownMode = false;static bool popupGrabOk;static QPointer<QWidget> *mouseInWidget = 0;static bool sm_blockUserInput = false; // session managementQWidget *qt_button_down = 0; // widget got last button-downWId qt_last_cursor = 0xffffffff; // Was -1, but WIds are unsignedclass QWSMouseEvent;class QWSKeyEvent;class QETWidget : public QWidget // event translator widget{public: bool translateMouseEvent(const QWSMouseEvent *, int oldstate); bool translateKeyEvent(const QWSKeyEvent *, bool grab); bool translateRegionEvent(const QWSRegionEvent *);#ifndef QT_NO_QWSEMBEDWIDGET void translateEmbedEvent(const QWSEmbedEvent *event);#endif bool translateWheelEvent(const QWSMouseEvent *me); void repaintDecoration(QRegion r, bool post); void updateRegion(); bool raiseOnClick() { // With limited windowmanagement/taskbar/etc., raising big windows // (eg. spreadsheet) over the top of everything else (eg. calculator) // is just annoying. return !isMaximized() && !isFullScreen(); }};void QApplicationPrivate::createEventDispatcher(){ Q_Q(QApplication); eventDispatcher = (q->type() != QApplication::Tty ? new QEventDispatcherQWS(q) : new QEventDispatcherUNIX(q));}// Single-process stuff. This should maybe move into qwindowsystem_qws.cppstatic bool qws_single_process;static QList<QWSEvent*> incoming;static QList<QWSCommand*> outgoing;void qt_client_enqueue(const QWSEvent *event){ QWSEvent *copy = QWSEvent::factory(event->type); copy->copyFrom(event); incoming.append(copy);}QList<QWSCommand*> *qt_get_server_queue(){ return &outgoing;}void qt_server_enqueue(const QWSCommand *command){ QWSCommand *copy = QWSCommand::factory(command->type); copy->copyFrom(command); outgoing.append(copy);}QWSDisplay::Data::Data(QObject* parent, bool singleProcess){#ifdef QT_NO_QWS_MULTIPROCESS Q_UNUSED(parent); Q_UNUSED(singleProcess);#else if (singleProcess) csocket = 0; else { csocket = new QWSSocket(parent); QObject::connect(csocket, SIGNAL(disconnected()), qApp, SLOT(quit())); } clientLock = 0;#endif init();}QWSDisplay::Data::~Data(){// delete rgnMan; rgnMan = 0;// delete memorymanager; memorymanager = 0; qt_screen->disconnect(); delete qt_screen; qt_screen = 0;#ifndef QT_NO_QWS_CURSOR delete qt_screencursor; qt_screencursor = 0;#endif#ifndef QT_NO_QWS_MULTIPROCESS shm.detach(); if (csocket) { csocket->flush(); // may be pending QCop message, eg. delete csocket; } delete clientLock; clientLock = 0;#endif delete connected_event; delete mouse_event; delete current_event; qDeleteAll(queue);#ifndef QT_NO_COP delete qcop_response;#endif}bool QWSDisplay::Data::lockClient(QWSLock::LockType type, int timeout){ return !clientLock || clientLock->lock(type, timeout);}void QWSDisplay::Data::unlockClient(QWSLock::LockType type){ if (clientLock) clientLock->unlock(type);}bool QWSDisplay::Data::waitClient(QWSLock::LockType type, int timeout){ return !clientLock || clientLock->wait(type, timeout);}QWSLock* QWSDisplay::Data::getClientLock(){ return clientLock;}void QWSDisplay::Data::flush(){#ifndef QT_NO_QWS_MULTIPROCESS if (csocket) { csocket->waitForReadyRead(0); csocket->flush(); }#endif}#if 0void QWSDisplay::Data::debugQueue() { for (int i = 0; i < queue.size(); ++i) { QWSEvent *e = queue.at(i); qDebug( " ev %d type %d sl %d rl %d", i, e->type, e->simpleLen, e->rawLen); }}#endifbool QWSDisplay::Data::queueNotEmpty(){ return mouse_event/*||region_event*/||queue.count() > 0;}QWSEvent* QWSDisplay::Data::dequeue(){ QWSEvent *r=0; if (queue.count()) { r = queue.first(); queue.removeFirst(); } else if (mouse_event) { r = mouse_event; mouse_event = 0;#ifdef QAPPLICATION_EXTRA_DEBUG mouse_event_count = 0;#endif#if 0 } else { r = region_event; region_event = 0;#endif } return r;}QWSEvent* QWSDisplay::Data::peek(){ return queue.first();}bool QWSDisplay::Data::directServerConnection(){#ifndef QT_NO_QWS_MULTIPROCESS return csocket == 0;#else return true;#endif}#if 0void QWSDisplay::Data::offsetPendingExpose(int, const QPoint &);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?