diff options
author | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-07-21 14:16:32 (GMT) |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@nokia.com> | 2010-07-21 14:16:32 (GMT) |
commit | 05e8e8056824dfa56830e12a6a50ec39018df6fc (patch) | |
tree | f1ad05f7600ed63f392c6bbb08bea54f2dd36b82 /src/plugins/platforms | |
parent | 3d0c33f70fb60095f9a1065eceb1ae1aa854af2d (diff) | |
parent | 77d17d054b8baff411613206a099af36f8e0bc43 (diff) | |
download | Qt-05e8e8056824dfa56830e12a6a50ec39018df6fc.zip Qt-05e8e8056824dfa56830e12a6a50ec39018df6fc.tar.gz Qt-05e8e8056824dfa56830e12a6a50ec39018df6fc.tar.bz2 |
Merge remote branch 'lighthouse/4.7' into lighthouse-master
Diffstat (limited to 'src/plugins/platforms')
15 files changed, 173 insertions, 160 deletions
diff --git a/src/plugins/platforms/directfb/qdirectfbinput.cpp b/src/plugins/platforms/directfb/qdirectfbinput.cpp index 90c3348..7101b7b 100644 --- a/src/plugins/platforms/directfb/qdirectfbinput.cpp +++ b/src/plugins/platforms/directfb/qdirectfbinput.cpp @@ -10,89 +10,61 @@ #include <directfb.h> -InputSocketWaiter::InputSocketWaiter(IDirectFBEventBuffer *eventBuffer, QObject *parent) - : QThread(parent), m_eventBuffer(eventBuffer),m_shouldStop(false) +QDirectFbInput::QDirectFbInput(QObject *parent) + : QObject(parent), m_shouldStop(false) { - this->start(); -} + m_dfbInterface = QDirectFbConvenience::dfbInterface(); -InputSocketWaiter::~InputSocketWaiter() -{ - m_shouldStop = true; - m_eventBuffer->WakeUp(m_eventBuffer); - m_cleanupMutex.lock(); -} + DFBResult ok = m_dfbInterface->CreateEventBuffer(m_dfbInterface,&m_eventBuffer); + if (ok != DFB_OK) + DirectFBError("Failed to initialise eventbuffer", ok); + + m_dfbInterface->GetDisplayLayer(m_dfbInterface,DLID_PRIMARY, &m_dfbDisplayLayer); -void InputSocketWaiter::continueWaitingForEvents() -{ - m_finishedProcessingEvents.wakeAll(); } -void InputSocketWaiter::run() +void QDirectFbInput::runInputEventLoop() { - m_cleanupMutex.lock(); - while (1) { + while (true) { m_eventBuffer->WaitForEvent(m_eventBuffer); - if (m_shouldStop) + if (m_shouldStop) { + m_waitStop.release(); break; - emit newEvent(); - QMutex waitForProcessingMutex; - waitForProcessingMutex.lock(); - m_finishedProcessingEvents.wait(&waitForProcessingMutex); - } - m_cleanupMutex.unlock(); -} - -QDirectFbInput *QDirectFbInput::instance() -{ - static QDirectFbInput *input = 0; - if (!input) { - input = new QDirectFbInput(); + } + handleEvents(); } - return input; } -QDirectFbInput::QDirectFbInput() - : QObject() +void QDirectFbInput::stopInputEventLoop() { - dfbInterface = QDirectFbConvenience::dfbInterface(); - - DFBResult ok = dfbInterface->CreateEventBuffer(dfbInterface,&eventBuffer); - if (ok != DFB_OK) - DirectFBError("Failed to initialise eventbuffer", ok); - - dfbInterface->GetDisplayLayer(dfbInterface,DLID_PRIMARY, &dfbDisplayLayer); - - m_inputHandler = new InputSocketWaiter(eventBuffer,this); - connect(m_inputHandler,SIGNAL(newEvent()),this,SLOT(handleEvents())); - - connect(QApplication::instance(),SIGNAL(aboutToQuit()),SLOT(applicationEnd())); + m_shouldStop = true; + m_waitStop.acquire(); } void QDirectFbInput::addWindow(DFBWindowID id, QWidget *tlw) { - tlwMap.insert(id,tlw); + m_tlwMap.insert(id,tlw); IDirectFBWindow *window; - dfbDisplayLayer->GetWindow(dfbDisplayLayer,id,&window); + m_dfbDisplayLayer->GetWindow(m_dfbDisplayLayer,id,&window); - window->AttachEventBuffer(window,eventBuffer); + window->AttachEventBuffer(window,m_eventBuffer); } void QDirectFbInput::removeWindow(WId wId) { IDirectFBWindow *window; - dfbDisplayLayer->GetWindow(dfbDisplayLayer,wId, &window); + m_dfbDisplayLayer->GetWindow(m_dfbDisplayLayer,wId, &window); - window->DetachEventBuffer(window,eventBuffer); - tlwMap.remove(wId); + window->DetachEventBuffer(window,m_eventBuffer); + m_tlwMap.remove(wId); } void QDirectFbInput::handleEvents() { - DFBResult hasEvent = eventBuffer->HasEvent(eventBuffer); + DFBResult hasEvent = m_eventBuffer->HasEvent(m_eventBuffer); while(hasEvent == DFB_OK){ DFBEvent event; - DFBResult ok = eventBuffer->GetEvent(eventBuffer,&event); + DFBResult ok = m_eventBuffer->GetEvent(m_eventBuffer,&event); if (ok != DFB_OK) DirectFBError("Failed to get event",ok); if (event.clazz == DFEC_WINDOW) { @@ -118,9 +90,8 @@ void QDirectFbInput::handleEvents() } - hasEvent = eventBuffer->HasEvent(eventBuffer); + hasEvent = m_eventBuffer->HasEvent(m_eventBuffer); } - m_inputHandler->continueWaitingForEvents(); } void QDirectFbInput::handleMouseEvents(const DFBEvent &event) @@ -140,22 +111,16 @@ void QDirectFbInput::handleMouseEvents(const DFBEvent &event) } else if (event.window.type == DWET_BUTTONUP) { window->UngrabPointer(window); } - QWidget *tlw = tlwMap.value(event.window.window_id); + QWidget *tlw = m_tlwMap.value(event.window.window_id); QWindowSystemInterface::handleMouseEvent(tlw, timestamp, p, globalPos, buttons); } -void QDirectFbInput::applicationEnd() -{ - delete m_inputHandler; - m_inputHandler = 0; -} - void QDirectFbInput::handleWheelEvent(const DFBEvent &event) { QPoint p(event.window.cx, event.window.cy); QPoint globalPos = globalPoint(event); long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000); - QWidget *tlw = tlwMap.value(event.window.window_id); + QWidget *tlw = m_tlwMap.value(event.window.window_id); QWindowSystemInterface::handleWheelEvent(tlw, timestamp, p, globalPos, event.window.step*120, Qt::Vertical); @@ -172,13 +137,13 @@ void QDirectFbInput::handleKeyEvents(const DFBEvent &event) QChar character; if (DFB_KEY_TYPE(event.window.key_symbol) == DIKT_UNICODE) character = QChar(event.window.key_symbol); - QWidget *tlw = tlwMap.value(event.window.window_id); + QWidget *tlw = m_tlwMap.value(event.window.window_id); QWindowSystemInterface::handleKeyEvent(tlw, timestamp, type, key, modifiers, character); } void QDirectFbInput::handleEnterLeaveEvents(const DFBEvent &event) { - QWidget *tlw = tlwMap.value(event.window.window_id); + QWidget *tlw = m_tlwMap.value(event.window.window_id); switch (event.window.type) { case DWET_ENTER: QWindowSystemInterface::handleEnterEvent(tlw); @@ -194,7 +159,7 @@ void QDirectFbInput::handleEnterLeaveEvents(const DFBEvent &event) inline QPoint QDirectFbInput::globalPoint(const DFBEvent &event) const { IDirectFBWindow *window; - dfbDisplayLayer->GetWindow(dfbDisplayLayer,event.window.window_id,&window); + m_dfbDisplayLayer->GetWindow(m_dfbDisplayLayer,event.window.window_id,&window); int x,y; window->GetPosition(window,&x,&y); return QPoint(event.window.cx +x, event.window.cy + y); diff --git a/src/plugins/platforms/directfb/qdirectfbinput.h b/src/plugins/platforms/directfb/qdirectfbinput.h index 016e7f1..0b2e7ed 100644 --- a/src/plugins/platforms/directfb/qdirectfbinput.h +++ b/src/plugins/platforms/directfb/qdirectfbinput.h @@ -1,9 +1,7 @@ #ifndef QDIRECTFBINPUT_H #define QDIRECTFBINPUT_H -#include <QThread> -#include <QMutex> -#include <QWaitCondition> +#include <QSemaphore> #include <QObject> #include <QHash> #include <QPoint> @@ -13,53 +11,35 @@ #include <directfb.h> -class InputSocketWaiter : public QThread -{ - Q_OBJECT -public: - InputSocketWaiter(IDirectFBEventBuffer *eventBuffer, QObject *parent); - virtual ~InputSocketWaiter(); - void continueWaitingForEvents(); -protected: - void run(); -signals: - void newEvent(); -private: - IDirectFBEventBuffer *m_eventBuffer; - bool m_shouldStop; - QMutex m_cleanupMutex; - QWaitCondition m_finishedProcessingEvents; -}; - class QDirectFbInput : public QObject { Q_OBJECT public: - static QDirectFbInput *instance(); + QDirectFbInput(QObject *parent); void addWindow(DFBWindowID id, QWidget *tlw); void removeWindow(WId wId); public slots: + void runInputEventLoop(); + void stopInputEventLoop(); void handleEvents(); - void applicationEnd(); private: - QDirectFbInput(); - void handleMouseEvents(const DFBEvent &event); void handleWheelEvent(const DFBEvent &event); void handleKeyEvents(const DFBEvent &event); void handleEnterLeaveEvents(const DFBEvent &event); - IDirectFB *dfbInterface; - IDirectFBDisplayLayer *dfbDisplayLayer; - IDirectFBEventBuffer *eventBuffer; + inline QPoint globalPoint(const DFBEvent &event) const; - QHash<DFBWindowID,QWidget *>tlwMap; - inline QPoint globalPoint(const DFBEvent &event) const; + IDirectFB *m_dfbInterface; + IDirectFBDisplayLayer *m_dfbDisplayLayer; + IDirectFBEventBuffer *m_eventBuffer; - InputSocketWaiter *m_inputHandler; + bool m_shouldStop; + QSemaphore m_waitStop; + QHash<DFBWindowID,QWidget *>m_tlwMap; }; #endif // QDIRECTFBINPUT_H diff --git a/src/plugins/platforms/directfb/qdirectfbintegration.cpp b/src/plugins/platforms/directfb/qdirectfbintegration.cpp index 60fce7e..c47fc8d 100644 --- a/src/plugins/platforms/directfb/qdirectfbintegration.cpp +++ b/src/plugins/platforms/directfb/qdirectfbintegration.cpp @@ -49,9 +49,10 @@ #include <private/qwindowsurface_raster_p.h> #include <private/qpixmap_raster_p.h> -#include <private/qpixmap_blitter_p.h> -#include <private/qpixmapdata_p.h> -#include <QCoreApplication> +#include <QtGui/private/qpixmap_blitter_p.h> +#include <QtGui/private/qpixmapdata_p.h> +#include <QtCore/QCoreApplication> +#include <QtCore/QThread> QT_BEGIN_NAMESPACE @@ -94,8 +95,22 @@ QDirectFbIntegration::QDirectFbIntegration() } delete[] argv; + QDirectFbScreen *primaryScreen = new QDirectFbScreen(0); mScreens.append(primaryScreen); + + mInputRunner = new QThread; + mInput = new QDirectFbInput(0); + mInput->moveToThread(mInputRunner); + QObject::connect(mInputRunner,SIGNAL(started()),mInput,SLOT(runInputEventLoop())); + mInputRunner->start(); +} + +QDirectFbIntegration::~QDirectFbIntegration() +{ + mInput->stopInputEventLoop(); + delete mInputRunner; + delete mInput; } QPixmapData *QDirectFbIntegration::createPixmapData(QPixmapData::PixelType type) const @@ -109,7 +124,8 @@ QPixmapData *QDirectFbIntegration::createPixmapData(QPixmapData::PixelType type) QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWidget *widget, WId winId) const { Q_UNUSED(winId); - return new QDirectFbWindow(widget); + QDirectFbInput *input = const_cast<QDirectFbInput *>(mInput);//gah + return new QDirectFbWindow(widget,input); } QWindowSurface *QDirectFbIntegration::createWindowSurface(QWidget *widget, WId winId) const diff --git a/src/plugins/platforms/directfb/qdirectfbintegration.h b/src/plugins/platforms/directfb/qdirectfbintegration.h index c0e770f..27847e2 100644 --- a/src/plugins/platforms/directfb/qdirectfbintegration.h +++ b/src/plugins/platforms/directfb/qdirectfbintegration.h @@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE +class QThread; class QDirectFBCursor; class QDirectFbScreen : public QPlatformScreen @@ -81,6 +82,7 @@ class QDirectFbIntegration : public QPlatformIntegration { public: QDirectFbIntegration(); + ~QDirectFbIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const; @@ -89,10 +91,10 @@ public: QList<QPlatformScreen *> screens() const { return mScreens; } - - private: QList<QPlatformScreen *> mScreens; + QDirectFbInput *mInput; + QThread *mInputRunner; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/directfb/qdirectfbwindow.cpp b/src/plugins/platforms/directfb/qdirectfbwindow.cpp index d88953e..30e6f5a 100644 --- a/src/plugins/platforms/directfb/qdirectfbwindow.cpp +++ b/src/plugins/platforms/directfb/qdirectfbwindow.cpp @@ -45,8 +45,8 @@ #include <directfb.h> -QDirectFbWindow::QDirectFbWindow(QWidget *tlw) - : QPlatformWindow(tlw) +QDirectFbWindow::QDirectFbWindow(QWidget *tlw, QDirectFbInput *inputhandler) + : QPlatformWindow(tlw), m_inputHandler(inputhandler) { IDirectFBDisplayLayer *layer = QDirectFbConvenience::dfbDisplayLayer(); DFBDisplayLayerConfig layerConfig; @@ -83,12 +83,12 @@ QDirectFbWindow::QDirectFbWindow(QWidget *tlw) DFBWindowID id; m_dfbWindow->GetID(m_dfbWindow, &id); - QDirectFbInput::instance()->addWindow(id,tlw); + m_inputHandler->addWindow(id,tlw); } QDirectFbWindow::~QDirectFbWindow() { - QDirectFbInput::instance()->removeWindow(winId()); + m_inputHandler->removeWindow(winId()); m_dfbWindow->Destroy(m_dfbWindow); } diff --git a/src/plugins/platforms/directfb/qdirectfbwindow.h b/src/plugins/platforms/directfb/qdirectfbwindow.h index d5fd408..b512afd 100644 --- a/src/plugins/platforms/directfb/qdirectfbwindow.h +++ b/src/plugins/platforms/directfb/qdirectfbwindow.h @@ -45,13 +45,14 @@ #include <QPlatformWindow> #include "qdirectfbconvenience.h" +#include "qdirectfbinput.h" QT_BEGIN_NAMESPACE class QDirectFbWindow : public QPlatformWindow { public: - QDirectFbWindow(QWidget *tlw); + QDirectFbWindow(QWidget *tlw, QDirectFbInput *inputhandler); ~QDirectFbWindow(); void setGeometry(const QRect &rect); @@ -66,6 +67,8 @@ public: private: IDirectFBWindow *m_dfbWindow; + QDirectFbInput *m_inputHandler; + }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/openkode.pro b/src/plugins/platforms/openkode/openkode.pro index c039131..2d90b15 100644 --- a/src/plugins/platforms/openkode/openkode.pro +++ b/src/plugins/platforms/openkode/openkode.pro @@ -10,13 +10,15 @@ SOURCES = main.cpp \ qopenkodewindowsurface.cpp \ qopenkodewindow.cpp \ ../eglconvenience/qeglplatformcontext.cpp \ - ../eglconvenience/qeglconvenience.cpp + ../eglconvenience/qeglconvenience.cpp \ + qopenkodeeventloopintegration.cpp HEADERS = qopenkodeintegration.h \ qopenkodewindowsurface.h \ qopenkodewindow.h \ ../eglconvenience/qeglplatformcontext.h \ - ../eglconvenience/qeglconvenience.h + ../eglconvenience/qeglconvenience.h \ + qopenkodeeventloopintegration.h RESOURCES = resources.qrc diff --git a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp new file mode 100644 index 0000000..467b5b5 --- /dev/null +++ b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp @@ -0,0 +1,29 @@ +#include "qopenkodeeventloopintegration.h" + +#include <KD/kd.h> + +#include <QtCore/QDebug> + +QOpenKODEEventLoopIntegration::QOpenKODEEventLoopIntegration() +{ + m_kdThread = kdThreadSelf(); +} + +void QOpenKODEEventLoopIntegration::processEvents(qint64 msec) +{ + if (msec == 0) + msec = -1; + const KDEvent *event = kdWaitEvent(msec*1000); + if (event) { + kdDefaultEvent(event); + while ((event = kdWaitEvent(0)) != 0) { + kdDefaultEvent(event); + } + } +} + +void QOpenKODEEventLoopIntegration::wakeup() +{ + KDEvent *event = kdCreateEvent(); + kdPostThreadEvent(event,m_kdThread); +} diff --git a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h new file mode 100644 index 0000000..ef04640 --- /dev/null +++ b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h @@ -0,0 +1,17 @@ +#ifndef QOPENKODEEVENTLOOPINTEGRATION_H +#define QOPENKODEEVENTLOOPINTEGRATION_H + +#include <QtGui/QPlatformEventLoopIntegration> + +class KDThread; +class QOpenKODEEventLoopIntegration : public QPlatformEventLoopIntegration +{ +public: + QOpenKODEEventLoopIntegration(); + void processEvents(qint64 msec); + void wakeup(); +private: + KDThread *m_kdThread; +}; + +#endif // QOPENKODEEVENTLOOPINTEGRATION_H diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.cpp b/src/plugins/platforms/openkode/qopenkodeintegration.cpp index 270763b..5dada28 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.cpp +++ b/src/plugins/platforms/openkode/qopenkodeintegration.cpp @@ -42,6 +42,7 @@ #include "qopenkodeintegration.h" #include "qopenkodewindowsurface.h" #include "qopenkodewindow.h" +#include "qopenkodeeventloopintegration.h" #include <QtOpenGL/private/qpixmapdata_gl_p.h> #include <QtOpenGL/private/qwindowsurface_gl_p.h> @@ -184,41 +185,11 @@ static GLuint loadShaders(const QString &vertexShader, const QString &fragmentSh return prog; } -class QOpenKODEEventLoopHelper : public QThread -{ -public: - QOpenKODEEventLoopHelper(QSemaphore *m) - : eventMutex(m) - { - m->acquire(); - } - -protected: - void run() - { - if (kdInitializeNV() == KD_ENOTINITIALIZED) { - qFatal("Did not manage to initialize openkode"); - } - eventMutex->release(); - - const KDEvent *event; - while ((event = kdWaitEvent(-1)) != 0) { - qDebug() << "!!! received event!"; - kdDefaultEvent(event); - } - } - -private: - QSemaphore *eventMutex; -}; - QOpenKODEIntegration::QOpenKODEIntegration() - : eventMutex(1) { - QOpenKODEEventLoopHelper *loop = new QOpenKODEEventLoopHelper(&eventMutex); - loop->start(); - eventMutex.acquire(); // block until initialization done - + if (kdInitializeNV() == KD_ENOTINITIALIZED) { + qFatal("Did not manage to initialize openkode"); + } QOpenKODEScreen *mPrimaryScreen = new QOpenKODEScreen(); mScreens.append(mPrimaryScreen); @@ -265,6 +236,11 @@ bool QOpenKODEIntegration::hasOpenGL() const return true; } +QPlatformEventLoopIntegration *QOpenKODEIntegration::createEventLoopIntegration() const +{ + return new QOpenKODEEventLoopIntegration; +} + GLuint QOpenKODEIntegration::blitterProgram() { static GLuint shaderProgram = 0; diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.h b/src/plugins/platforms/openkode/qopenkodeintegration.h index 9029086..0eaf127 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.h +++ b/src/plugins/platforms/openkode/qopenkodeintegration.h @@ -86,7 +86,8 @@ public: QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; bool hasOpenGL() const; - QPlatformGLContext * createGLContext(); + + QPlatformEventLoopIntegration *createEventLoopIntegration() const; virtual QList<QPlatformScreen *> screens() const { return mScreens; } @@ -94,7 +95,6 @@ public: private: QList<QPlatformScreen *> mScreens; - QSemaphore eventMutex; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/qopenkodewindow.cpp b/src/plugins/platforms/openkode/qopenkodewindow.cpp index 2213a8f..faba2fb 100644 --- a/src/plugins/platforms/openkode/qopenkodewindow.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindow.cpp @@ -60,7 +60,6 @@ QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw) : QPlatformWindow(tlw) { - if (tlw->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenVG) { m_eglApi = EGL_OPENVG_API; } else { diff --git a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp index a349031..84e27f5 100644 --- a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp @@ -93,8 +93,6 @@ void QOpenKODEWindowSurface::flush(QWidget *widget, const QRegion ®ion, const y = boundingRect.y(); } - qDebug() << "flush" << widget << offset << region.boundingRect() << mImage.format() << blitImage.format(); - GLuint shaderProgram = QOpenKODEIntegration::blitterProgram(); glUseProgram(shaderProgram); @@ -125,7 +123,7 @@ void QOpenKODEWindowSurface::flush(QWidget *widget, const QRegion ®ion, const glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage.bits()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, mImage.bits()); // Enable vertex attribute associated with vertex position glEnableVertexAttribArray(posId); @@ -166,7 +164,7 @@ void QOpenKODEWindowSurface::beginPaint(const QRegion ®ion) Q_UNUSED(region); if (mImage.isNull()) { m_platformGLContext = window()->platformWindow()->glContext(); - mImage = QImage(size(),QImage::Format_RGB32); + mImage = QImage(size(),QImage::Format_RGB888); } } diff --git a/src/plugins/platforms/vnc/qvncintegration.cpp b/src/plugins/platforms/vnc/qvncintegration.cpp index 16fa5bb..331c16a 100644 --- a/src/plugins/platforms/vnc/qvncintegration.cpp +++ b/src/plugins/platforms/vnc/qvncintegration.cpp @@ -156,16 +156,6 @@ QPixmapData *QVNCIntegration::createPixmapData(QPixmapData::PixelType type) cons return new QRasterPixmapData(type); } -// QWindowSurface *QVNCIntegration::createWindowSurface(QWidget *widget) const -// { -// if (widget->windowType() == Qt::Desktop) -// return 0; // Don't create an explicit window surface for the destkop. -// QFbWindowSurface * surface; -// surface = new QFbWindowSurface(mPrimaryScreen, widget); -// mPrimaryScreen->addWindowSurface(surface); -// return surface; -// } - QWindowSurface *QVNCIntegration::createWindowSurface(QWidget *widget, WId) const { QFbWindowSurface * surface; @@ -192,6 +182,40 @@ QPlatformWindow *QVNCIntegration::createPlatformWindow(QWidget *widget, WId /*wi return w; } +QPixmap QVNCIntegration::grabWindow(WId window, int x, int y, int width, int height) const +{ +// qDebug() << "QVNCIntegration::grabWindow" << window << x << y << width << height; + + if (window == 0) { //desktop + QImage *desktopImage = mPrimaryScreen->image(); + if (x==0 && y == 0 && width < 0 && height < 0) { + return QPixmap::fromImage(*desktopImage); + } + if (width < 0) + width = desktopImage->width() - x; + if (height < 0) + height = desktopImage->height() - y; + int bytesPerPixel = desktopImage->depth()/8; //We don't support 1, 2, or 4 bpp + QImage img(desktopImage->scanLine(y) + bytesPerPixel*x, width, height, desktopImage->bytesPerLine(), desktopImage->format()); + return QPixmap::fromImage(img); + } + QWidget *win = QWidget::find(window); + if (win) { + QRect r = win->geometry(); + if (width < 0) + width = r.width() - x; + if (height < 0) + height = r.height() - y; + QImage *desktopImage = mPrimaryScreen->image(); + int bytesPerPixel = desktopImage->depth()/8; //We don't support 1, 2, or 4 bpp + + QImage img(desktopImage->scanLine(r.top() + y) + bytesPerPixel*(r.left()+x), width, height, desktopImage->bytesPerLine(), desktopImage->format()); + return QPixmap::fromImage(img); + } + return QPixmap(); +} + + void QVNCIntegration::moveToScreen(QWidget *window, int screen) { if (virtualDesktop) { // all windows exist on all screens in virtual desktop mode diff --git a/src/plugins/platforms/vnc/qvncintegration.h b/src/plugins/platforms/vnc/qvncintegration.h index d49e051..241993d 100644 --- a/src/plugins/platforms/vnc/qvncintegration.h +++ b/src/plugins/platforms/vnc/qvncintegration.h @@ -84,6 +84,8 @@ public: QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; + QPixmap grabWindow(WId window, int x, int y, int width, int height) const; + QList<QPlatformScreen *> screens() const { return mScreens; } bool isVirtualDesktop() { return virtualDesktop; } |