⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qapplication_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    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 &);void QWSDisplay::Data::translateExpose(QWSRegionModifiedEvent *re, const QPoint &p){    for (int i = 0; i < re->simpleData.nrectangles; i++)        re->rectangles[i].translate(p.x(), p.y());}#endifvoid QWSDisplay::Data::create(int n){    QWSCreateCommand cmd(n);    sendCommand(cmd);}void QWSDisplay::Data::flushCommands(){#ifndef QT_NO_QWS_MULTIPROCESS    if  (csocket)        csocket->flush();#endif}void QWSDisplay::Data::sendCommand(QWSCommand & cmd){#ifndef QT_NO_QWS_MULTIPROCESS    if  (csocket)        cmd.write(csocket);    else#endif        qt_server_enqueue(&cmd);}void QWSDisplay::Data::sendSynchronousCommand(QWSCommand & cmd){#ifndef QT_NO_QWS_MULTIPROCESS    if  (csocket) {        lockClient(QWSLock::Communication);        cmd.write(csocket);        csocket->waitForBytesWritten();        waitClient(QWSLock::Communication);    } else#endif        qt_server_enqueue(&cmd);}int QWSDisplay::Data::takeId(){    if (unused_identifiers.count() == 10)        create(15);    if (unused_identifiers.count() == 0)        waitForCreation();    return unused_identifiers.takeFirst();}void QWSDisplay::Data::setMouseFilter(void (*filter)(QWSMouseEvent*)){    mouseFilter = filter;}#ifndef QT_NO_QWS_MULTIPROCESSQWSLock* QWSDisplay::Data::clientLock = 0;void Q_GUI_EXPORT qt_app_reinit( const QString& newAppName ){    qt_fbdpy->d->reinit( newAppName );}#endif // QT_NO_QWS_MULTIPROCESSclass QDesktopWidget;#ifndef QT_NO_QWS_MULTIPROCESSvoid QWSDisplay::Data::reinit( const QString& newAppName ){    Q_ASSERT(csocket);    delete connected_event;    connected_event = 0;//    region_ack = 0;    delete mouse_event;    mouse_event = 0;//    region_event = 0;    region_offset_window = 0;#ifndef QT_NO_COP    delete qcop_response;    qcop_response = 0;#endif    delete current_event;    current_event = 0;#ifdef QAPPLICATION_EXTRA_DEBUG    mouse_event_count = 0;#endif    mouseFilter = 0;    qt_desktopWidget = 0;    delete QWSDisplay::Data::clientLock;    QWSDisplay::Data::clientLock = 0;    QString pipe = qws_qtePipeFilename();    // QWS client    // Cleanup all cached ids    unused_identifiers.clear();    delete csocket;    appName = newAppName;    qApp->setObjectName( appName );    csocket = new QWSSocket();    QObject::connect(csocket, SIGNAL(disconnected()),                     qApp, SLOT(quit()));    csocket->connectToLocalFile(pipe);    QWSDisplay::Data::clientLock = new QWSLock();    QWSIdentifyCommand cmd;    cmd.setId(appName, QWSDisplay::Data::clientLock->id());#ifndef QT_NO_SXE    QTransportAuth *a = QTransportAuth::getInstance();    QTransportAuth::Data *d = a->connectTransport(            QTransportAuth::UnixStreamSock |            QTransportAuth::Trusted,            csocket->socketDescriptor());    QAuthDevice *ad = a->authBuf( d, csocket );    ad->setClient( csocket );    cmd.write(ad);#else    cmd.write(csocket);#endif    // wait for connect confirmation    waitForConnection();    qws_client_id = connected_event->simpleData.clientId;    if (!QWSDisplay::initLock(pipe, false))        qFatal("Cannot get display lock");    if (shm.attach(connected_event->simpleData.servershmid)) {        sharedRam = static_cast<uchar *>(shm.address());        QScreen *s = qt_get_screen(qws_display_id, qws_display_spec.constData());        if (s)            sharedRamSize += s->memoryNeeded(QLatin1String(qws_display_spec.constData()));    } else {        perror("QWSDisplay::Data::init");        qFatal("Client can't attach to main ram memory.");    }    qApp->desktop();    // We wait for creation mainly so that we can process important    // initialization events such as MaxWindowRect that are sent    // before object id creation.  Waiting here avoids later window    // resizing since we have the MWR before windows are displayed.    waitForCreation();    sharedRamSize -= sizeof(int);    qt_last_x = reinterpret_cast<int *>(sharedRam + sharedRamSize);    sharedRamSize -= sizeof(int);    qt_last_y = reinterpret_cast<int *>(sharedRam + sharedRamSize);#ifndef QT_NO_COP    QCopChannel::reregisterAll();#endif    csocket->flush();}#endifvoid QWSDisplay::Data::init(){    connected_event = 0;//    region_ack = 0;    mouse_event = 0;    mouse_state = -1;    mouse_winid = 0;//    region_event = 0;    region_offset_window = 0;#ifndef QT_NO_COP    qcop_response = 0;#endif    current_event = 0;#ifdef QAPPLICATION_EXTRA_DEBUG    mouse_event_count = 0;#endif    mouseFilter = 0;    QString pipe = qws_qtePipeFilename();    sharedRamSize = qwsSharedRamSize;#ifndef QT_NO_QWS_MULTIPROCESS    if (csocket)    {        // QWS client        connectToPipe();        QWSDisplay::Data::clientLock = new QWSLock();        QWSIdentifyCommand cmd;        cmd.setId(appName, QWSDisplay::Data::clientLock->id());#ifndef QT_NO_SXE        QTransportAuth *a = QTransportAuth::getInstance();        QTransportAuth::Data *d = a->connectTransport(                QTransportAuth::UnixStreamSock |                QTransportAuth::Trusted,                csocket->socketDescriptor());        QAuthDevice *ad = a->authBuf( d, csocket );        ad->setClient( csocket );        cmd.write(ad);#else        cmd.write(csocket);#endif        // create(30); // not necessary, server will send ids anyway        waitForConnection();        qws_client_id = connected_event->simpleData.clientId;        // now we want to get the exact display spec to use if we haven't        // specified anything.        if (qws_display_spec.at(0) == ':')            qws_display_spec = connected_event->display;        if (!QWSDisplay::initLock(pipe, false))            qFatal("Cannot get display lock");        if (shm.attach(connected_event->simpleData.servershmid)) {            sharedRam = static_cast<uchar *>(shm.address());            QScreen *s = qt_get_screen(qws_display_id, qws_display_spec.constData());            if (s)                sharedRamSize += s->memoryNeeded(QLatin1String(qws_display_spec.constData()));        } else {            perror("QWSDisplay::Data::init");            qFatal("Client can't attach to main ram memory.");        }        // We wait for creation mainly so that we can process important        // initialization events such as MaxWindowRect that are sent        // before object id creation.  Waiting here avoids later window        // resizing since we have the MWR before windows are displayed.        waitForCreation();    } else#endif    {        create(30);        // QWS server        if (!QWSDisplay::initLock(pipe, true))            qFatal("Cannot get display lock");        QScreen *s = qt_get_screen(qws_display_id, qws_display_spec.constData());        if (s)            sharedRamSize += s->memoryNeeded(QLatin1String(qws_display_spec.constData()));#ifndef QT_NO_QWS_MULTIPROCESS        if (!shm.create(sharedRamSize)) {            perror("Cannot create main ram shared memory\n");            qFatal("Unable to allocate %d bytes of shared memory", sharedRamSize);        }        qt_servershmid = shm.id();        sharedRam = static_cast<uchar *>(shm.address());#else        sharedRam=static_cast<uchar *>(malloc(sharedRamSize));#endif        // Need to zero index count at end of block, might as well zero        // the rest too        memset(sharedRam,0,sharedRamSize);        QWSIdentifyCommand cmd;        cmd.setId(appName, -1);        qt_server_enqueue(&cmd);    }    // Allow some memory for the graphics driver too    //### Note that sharedRamSize() has side effects; it must be called    //### once, and only once, and before initDevice()    sharedRamSize -= qt_screen->sharedRamSize(sharedRam+sharedRamSize);#ifndef QT_NO_QWS_MULTIPROCESS    if(!csocket)#endif    {        //QWS server process        qt_screen->initDevice();    }    sharedRamSize -= sizeof(int);    qt_last_x = reinterpret_cast<int *>(sharedRam + sharedRamSize);    sharedRamSize -= sizeof(int);    qt_last_y = reinterpret_cast<int *>(sharedRam + sharedRamSize);    /* Initialise framebuffer memory manager */    /* Add 4k for luck and to avoid clobbering hardware cursor *///    int screensize=qt_screen->screenSize();//     memorymanager=new QMemoryManager(qt_screen->base()+screensize+4096,//         qt_screen->totalSize()-(screensize+4096),0);// #ifndef QT_NO_QWS_MULTIPROCESS//     rgnMan = new QWSRegionManager(pipe, csocket);// #else//     rgnMan = new QWSRegionManager(pipe, 0); //####### not necessary// #endif#ifndef QT_NO_QWS_MULTIPROCESS    if (csocket)        csocket->flush();#endif}QWSEvent* QWSDisplay::Data::readMore(){#ifdef QT_NO_QWS_MULTIPROCESS    return incoming.isEmpty() ? 0 : incoming.takeFirst();#else    if (!csocket)        return incoming.isEmpty() ? 0 : incoming.takeFirst();    // read next event    if (!current_event) {        int event_type = qws_read_uint(csocket);        if (event_type >= 0) {            current_event = QWSEvent::factory(event_type);        }    }    if (current_event) {        if (current_event->read(csocket)) {            // Finished reading a whole event.            QWSEvent* result = current_event;            current_event = 0;            return result;        }    }    // Not finished reading a whole event.    return 0;#endif}void QWSDisplay::Data::fillQueue(){    QWSServer::processEventQueue();    QWSEvent *e = readMore();#ifndef QT_NO_QWS_MULTIPROCESS    int bytesAvailable = csocket ? csocket->bytesAvailable() : 0;    int bytesRead = 0;#endif    while (e) {#ifndef QT_NO_QWS_MULTIPROCESS        bytesRead += 2* sizeof(int) + e->simpleLen + e->rawLen;#endif        if (e->type == QWSEvent::Connected) {            connected_event = static_cast<QWSConnectedEvent *>(e);            return;        } else if (e->type == QWSEvent::Creation) {            QWSCreationEvent *ce = static_cast<QWSCreationEvent*>(e);            int id = ce->simpleData.objectid;            int count = ce->simpleData.count;            for (int i = 0; i < count; ++i)                unused_identifiers.append(id++);            delete e;        } else if (e->type == QWSEvent::Mouse) {            if (!qt_screen) {                delete e;            } else {                QWSMouseEvent *me = static_cast<QWSMouseEvent*>(e);                if (mouseFilter)                    mouseFilter(me);#ifdef QAPPLICATION_EXTRA_DEBUG                static const char *defaultAction= "INITIAL";                const char * action = defaultAction;#endif                delete mouse_event;                if (mouse_winid != me->window ()                    || mouse_state != me->simpleData.state) {                        queue.append(me);                        mouse_winid = me->window();                        mouse_state = me->simpleData.state;                        mouse_event = 0;#ifdef QAPPLICATION_EXTRA_DEBUG                        mouse_event_count = 0;                        action = "ENQUEUE";#endif                } else {#ifdef QAPPLICATION_EXTRA_DEBUG                    if (mouse_event)                        action = "COMPRESS";                    mouse_event_count++;#endif                    mouse_event = me;                }#ifdef QAPPLICATION_EXTRA_DEBUG                if (me->simpleData.state !=0 || action != defaultAction || mouse_event_count != 0)                    qDebug("fillQueue %s (%d,%d), state %x win %d count %d", action,                           me->simpleData.x_root, me->simpleData.y_root, me->simpleData.state,                           me->window(), mouse_event_count);#endif            }#ifndef QT_NO_QWS_MULTIPROCESS        } else if (e->type == QWSEvent::Region && clientLock) {            // not really an unlock, decrements the semaphore            clientLock->unlock(QWSLock::RegionEvent);            queue.append(e);#endif#if 0        } else if (e->type == QWSEvent::RegionModified) {            QWSRegionModifiedEvent *re = static_cast<QWSRegionModifiedEvent *>(e);            if (re->simpleData.is_ack) {                region_ack = re;                region_offset = QPoint();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -