From c13076a30e5ae3d0f6795261ad00ca1eb73ad0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 7 Apr 2010 16:13:19 +0200 Subject: Added QPlatformWindow --- src/gui/kernel/kernel.pri | 4 +- src/gui/kernel/qplatformintegration_lite.h | 2 +- src/gui/kernel/qplatformwindow_lite.cpp | 72 +++++++++++++++++++ src/gui/kernel/qplatformwindow_lite.h | 79 +++++++++++++++++++++ src/gui/kernel/qwidget.cpp | 38 ++++++++++ src/gui/kernel/qwidget.h | 6 ++ src/gui/kernel/qwidget_lite.cpp | 82 +++++++++++----------- src/gui/kernel/qwidget_p.h | 5 ++ src/gui/painting/painting.pri | 2 +- src/gui/painting/qbackingstore.cpp | 16 ++++- src/gui/painting/qgraphicssystem_lite.cpp | 3 +- src/gui/painting/qwindowsurface.cpp | 53 +++++--------- src/gui/painting/qwindowsurface_p.h | 16 ++--- .../minimal/qplatformintegration_minimal.cpp | 7 +- .../minimal/qplatformintegration_minimal.h | 2 +- .../platforms/minimal/qwindowsurface_minimal.cpp | 8 +-- .../platforms/minimal/qwindowsurface_minimal.h | 4 +- src/plugins/plugins.pro | 2 +- 18 files changed, 298 insertions(+), 103 deletions(-) create mode 100644 src/gui/kernel/qplatformwindow_lite.cpp create mode 100644 src/gui/kernel/qplatformwindow_lite.h diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index cf5ec92..049637f 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -207,6 +207,7 @@ embedded_lite { kernel/qplatformscreen_lite.h \ kernel/qplatformintegrationfactory_lite_p.h \ kernel/qplatformintegrationplugin_lite.h \ + kernel/qplatformwindow_lite.h SOURCES += \ kernel/qapplication_lite.cpp \ @@ -224,7 +225,8 @@ embedded_lite { kernel/qplatformintegration_lite.cpp \ kernel/qplatformscreen_lite.cpp \ kernel/qplatformintegrationfactory_lite.cpp \ - kernel/qplatformintegrationplugin_lite.cpp + kernel/qplatformintegrationplugin_lite.cpp \ + kernel/qplatformwindow_lite.cpp contains(QT_CONFIG, glib) { SOURCES += \ diff --git a/src/gui/kernel/qplatformintegration_lite.h b/src/gui/kernel/qplatformintegration_lite.h index 9125bd1..389dcfb 100644 --- a/src/gui/kernel/qplatformintegration_lite.h +++ b/src/gui/kernel/qplatformintegration_lite.h @@ -62,7 +62,7 @@ public: // GraphicsSystem functions virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0; - virtual QWindowSurface *createWindowSurface(QWidget *widget) const = 0; + virtual void createWindowAndSurface(QPlatformWindow **window, QWindowSurface **surface, QWidget *widget, WId winId = 0) const = 0; virtual QBlittable *createBlittable(const QSize &size) const; // Window System functions diff --git a/src/gui/kernel/qplatformwindow_lite.cpp b/src/gui/kernel/qplatformwindow_lite.cpp new file mode 100644 index 0000000..ff1bf48 --- /dev/null +++ b/src/gui/kernel/qplatformwindow_lite.cpp @@ -0,0 +1,72 @@ +#include "qplatformwindow_lite.h" + +#include + +class QPlatformWindowPrivate +{ + QWidget *tlw; + QRect rect; + friend class QPlatformWindow; +}; + +QPlatformWindow::QPlatformWindow(QWidget *tlw) + : d_ptr(new QPlatformWindowPrivate) +{ + Q_D(QPlatformWindow); + d->tlw = tlw; + tlw->setPlatformWindow(this); +} + +QPlatformWindow::~QPlatformWindow() +{ +} + +QWidget *QPlatformWindow::widget() const +{ + Q_D(const QPlatformWindow); + return d->tlw; +} + +void QPlatformWindow::setGeometry(const QRect &rect) +{ + Q_D(QPlatformWindow); + d->rect = rect; +} + +QRect QPlatformWindow::geometry() const +{ + Q_D(const QPlatformWindow); + return d->rect; +} + +/*! +Reimplemented in subclasses to show the surface if \a visible is \c true, and hide it if \a visible is \c false. +*/ +void QPlatformWindow::setVisible(bool visible) +{ + Q_UNUSED(visible); +} +/*! +Requests setting the window flags of this surface to \a type. Returns the actual flags set. +*/ +Qt::WindowFlags QPlatformWindow::setWindowFlags(Qt::WindowFlags flags) +{ + Q_UNUSED(flags); + return Qt::Window; +} + +/*! + Returns the effective window flags for this surface. +*/ +Qt::WindowFlags QPlatformWindow::windowFlags() const +{ + return Qt::Window; +} + +WId QPlatformWindow::winId() const { return WId(0); } + +void QPlatformWindow::setWindowTitle(const QString &) {} + +void QPlatformWindow::raise() { qWarning("This plugin does not support raise()"); } + +void QPlatformWindow::lower() { qWarning("This plugin does not support lower()"); } diff --git a/src/gui/kernel/qplatformwindow_lite.h b/src/gui/kernel/qplatformwindow_lite.h new file mode 100644 index 0000000..3fa97b5 --- /dev/null +++ b/src/gui/kernel/qplatformwindow_lite.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QPLATFORMWINDOW_H +#define QPLATFORMWINDOW_H + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +#include + +class QPlatformWindowPrivate; + +class Q_GUI_EXPORT QPlatformWindow +{ + Q_DECLARE_PRIVATE(QPlatformWindow); +public: + QPlatformWindow(QWidget *tlw); + virtual ~QPlatformWindow(); + + QWidget *widget() const; + virtual void setGeometry(const QRect &rect); + virtual QRect geometry() const; + + virtual void setVisible(bool visible); + virtual Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags); + virtual Qt::WindowFlags windowFlags() const; + virtual WId winId() const; + + virtual void setWindowTitle(const QString &); + virtual void raise(); + virtual void lower(); + +protected: + QScopedPointer d_ptr; +}; + +QT_END_NAMESPACE + +QT_END_HEADER +#endif //QPLATFORMWINDOW_H diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 3ca7591..4bcec93 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11836,6 +11836,44 @@ QWindowSurface *QWidget::windowSurface() const return bs ? bs->windowSurface : 0; } +/*! + \preliminary + + Sets the window to be the \a window specified. + The QWidget takes ownership of the \a surface. +*/ +void QWidget::setPlatformWindow(QPlatformWindow *window) +{ +#ifndef Q_BACKINGSTORE_SUBSURFACES + if (!isTopLevel()) + return; +#endif + + Q_D(QWidget); + + QTLWExtra *topData = d->topData(); + if (topData->platformWindow == window) + return; + + delete topData->platformWindow; + topData->platformWindow = window; +} + +/*! + \preliminary + + Returns the QPlatformWindow this widget will be drawn into. +*/ +QPlatformWindow *QWidget::platformWindow() const +{ + Q_D(const QWidget); + QTLWExtra *extra = d->maybeTopData(); + if (extra && extra->platformWindow) + return extra->platformWindow; + + return 0; +} + void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const { if (left) diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index e12148b..7dff703 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -94,6 +94,7 @@ class QHideEvent; class QInputContext; class QIcon; class QWindowSurface; +class QPlatformWindow; class QLocale; class QGraphicsProxyWidget; class QGraphicsEffect; @@ -625,6 +626,11 @@ public: void setWindowSurface(QWindowSurface *surface); QWindowSurface *windowSurface() const; +#if defined(Q_WS_LITE) + void setPlatformWindow(QPlatformWindow *window); + QPlatformWindow *platformWindow() const; +#endif + Q_SIGNALS: void customContextMenuRequested(const QPoint &pos); diff --git a/src/gui/kernel/qwidget_lite.cpp b/src/gui/kernel/qwidget_lite.cpp index add5592..7915d7f 100644 --- a/src/gui/kernel/qwidget_lite.cpp +++ b/src/gui/kernel/qwidget_lite.cpp @@ -39,26 +39,28 @@ ** ****************************************************************************/ -#include "qwidget.h" -#include "qevent.h" -#include "qapplication.h" -#include "private/qbackingstore_p.h" -#include "private/qwidget_p.h" -#include "private/qgraphicssystem_p.h" -#include "private/qapplication_p.h" -#include "qdesktopwidget.h" - -#include +#include "QtGui/qwidget.h" +#include "QtGui/qevent.h" +#include "QtGui/qapplication.h" +#include "QtGui/private/qbackingstore_p.h" +#include "QtGui/private/qwidget_p.h" +#include "QtGui/private/qgraphicssystem_p.h" +#include "QtGui/private/qapplication_p.h" +#include "QtGui/qdesktopwidget.h" +#include "QtGui/qplatformwindow_lite.h" + +#include QT_BEGIN_NAMESPACE static QPlatformScreen *qt_screenForWidget(const QWidget *w); -void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool /*destroyOldWindow*/) +void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) { Q_Q(QWidget); Q_UNUSED(window); Q_UNUSED(initializeWindow); + Q_UNUSED(destroyOldWindow); // XXX Qt::WindowFlags flags = data.window_flags; @@ -67,15 +69,16 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool /*destro return; // we only care about real toplevels QWindowSurface *surface = q->windowSurface(); + QPlatformWindow *platformWindow = q->platformWindow(); - if (!surface) - surface = createDefaultWindowSurface(); - + if (!surface) { + QApplicationPrivate::platformIntegration()->createWindowAndSurface(&platformWindow,&surface,q); + } Q_ASSERT(surface); - data.window_flags = surface->setWindowFlags(data.window_flags); + data.window_flags = q->platformWindow()->setWindowFlags(data.window_flags); - setWinId(surface->winId()); + setWinId(q->platformWindow()->winId()); // qDebug() << "create_sys" << q << q->internalWinId(); } @@ -119,8 +122,8 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) if (f & Qt::Window) { //qDebug() << "setParent_sys" << q << newparent << hex << f; - if (QWindowSurface *surface = q->windowSurface()) - data.window_flags = surface->setWindowFlags(data.window_flags); + if (QPlatformWindow *window = q->platformWindow()) + data.window_flags = window->setWindowFlags(data.window_flags); } // XXX Reparenting child to toplevel or vice versa ### if ((f&Qt::Window) && !(oldFlags&Qt::Window)) { @@ -191,8 +194,8 @@ void QWidgetPrivate::setWindowTitle_sys(const QString &caption) if (!q->isWindow()) return; - if (QWindowSurface *surface = q->windowSurface()) - surface->setWindowTitle(caption); + if (QPlatformWindow *window = q->platformWindow()) + window->setWindowTitle(caption); } @@ -299,9 +302,14 @@ void QWidgetPrivate::show_sys() if (QWindowSurface *surface = q->windowSurface()) { const QRect geomRect = q->geometry(); - if (surface->geometry() != geomRect) - surface->setGeometry(geomRect); - surface->setVisible(true); + const QRect windowRect = q->platformWindow()->geometry(); + if (windowRect != geomRect) { + q->platformWindow()->setGeometry(geomRect); + if (windowRect.size() != geomRect.size()) { + surface->resize(geomRect.size()); + } + } + q->platformWindow()->setVisible(true); } if (q->windowType() != Qt::Popup && q->windowType() != Qt::ToolTip && !(q->windowFlags() & Qt::X11BypassWindowManagerHint)) @@ -320,8 +328,8 @@ void QWidgetPrivate::hide_sys() } return; } - if (QWindowSurface *surface = q->windowSurface()) { - surface->setVisible(false); + if (QPlatformWindow *window = q->platformWindow()) { + window->setVisible(false); } //### we don't yet have proper focus event handling @@ -427,8 +435,7 @@ void QWidgetPrivate::raise_sys() { Q_Q(QWidget); if (q->isWindow()) { - QWindowSurface *surface = q->windowSurface(); - surface->raise(); + q->platformWindow()->raise(); } } @@ -437,8 +444,7 @@ void QWidgetPrivate::lower_sys() Q_Q(QWidget); if (q->isWindow()) { Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); - QWindowSurface *surface = q->windowSurface(); - surface->lower(); + q->platformWindow()->lower(); } else if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); @@ -491,8 +497,11 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) if (q->isWindow()) { const QWidgetBackingStore *bs = maybeBackingStore(); - if (bs->windowSurface) - bs->windowSurface->setGeometry(q->frameGeometry()); + if (bs->windowSurface) { + q->platformWindow()->setGeometry(q->frameGeometry()); + if (isResize) + bs->windowSurface->resize(r.size()); + } } else { if (isMove && !isResize) moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y()); @@ -653,16 +662,7 @@ QPaintEngine *QWidget::paintEngine() const QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys() { - Q_Q(QWidget); - if (q->windowType() == Qt::Desktop) - return 0; - q->ensurePolished(); - - QGraphicsSystem *gs = QApplicationPrivate::graphicsSystem(); - if (!gs) - return 0; - - return gs->createWindowSurface(q); + qFatal("CreateDefaultWindowSurface_sys should not be used on lighthouse"); } void QWidgetPrivate::setModal_sys() diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 0f34ae0..4ca493e 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -102,6 +102,9 @@ class QWSManager; #if defined(Q_WS_MAC) class QCoreGraphicsPaintEnginePrivate; #endif +#if defined(Q_WS_LITE) +class QPlatformWindow; +#endif class QPaintEngine; class QPixmap; class QWidgetBackingStore; @@ -176,6 +179,8 @@ struct QTLWExtra { #endif #elif defined(Q_OS_SYMBIAN) uint inExpose : 1; // Prevents drawing recursion +#elif defined(Q_WS_LITE) + QPlatformWindow *platformWindow; #endif }; diff --git a/src/gui/painting/painting.pri b/src/gui/painting/painting.pri index c4e8f7a..972bac2 100644 --- a/src/gui/painting/painting.pri +++ b/src/gui/painting/painting.pri @@ -117,7 +117,7 @@ embedded { SOURCES += \ painting/qgraphicssystem_qws.cpp \ -} else { +} else: if(!embedded_lite) { HEADERS += \ painting/qgraphicssystem_raster_p.h \ painting/qgraphicssystemfactory_p.h \ diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index f2cd7e6..30c042e 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -286,7 +286,11 @@ bool QWidgetBackingStore::bltRect(const QRect &rect, int dx, int dy, QWidget *wi void QWidgetBackingStore::releaseBuffer() { if (windowSurface) +#if defined(Q_WS_LITE) + windowSurface->resize(QSize()); +#else windowSurface->setGeometry(QRect()); +#endif #ifdef Q_BACKINGSTORE_SUBSURFACES for (int i = 0; i < subSurfaces.size(); ++i) subSurfaces.at(i)->setGeometry(QRect()); @@ -415,6 +419,7 @@ void QWidgetBackingStore::endPaint(const QRegion &cleaned, QWindowSurface *windo QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const { const bool widgetDirty = widget && widget != tlw; +#if !defined(Q_WS_LITE) const QRect tlwRect(topLevelRect()); const QRect surfaceGeometry(windowSurface->geometry()); if (surfaceGeometry != tlwRect && surfaceGeometry.size() != tlwRect.size()) { @@ -426,6 +431,7 @@ QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const } return QRect(QPoint(), tlwRect.size()); } +#endif // Calculate the region that needs repaint. QRegion r(dirty); @@ -467,7 +473,11 @@ QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const QRegion QWidgetBackingStore::staticContents(QWidget *parent, const QRect &withinClipRect) const { if (!parent && tlw->testAttribute(Qt::WA_StaticContents)) { +#if defined(Q_WS_LITE) + const QSize surfaceGeometry(windowSurface->size()); +#else const QRect surfaceGeometry(windowSurface->geometry()); +#endif QRect surfaceRect(0, 0, surfaceGeometry.width(), surfaceGeometry.height()); if (!withinClipRect.isEmpty()) surfaceRect &= withinClipRect; @@ -1144,11 +1154,12 @@ void QWidgetBackingStore::sync() return; } - const bool inTopLevelResize = tlwExtra->inTopLevelResize; const bool updatesDisabled = !tlw->updatesEnabled(); + bool repaintAllWidgets = false; +#if !defined(Q_WS_LITE) + const bool inTopLevelResize = tlwExtra->inTopLevelResize; const QRect tlwRect(topLevelRect()); const QRect surfaceGeometry(windowSurface->geometry()); - bool repaintAllWidgets = false; if (inTopLevelResize || surfaceGeometry != tlwRect) { if ((inTopLevelResize || surfaceGeometry.size() != tlwRect.size()) && !updatesDisabled) { @@ -1171,6 +1182,7 @@ void QWidgetBackingStore::sync() } windowSurface->setGeometry(tlwRect); } +#endif if (updatesDisabled) return; diff --git a/src/gui/painting/qgraphicssystem_lite.cpp b/src/gui/painting/qgraphicssystem_lite.cpp index 42e7238..a62abbb 100644 --- a/src/gui/painting/qgraphicssystem_lite.cpp +++ b/src/gui/painting/qgraphicssystem_lite.cpp @@ -51,7 +51,8 @@ QPixmapData *QLiteGraphicsSystem::createPixmapData(QPixmapData::PixelType type) QWindowSurface *QLiteGraphicsSystem::createWindowSurface(QWidget *widget) const { - return QApplicationPrivate::platformIntegration()->createWindowSurface(widget); + qFatal("should not use QLiteGraphicsSystem::createWindowSurface"); + return 0; } QBlittable *QLiteGraphicsSystem::createBlittable(const QSize &size) const diff --git a/src/gui/painting/qwindowsurface.cpp b/src/gui/painting/qwindowsurface.cpp index 34c2936..20594c4 100644 --- a/src/gui/painting/qwindowsurface.cpp +++ b/src/gui/painting/qwindowsurface.cpp @@ -52,7 +52,11 @@ public: QWindowSurfacePrivate(QWidget *w) : window(w), staticContentsSupport(false) {} QWidget *window; +#if !defined(Q_WS_LITE) QRect geometry; +#else + QSize size; +#endif //Q_WS_LITE QRegion staticContents; QList bufferImages; bool staticContentsSupport; @@ -144,6 +148,7 @@ void QWindowSurface::endPaint(const QRegion &) d_ptr->bufferImages.clear(); } +#if !defined(Q_WS_LITE) /*! Sets the currently allocated area to be the given \a rect. @@ -164,6 +169,17 @@ QRect QWindowSurface::geometry() const { return d_ptr->geometry; } +#else +void QWindowSurface::resize(const QSize &size) +{ + d_ptr->size = size; +} + +QSize QWindowSurface::size() const +{ + return d_ptr->size; +} +#endif //Q_WS_LITE /*! Scrolls the given \a area \a dx pixels to the right and \a dy @@ -349,41 +365,4 @@ void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset) } } - -#ifdef Q_WS_LITE -/*! -Requests setting the window flags of this surface to \a type. Returns the actual flags set. -*/ -Qt::WindowFlags QWindowSurface::setWindowFlags(Qt::WindowFlags type) -{ - Q_UNUSED(type); - qDebug() << "QWindowSurface::setWindowFlags" << hex << type; - return Qt::Window; -} - -/*! - Returns the effective window flags for this surface. -*/ -Qt::WindowFlags QWindowSurface::windowFlags() const -{ - return Qt::Window; -} - -/*! -Reimplemented in subclasses to show the surface if \a visible is \c true, and hide it if \a visible is \c false. -*/ - -void QWindowSurface::setVisible(bool visible) -{ - Q_UNUSED(visible); -} - - -WId QWindowSurface::winId() const -{ - return WId(0); -} - -#endif - QT_END_NAMESPACE diff --git a/src/gui/painting/qwindowsurface_p.h b/src/gui/painting/qwindowsurface_p.h index 5930704..3a14b0f 100644 --- a/src/gui/painting/qwindowsurface_p.h +++ b/src/gui/painting/qwindowsurface_p.h @@ -63,6 +63,7 @@ class QRect; class QPoint; class QImage; class QWindowSurfacePrivate; +class QPlatformWindow; class Q_GUI_EXPORT QWindowSurface { @@ -75,8 +76,13 @@ public: virtual QPaintDevice *paintDevice() = 0; virtual void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) = 0; +#if !defined(Q_WS_LITE) virtual void setGeometry(const QRect &rect); QRect geometry() const; +#else + virtual void resize(const QSize &size); + QSize size() const; +#endif virtual bool scroll(const QRegion &area, int dx, int dy); @@ -89,16 +95,6 @@ public: virtual QPoint offset(const QWidget *widget) const; inline QRect rect(const QWidget *widget) const; -#ifdef Q_WS_LITE - virtual void setVisible(bool visible); - virtual Qt::WindowFlags setWindowFlags(Qt::WindowFlags type); - virtual Qt::WindowFlags windowFlags() const; - virtual WId winId() const; - - virtual void setWindowTitle(const QString &) {} - virtual void raise() { qWarning("This plugin does not support raise()"); } - virtual void lower() { qWarning("This plugin does not support lower()"); } -#endif bool hasStaticContentsSupport() const; void setStaticContents(const QRegion ®ion); diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp index 693e0c3..2f03127 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp @@ -2,6 +2,7 @@ #include "qwindowsurface_minimal.h" #include +#include QMinimalIntegration::QMinimalIntegration() { @@ -19,7 +20,9 @@ QPixmapData *QMinimalIntegration::createPixmapData(QPixmapData::PixelType type) { return new QRasterPixmapData(type); } -QWindowSurface *QMinimalIntegration::createWindowSurface(QWidget *widget) const +void QMinimalIntegration::createWindowAndSurface(QPlatformWindow**window, QWindowSurface**surface, QWidget *widget, WId winId) const { - return new QMinimalWindowSurface(widget); + qDebug() << "createWindow"; + *surface = new QMinimalWindowSurface(widget); + *window = new QPlatformWindow(widget); } diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.h b/src/plugins/platforms/minimal/qplatformintegration_minimal.h index d4eb78b..127c573 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.h +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.h @@ -72,7 +72,7 @@ public: QMinimalIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; + void createWindowAndSurface(QPlatformWindow**window, QWindowSurface**surface, QWidget *widget, WId winId) const; QList screens() const { return mScreens; } diff --git a/src/plugins/platforms/minimal/qwindowsurface_minimal.cpp b/src/plugins/platforms/minimal/qwindowsurface_minimal.cpp index 0b2bdd2..2f8b1f0 100644 --- a/src/plugins/platforms/minimal/qwindowsurface_minimal.cpp +++ b/src/plugins/platforms/minimal/qwindowsurface_minimal.cpp @@ -73,13 +73,13 @@ void QMinimalWindowSurface::flush(QWidget *widget, const QRegion ®ion, const mImage.save(filename); } -void QMinimalWindowSurface::setGeometry(const QRect &rect) +void QMinimalWindowSurface::resize(const QSize &size) { //qDebug() << "QMinimalWindowSurface::setGeometry:" << (long)this << rect; - QWindowSurface::setGeometry(rect); + QWindowSurface::resize(size); QImage::Format format = QApplicationPrivate::platformIntegration()->screens().first()->format(); - if (mImage.size() != rect.size()) - mImage = QImage(rect.size(), format); + if (mImage.size() != size) + mImage = QImage(size, format); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/minimal/qwindowsurface_minimal.h b/src/plugins/platforms/minimal/qwindowsurface_minimal.h index 959a731..96f989d 100644 --- a/src/plugins/platforms/minimal/qwindowsurface_minimal.h +++ b/src/plugins/platforms/minimal/qwindowsurface_minimal.h @@ -44,6 +44,8 @@ #include +#include + QT_BEGIN_NAMESPACE class QMinimalWindowSurface : public QWindowSurface @@ -54,7 +56,7 @@ public: QPaintDevice *paintDevice(); void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void setGeometry(const QRect &rect); + void resize(const QSize &size); private: QImage mImage; diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 730fdc5..73ab3e9 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -6,7 +6,7 @@ unix:!symbian { } else { SUBDIRS *= codecs } -!embedded:SUBDIRS *= graphicssystems +!embedded:!embedded-lite:SUBDIRS *= graphicssystems embedded:SUBDIRS *= gfxdrivers decorations mousedrivers kbddrivers !win32:!embedded:!mac:!symbian:SUBDIRS *= inputmethods symbian:SUBDIRS += s60 -- cgit v0.12 From d6cf18d036df1ecead4c8471944880c7f9a414f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Thu, 8 Apr 2010 09:58:08 +0200 Subject: QPlatformWindow refactoring and ported the directfb plugin to use QPlatformWindow --- src/gui/kernel/qplatformintegration_lite.h | 3 +- src/gui/kernel/qplatformwindow_lite.cpp | 6 + src/gui/kernel/qplatformwindow_lite.h | 12 +- src/gui/kernel/qwidget.cpp | 6 + src/gui/kernel/qwidget_lite.cpp | 15 +- src/plugins/platforms/directfb/qdirectfbinput.cpp | 13 +- src/plugins/platforms/directfb/qdirectfbinput.h | 4 +- src/plugins/platforms/directfb/qdirectfbwindow.cpp | 157 +++++++++++++++++++++ src/plugins/platforms/directfb/qdirectfbwindow.h | 73 ++++++++++ .../directfb/qplatformintegration_directfb.cpp | 11 +- .../directfb/qplatformintegration_directfb.h | 3 +- .../platforms/directfb/qwindowsurface_directfb.cpp | 114 ++------------- .../platforms/directfb/qwindowsurface_directfb.h | 15 +- src/plugins/platforms/minimal/minimal.pro | 2 +- .../minimal/qplatformintegration_minimal.cpp | 14 +- .../minimal/qplatformintegration_minimal.h | 3 +- 16 files changed, 309 insertions(+), 142 deletions(-) create mode 100644 src/plugins/platforms/directfb/qdirectfbwindow.cpp create mode 100644 src/plugins/platforms/directfb/qdirectfbwindow.h diff --git a/src/gui/kernel/qplatformintegration_lite.h b/src/gui/kernel/qplatformintegration_lite.h index 389dcfb..b13260e 100644 --- a/src/gui/kernel/qplatformintegration_lite.h +++ b/src/gui/kernel/qplatformintegration_lite.h @@ -62,7 +62,8 @@ public: // GraphicsSystem functions virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0; - virtual void createWindowAndSurface(QPlatformWindow **window, QWindowSurface **surface, QWidget *widget, WId winId = 0) const = 0; + virtual QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const = 0; + virtual QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const = 0; virtual QBlittable *createBlittable(const QSize &size) const; // Window System functions diff --git a/src/gui/kernel/qplatformwindow_lite.cpp b/src/gui/kernel/qplatformwindow_lite.cpp index ff1bf48..c8a3ed5 100644 --- a/src/gui/kernel/qplatformwindow_lite.cpp +++ b/src/gui/kernel/qplatformwindow_lite.cpp @@ -70,3 +70,9 @@ void QPlatformWindow::setWindowTitle(const QString &) {} void QPlatformWindow::raise() { qWarning("This plugin does not support raise()"); } void QPlatformWindow::lower() { qWarning("This plugin does not support lower()"); } + +void QPlatformWindow::setOpacity(qreal level) +{ + Q_UNUSED(level); + qWarning("This plugin does not support setting window opacity"); +} diff --git a/src/gui/kernel/qplatformwindow_lite.h b/src/gui/kernel/qplatformwindow_lite.h index 3fa97b5..8771cfe 100644 --- a/src/gui/kernel/qplatformwindow_lite.h +++ b/src/gui/kernel/qplatformwindow_lite.h @@ -41,13 +41,18 @@ #ifndef QPLATFORMWINDOW_H #define QPLATFORMWINDOW_H -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE #include +#include +#include +#include class QPlatformWindowPrivate; +class QWidget; + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE class Q_GUI_EXPORT QPlatformWindow { @@ -69,6 +74,7 @@ public: virtual void raise(); virtual void lower(); + virtual void setOpacity(qreal level); protected: QScopedPointer d_ptr; }; diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 4bcec93..7eaf03c 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -74,6 +74,9 @@ # include "qpaintengine.h" // for PorterDuff # include "private/qwindowsurface_qws_p.h" #endif +#if defined(Q_WS_LITE) +#include "qplatformwindow_lite.h" +#endif #include "qpainter.h" #include "qtooltip.h" #include "qwhatsthis.h" @@ -1574,6 +1577,9 @@ void QWidgetPrivate::createTLExtra() static int count = 0; qDebug() << "tlextra" << ++count; #endif +#if defined(Q_WS_LITE) + x->platformWindow = 0; +#endif } } diff --git a/src/gui/kernel/qwidget_lite.cpp b/src/gui/kernel/qwidget_lite.cpp index 7915d7f..cf93c5e 100644 --- a/src/gui/kernel/qwidget_lite.cpp +++ b/src/gui/kernel/qwidget_lite.cpp @@ -71,8 +71,13 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO QWindowSurface *surface = q->windowSurface(); QPlatformWindow *platformWindow = q->platformWindow(); + if (!platformWindow) { + platformWindow = QApplicationPrivate::platformIntegration()->createPlatformWindow(q); + } + Q_ASSERT(platformWindow); + if (!surface) { - QApplicationPrivate::platformIntegration()->createWindowAndSurface(&platformWindow,&surface,q); + surface = QApplicationPrivate::platformIntegration()->createWindowSurfaceForWindow(q,platformWindow->winId()); } Q_ASSERT(surface); @@ -102,8 +107,7 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) { Q_Q(QWidget); - - QWidget *oldParent = q->parentWidget(); +// QWidget *oldParent = q->parentWidget(); Qt::WindowFlags oldFlags = data.window_flags; if (parent != newparent) { QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function??? @@ -643,8 +647,8 @@ void QWidgetPrivate::updateFrameStrut() void QWidgetPrivate::setWindowOpacity_sys(qreal level) { - Q_UNUSED(level); - // XXX + Q_Q(QWidget); + q->platformWindow()->setOpacity(level); } void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect) @@ -663,6 +667,7 @@ QPaintEngine *QWidget::paintEngine() const QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys() { qFatal("CreateDefaultWindowSurface_sys should not be used on lighthouse"); + return 0; } void QWidgetPrivate::setModal_sys() diff --git a/src/plugins/platforms/directfb/qdirectfbinput.cpp b/src/plugins/platforms/directfb/qdirectfbinput.cpp index 74a38a4..90c3348 100644 --- a/src/plugins/platforms/directfb/qdirectfbinput.cpp +++ b/src/plugins/platforms/directfb/qdirectfbinput.cpp @@ -78,16 +78,13 @@ void QDirectFbInput::addWindow(DFBWindowID id, QWidget *tlw) window->AttachEventBuffer(window,eventBuffer); } -void QDirectFbInput::removeWindow(QWidget *tlw) +void QDirectFbInput::removeWindow(WId wId) { - DFBWindowID id = tlwMap.key(tlw,0); - if (id) { - IDirectFBWindow *window; - dfbDisplayLayer->GetWindow(dfbDisplayLayer,id, &window); + IDirectFBWindow *window; + dfbDisplayLayer->GetWindow(dfbDisplayLayer,wId, &window); - window->DetachEventBuffer(window,eventBuffer); - tlwMap.remove(id); - } + window->DetachEventBuffer(window,eventBuffer); + tlwMap.remove(wId); } void QDirectFbInput::handleEvents() diff --git a/src/plugins/platforms/directfb/qdirectfbinput.h b/src/plugins/platforms/directfb/qdirectfbinput.h index 31aa082..016e7f1 100644 --- a/src/plugins/platforms/directfb/qdirectfbinput.h +++ b/src/plugins/platforms/directfb/qdirectfbinput.h @@ -9,6 +9,8 @@ #include #include +#include + #include class InputSocketWaiter : public QThread @@ -35,7 +37,7 @@ class QDirectFbInput : public QObject public: static QDirectFbInput *instance(); void addWindow(DFBWindowID id, QWidget *tlw); - void removeWindow(QWidget *tlw); + void removeWindow(WId wId); public slots: void handleEvents(); diff --git a/src/plugins/platforms/directfb/qdirectfbwindow.cpp b/src/plugins/platforms/directfb/qdirectfbwindow.cpp new file mode 100644 index 0000000..d88953e --- /dev/null +++ b/src/plugins/platforms/directfb/qdirectfbwindow.cpp @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qdirectfbwindow.h" +#include "qdirectfbinput.h" + +#include + +#include + +QDirectFbWindow::QDirectFbWindow(QWidget *tlw) + : QPlatformWindow(tlw) +{ + IDirectFBDisplayLayer *layer = QDirectFbConvenience::dfbDisplayLayer(); + DFBDisplayLayerConfig layerConfig; + layer->GetConfiguration(layer,&layerConfig); + + DFBWindowDescription description; + memset(&description,0,sizeof(DFBWindowDescription)); + description.flags = DFBWindowDescriptionFlags(DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_POSX|DWDESC_POSY|DWDESC_SURFACE_CAPS +#if DIRECTFB_MINOR_VERSION >= 1 + |DWDESC_OPTIONS +#endif + |DWDESC_CAPS); + description.width = tlw->rect().width(); + description.height = tlw->rect().height(); + description.posx = tlw->rect().x(); + description.posy = tlw->rect().y(); + + if (layerConfig.surface_caps & DSCAPS_PREMULTIPLIED) + description.surface_caps = DSCAPS_PREMULTIPLIED; + description.pixelformat = layerConfig.pixelformat; + +#if DIRECTFB_MINOR_VERSION >= 1 + description.options = DFBWindowOptions(DWOP_ALPHACHANNEL); +#endif + description.caps = DFBWindowCapabilities(DWCAPS_DOUBLEBUFFER|DWCAPS_ALPHACHANNEL); + description.surface_caps = DSCAPS_PREMULTIPLIED; + + DFBResult result = layer->CreateWindow(layer,&description,&m_dfbWindow); + if (result != DFB_OK) { + DirectFBError("QDirectFbGraphicsSystemScreen: failed to create window",result); + } + + m_dfbWindow->SetOpacity(m_dfbWindow,0xff); + + DFBWindowID id; + m_dfbWindow->GetID(m_dfbWindow, &id); + QDirectFbInput::instance()->addWindow(id,tlw); +} + +QDirectFbWindow::~QDirectFbWindow() +{ + QDirectFbInput::instance()->removeWindow(winId()); + m_dfbWindow->Destroy(m_dfbWindow); +} + +void QDirectFbWindow::setGeometry(const QRect &rect) +{ + QPlatformWindow::setGeometry(rect); + m_dfbWindow->SetBounds(m_dfbWindow, rect.x(),rect.y(), + rect.width(), rect.height()); + +} + +void QDirectFbWindow::setOpacity(qreal level) +{ + const quint8 windowOpacity = quint8(level * 0xff); + m_dfbWindow->SetOpacity(m_dfbWindow,windowOpacity); +} + +void QDirectFbWindow::setVisible(bool visible) +{ + if (visible) { + int x = geometry().x(); + int y = geometry().y(); + m_dfbWindow->MoveTo(m_dfbWindow,x,y); + } else { + IDirectFBDisplayLayer *displayLayer; + QDirectFbConvenience::dfbInterface()->GetDisplayLayer(QDirectFbConvenience::dfbInterface(),DLID_PRIMARY,&displayLayer); + + DFBDisplayLayerConfig config; + displayLayer->GetConfiguration(displayLayer,&config); + m_dfbWindow->MoveTo(m_dfbWindow,config.width+1,config.height + 1); + } +} + +Qt::WindowFlags QDirectFbWindow::setWindowFlags(Qt::WindowFlags flags) +{ + switch (flags & Qt::WindowType_Mask) { + case Qt::ToolTip: { + DFBWindowOptions options; + m_dfbWindow->GetOptions(m_dfbWindow,&options); + options = DFBWindowOptions(options | DWOP_GHOST); + m_dfbWindow->SetOptions(m_dfbWindow,options); + break; } + default: + break; + } + + m_dfbWindow->SetStackingClass(m_dfbWindow, flags & Qt::WindowStaysOnTopHint ? DWSC_UPPER : DWSC_MIDDLE); + return flags; +} + +void QDirectFbWindow::raise() +{ + m_dfbWindow->RaiseToTop(m_dfbWindow); +} + +void QDirectFbWindow::lower() +{ + m_dfbWindow->LowerToBottom(m_dfbWindow); +} + +WId QDirectFbWindow::winId() const +{ + DFBWindowID id; + m_dfbWindow->GetID(m_dfbWindow, &id); + return WId(id); +} diff --git a/src/plugins/platforms/directfb/qdirectfbwindow.h b/src/plugins/platforms/directfb/qdirectfbwindow.h new file mode 100644 index 0000000..d5fd408 --- /dev/null +++ b/src/plugins/platforms/directfb/qdirectfbwindow.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDIRECTFBWINDOW_H +#define QDIRECTFBWINDOW_H + +#include + +#include "qdirectfbconvenience.h" + +QT_BEGIN_NAMESPACE + +class QDirectFbWindow : public QPlatformWindow +{ +public: + QDirectFbWindow(QWidget *tlw); + ~QDirectFbWindow(); + + void setGeometry(const QRect &rect); + void setOpacity(qreal level); + + void setVisible(bool visible); + + Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags); + void raise(); + void lower(); + WId winId() const; + +private: + IDirectFBWindow *m_dfbWindow; +}; + +QT_END_NAMESPACE + +#endif // QDIRECTFBWINDOW_H diff --git a/src/plugins/platforms/directfb/qplatformintegration_directfb.cpp b/src/plugins/platforms/directfb/qplatformintegration_directfb.cpp index c70bb64..5f428ef 100644 --- a/src/plugins/platforms/directfb/qplatformintegration_directfb.cpp +++ b/src/plugins/platforms/directfb/qplatformintegration_directfb.cpp @@ -44,6 +44,7 @@ #include "qblitter_directfb.h" #include "qdirectfbconvenience.h" #include "qdirectfbcursor.h" +#include "qdirectfbwindow.h" #include #include @@ -105,9 +106,15 @@ QPixmapData *QDirectFbIntegration::createPixmapData(QPixmapData::PixelType type) return new QBlittablePixmapData(type); } -QWindowSurface *QDirectFbIntegration::createWindowSurface(QWidget *widget) const +QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWidget *widget, WId winId) const { - return new QDirectFbWindowSurface (widget); + Q_UNUSED(winId); + return new QDirectFbWindow(widget); +} + +QWindowSurface *QDirectFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId winId) const +{ + return new QDirectFbWindowSurface(widget,winId); } QBlittable *QDirectFbIntegration::createBlittable(const QSize &size) const diff --git a/src/plugins/platforms/directfb/qplatformintegration_directfb.h b/src/plugins/platforms/directfb/qplatformintegration_directfb.h index f74a81d..a8489c0 100644 --- a/src/plugins/platforms/directfb/qplatformintegration_directfb.h +++ b/src/plugins/platforms/directfb/qplatformintegration_directfb.h @@ -82,7 +82,8 @@ public: QDirectFbIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; QBlittable *createBlittable(const QSize &size) const; QList screens() const { return mScreens; } diff --git a/src/plugins/platforms/directfb/qwindowsurface_directfb.cpp b/src/plugins/platforms/directfb/qwindowsurface_directfb.cpp index afe34b7..e978cae 100644 --- a/src/plugins/platforms/directfb/qwindowsurface_directfb.cpp +++ b/src/plugins/platforms/directfb/qwindowsurface_directfb.cpp @@ -49,49 +49,19 @@ QT_BEGIN_NAMESPACE -QDirectFbWindowSurface::QDirectFbWindowSurface(QWidget *window) - : QWindowSurface(window), m_pixmap(0), m_pmdata(0), - m_dfbWindow(0), m_dfbSurface(0) +QDirectFbWindowSurface::QDirectFbWindowSurface(QWidget *window, WId wId) + : QWindowSurface(window), m_pixmap(0), m_pmdata(0), m_dfbSurface(0) { - window->setWindowSurface(this); IDirectFBDisplayLayer *layer = QDirectFbConvenience::dfbDisplayLayer(); - DFBDisplayLayerConfig layerConfig; - layer->GetConfiguration(layer,&layerConfig); - - DFBWindowDescription description; - memset(&description,0,sizeof(DFBWindowDescription)); - description.flags = DFBWindowDescriptionFlags(DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_POSX|DWDESC_POSY|DWDESC_SURFACE_CAPS -#if DIRECTFB_MINOR_VERSION >= 1 - |DWDESC_OPTIONS -#endif - |DWDESC_CAPS); - description.width = window->rect().width(); - description.height = window->rect().height(); - description.posx = window->rect().x(); - description.posy = window->rect().y(); - - if (layerConfig.surface_caps & DSCAPS_PREMULTIPLIED) - description.surface_caps = DSCAPS_PREMULTIPLIED; - description.pixelformat = layerConfig.pixelformat; - -#if DIRECTFB_MINOR_VERSION >= 1 - description.options = DFBWindowOptions(DWOP_ALPHACHANNEL); -#endif - description.caps = DFBWindowCapabilities(DWCAPS_DOUBLEBUFFER|DWCAPS_ALPHACHANNEL); - description.surface_caps = DSCAPS_PREMULTIPLIED; - - DFBResult result = layer->CreateWindow(layer,&description,&m_dfbWindow); - if (result != DFB_OK) { - DirectFBError("QDirectFbGraphicsSystemScreen: failed to create window",result); - } - DFBWindowID id; - m_dfbWindow->GetID(m_dfbWindow, &id); - QDirectFbInput::instance()->addWindow(id,window); + DFBWindowID id(wId); + IDirectFBWindow *dfbWindow; - m_dfbWindow->GetSurface(m_dfbWindow,&m_dfbSurface); + layer->GetWindow(layer,id,&dfbWindow); + dfbWindow->GetSurface(dfbWindow,&m_dfbSurface); +//WRONGSIZE QDirectFbBlitter *blitter = new QDirectFbBlitter(window->rect().size(), m_dfbSurface); m_pmdata = new QBlittablePixmapData(QPixmapData::PixmapType); m_pmdata->setBlittable(blitter); @@ -100,8 +70,7 @@ QDirectFbWindowSurface::QDirectFbWindowSurface(QWidget *window) QDirectFbWindowSurface::~QDirectFbWindowSurface() { - QDirectFbInput::instance()->removeWindow(this->window()); - m_dfbWindow->Destroy(m_dfbWindow); + } QPaintDevice *QDirectFbWindowSurface::paintDevice() @@ -111,11 +80,9 @@ QPaintDevice *QDirectFbWindowSurface::paintDevice() void QDirectFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { + Q_UNUSED(widget); m_pmdata->blittable()->unlock(); - const quint8 windowOpacity = quint8(widget->windowOpacity() * 0xff); - m_dfbWindow->SetOpacity(m_dfbWindow,windowOpacity); - QVector rects = region.rects(); for (int i = 0 ; i < rects.size(); i++) { const QRect rect = rects.at(i); @@ -124,17 +91,13 @@ void QDirectFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const } } -void QDirectFbWindowSurface::setGeometry(const QRect &rect) +void QDirectFbWindowSurface::resize(const QSize &size) { - m_pmdata->blittable()->unlock(); - - QWindowSurface::setGeometry(rect); - m_dfbWindow->SetBounds(m_dfbWindow, rect.x(),rect.y(), - rect.width(), rect.height()); + QWindowSurface::resize(size); //Have to add 1 ref ass it will be removed by deleting the old blitter in setBlittable m_dfbSurface->AddRef(m_dfbSurface); - QDirectFbBlitter *blitter = new QDirectFbBlitter(rect.size(),m_dfbSurface); + QDirectFbBlitter *blitter = new QDirectFbBlitter(size,m_dfbSurface); m_pmdata->setBlittable(blitter); } @@ -175,57 +138,4 @@ void QDirectFbWindowSurface::endPaint(const QRegion ®ion) Q_UNUSED(region); } -void QDirectFbWindowSurface::setVisible(bool visible) -{ - m_pmdata->blittable()->unlock(); - - if (visible) { - int x = this->geometry().x(); - int y = this->geometry().y(); - m_dfbWindow->MoveTo(m_dfbWindow,x,y); - } else { - IDirectFBDisplayLayer *displayLayer; - QDirectFbConvenience::dfbInterface()->GetDisplayLayer(QDirectFbConvenience::dfbInterface(),DLID_PRIMARY,&displayLayer); - - DFBDisplayLayerConfig config; - displayLayer->GetConfiguration(displayLayer,&config); - m_dfbWindow->MoveTo(m_dfbWindow,config.width+1,config.height + 1); - } -} - -Qt::WindowFlags QDirectFbWindowSurface::setWindowFlags(Qt::WindowFlags flags) -{ - switch (flags & Qt::WindowType_Mask) { - case Qt::ToolTip: { - DFBWindowOptions options; - m_dfbWindow->GetOptions(m_dfbWindow,&options); - options = DFBWindowOptions(options | DWOP_GHOST); - m_dfbWindow->SetOptions(m_dfbWindow,options); - break; } - default: - break; - } - - m_dfbWindow->SetStackingClass(m_dfbWindow, flags & Qt::WindowStaysOnTopHint ? DWSC_UPPER : DWSC_MIDDLE); - return flags; -} - -void QDirectFbWindowSurface::raise() -{ - m_dfbWindow->RaiseToTop(m_dfbWindow); -} - -void QDirectFbWindowSurface::lower() -{ - m_dfbWindow->LowerToBottom(m_dfbWindow); -} - -WId QDirectFbWindowSurface::winId() const -{ - DFBWindowID id; - m_dfbWindow->GetID(m_dfbWindow, &id); - return WId(id); -} - - QT_END_NAMESPACE diff --git a/src/plugins/platforms/directfb/qwindowsurface_directfb.h b/src/plugins/platforms/directfb/qwindowsurface_directfb.h index 2f31513..d48f534 100644 --- a/src/plugins/platforms/directfb/qwindowsurface_directfb.h +++ b/src/plugins/platforms/directfb/qwindowsurface_directfb.h @@ -49,37 +49,26 @@ QT_BEGIN_NAMESPACE -class QDirectFbGraphicsSystemScreen; - class QDirectFbWindowSurface : public QWindowSurface { public: - QDirectFbWindowSurface(QWidget *window); + QDirectFbWindowSurface(QWidget *window, WId wid); ~QDirectFbWindowSurface(); QPaintDevice *paintDevice(); void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void setGeometry(const QRect &rect); + void resize (const QSize &size); bool scroll(const QRegion &area, int dx, int dy); void beginPaint(const QRegion ®ion); void endPaint(const QRegion ®ion); - void setVisible(bool visible); - Qt::WindowFlags setWindowFlags(Qt::WindowFlags type); - - void raise(); - void lower(); - - WId winId() const; - private: void lockSurfaceToImage(); QPixmap *m_pixmap; QBlittablePixmapData *m_pmdata; - IDirectFBWindow *m_dfbWindow; IDirectFBSurface *m_dfbSurface; }; diff --git a/src/plugins/platforms/minimal/minimal.pro b/src/plugins/platforms/minimal/minimal.pro index 567b551..6c97f07 100644 --- a/src/plugins/platforms/minimal/minimal.pro +++ b/src/plugins/platforms/minimal/minimal.pro @@ -1,4 +1,4 @@ -TARGET = qminimalgraphicssystem +TARGET = qminimal include(../../qpluginbase.pri) QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp index 2f03127..404ffbc 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp @@ -20,9 +20,15 @@ QPixmapData *QMinimalIntegration::createPixmapData(QPixmapData::PixelType type) { return new QRasterPixmapData(type); } -void QMinimalIntegration::createWindowAndSurface(QPlatformWindow**window, QWindowSurface**surface, QWidget *widget, WId winId) const + +QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWidget *widget, WId winId) const +{ + Q_UNUSED(winId); + return new QPlatformWindow(widget); +} + +QWindowSurface *QMinimalIntegration::createWindowSurfaceForWindow(QWidget *widget, WId winId) const { - qDebug() << "createWindow"; - *surface = new QMinimalWindowSurface(widget); - *window = new QPlatformWindow(widget); + Q_UNUSED(winId); + return new QMinimalWindowSurface(widget); } diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.h b/src/plugins/platforms/minimal/qplatformintegration_minimal.h index 127c573..2e8a8cf 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.h +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.h @@ -72,7 +72,8 @@ public: QMinimalIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - void createWindowAndSurface(QPlatformWindow**window, QWindowSurface**surface, QWidget *widget, WId winId) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; QList screens() const { return mScreens; } -- cgit v0.12 From 6e41376f73cc54efd2e82df8b7bdd5797438e6c5 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Thu, 8 Apr 2010 15:02:17 +0200 Subject: Compile on Lighthouse after the windowsurface API change. --- src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp b/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp index 6bf9d6b..695050e 100644 --- a/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp +++ b/src/plugins/graphicssystems/trace/qgraphicssystem_trace.cpp @@ -98,7 +98,11 @@ QPaintDevice *QTraceWindowSurface::paintDevice() { if (!buffer) { buffer = new QPaintBuffer; +#ifdef Q_WS_LITE + buffer->setBoundingRect(QRect(QPoint(), size())); +#else buffer->setBoundingRect(geometry()); +#endif } return buffer; } -- cgit v0.12 From c3be673a149201d15cd8a7ca0a5047a7e24331fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Thu, 8 Apr 2010 14:57:36 +0200 Subject: Add the DirectFbWindow to the pro file --- src/plugins/platforms/directfb/directfb.pro | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/directfb/directfb.pro b/src/plugins/platforms/directfb/directfb.pro index f8fccaa..ec5f0f1 100644 --- a/src/plugins/platforms/directfb/directfb.pro +++ b/src/plugins/platforms/directfb/directfb.pro @@ -18,12 +18,14 @@ SOURCES = main.cpp \ qblitter_directfb.cpp \ qdirectfbconvenience.cpp \ qdirectfbinput.cpp \ - qdirectfbcursor.cpp + qdirectfbcursor.cpp \ + qdirectfbwindow.cpp HEADERS = qplatformintegration_directfb.h \ qwindowsurface_directfb.h \ qblitter_directfb.h \ qdirectfbconvenience.h \ qdirectfbinput.h \ - qdirectfbcursor.h + qdirectfbcursor.h \ + qdirectfbwindow.h target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target -- cgit v0.12 From b773920624a3420fb01071fe75c304a03051cfd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Thu, 8 Apr 2010 15:02:51 +0200 Subject: Fix "bug" in plugins.pro Dont build graphicssystems for lighthouse anymore --- src/plugins/plugins.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 73ab3e9..0e9a14c 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -6,7 +6,7 @@ unix:!symbian { } else { SUBDIRS *= codecs } -!embedded:!embedded-lite:SUBDIRS *= graphicssystems +!embedded:!embedded_lite:SUBDIRS *= graphicssystems embedded:SUBDIRS *= gfxdrivers decorations mousedrivers kbddrivers !win32:!embedded:!mac:!symbian:SUBDIRS *= inputmethods symbian:SUBDIRS += s60 -- cgit v0.12 From 473d152acc9fe0d04167406c0926363c3eddd16c Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 9 Apr 2010 10:25:06 +0200 Subject: Compile after the QPlatformWindow change ...but it doesn't *quite* work yet. --- .../testlite/qplatformintegration_testlite.cpp | 17 +++- .../testlite/qplatformintegration_testlite.h | 3 +- .../platforms/testlite/qwindowsurface_testlite.cpp | 109 ++++++++++++++------- .../platforms/testlite/qwindowsurface_testlite.h | 24 ++++- src/plugins/platforms/testlite/x11util.cpp | 18 ++-- src/plugins/platforms/testlite/x11util.h | 4 +- 6 files changed, 119 insertions(+), 56 deletions(-) diff --git a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp index 6811e2e..3e73821 100644 --- a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp +++ b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp @@ -57,20 +57,20 @@ public: MyCursor(QPlatformScreen *screen) : QGraphicsSystemCursor(screen) {} void changeCursor(QCursor * cursor, QWidget * widget) { - QTestLiteWindowSurface *ws = 0; + QTestLiteWindow *w = 0; if (widget) { QWidget *window = widget->window(); - ws = static_cast(window->windowSurface()); + w = static_cast(window->platformWindow()); } else { // No X11 cursor control when there is no widget under the cursor return; } //qDebug() << "changeCursor" << widget << ws; - if (!ws) + if (!w) return; - ws->setCursor(cursor); + w->setCursor(cursor); } }; @@ -101,7 +101,7 @@ QPixmapData *QTestLiteIntegration::createPixmapData(QPixmapData::PixelType type) return new QRasterPixmapData(type); } -QWindowSurface *QTestLiteIntegration::createWindowSurface(QWidget *widget) const +QWindowSurface *QTestLiteIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const { if (widget->windowType() == Qt::Desktop) return 0; // Don't create an explicit window surface for the destkop. @@ -110,6 +110,13 @@ QWindowSurface *QTestLiteIntegration::createWindowSurface(QWidget *widget) const } +QPlatformWindow *QTestLiteIntegration::createPlatformWindow(QWidget *widget, WId winId) const +{ + return new QTestLiteWindow(const_cast(this), mPrimaryScreen, widget); +} + + + QPixmap QTestLiteIntegration::grabWindow(WId window, int x, int y, int width, int height) const { QImage img = xd->grabWindow(window, x, y, width, height); diff --git a/src/plugins/platforms/testlite/qplatformintegration_testlite.h b/src/plugins/platforms/testlite/qplatformintegration_testlite.h index c540c48..bd27d89 100644 --- a/src/plugins/platforms/testlite/qplatformintegration_testlite.h +++ b/src/plugins/platforms/testlite/qplatformintegration_testlite.h @@ -74,7 +74,8 @@ public: QTestLiteIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; QPixmap grabWindow(WId window, int x, int y, int width, int height) const; diff --git a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp index e2574f9..801491c 100644 --- a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp +++ b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp @@ -58,19 +58,16 @@ QTestLiteWindowSurface::QTestLiteWindowSurface xw(0) { - - xw = new MyWindow(platformIntegration->xd, 0,0,300,300); - xw->windowSurface = this; + xw = static_cast(window->platformWindow())->xw; +// xw = new MyWindow(platformIntegration->xd, 0,0,300,300); // qDebug() << "QTestLiteWindowSurface::QTestLiteWindowSurface:" << xw->window; - setWindowFlags(window->windowFlags()); //##### This should not be the plugin's responsibility } QTestLiteWindowSurface::~QTestLiteWindowSurface() { // qDebug() << "~QTestLiteWindowSurface" << xw->window; - delete xw; } QPaintDevice *QTestLiteWindowSurface::paintDevice() @@ -90,18 +87,18 @@ void QTestLiteWindowSurface::flush(QWidget *widget, const QRegion ®ion, const } -void QTestLiteWindowSurface::setGeometry(const QRect &rect) -{ - QRect oldRect = geometry(); - if (rect == oldRect) - return; +// void QTestLiteWindowSurface::resize(const QSize &s) +// { +// if (s == size()) +// return; - QWindowSurface::setGeometry(rect); +// QWindowSurface::resize(size); - //if unchanged ### -// xw->setSize(rect.width(), rect.height()); - xw->setGeometry(rect.x(), rect.y(), rect.width(), rect.height()); -} +// //if unchanged ### +// // xw->setSize(rect.width(), rect.height()); + + +// } //### scroll logic copied from QRasterWindowSurface, we should make better API for this @@ -168,7 +165,8 @@ bool QTestLiteWindowSurface::scroll(const QRegion &area, int dx, int dy) void QTestLiteWindowSurface::beginPaint(const QRegion ®ion) { Q_UNUSED(region); - xw->resizeBuffer(geometry().size()); + qDebug() << "QTestLiteWindowSurface::beginPaint" << size(); + xw->resizeBuffer(size()); } void QTestLiteWindowSurface::endPaint(const QRegion ®ion) @@ -178,6 +176,29 @@ void QTestLiteWindowSurface::endPaint(const QRegion ®ion) } +/************************************************************************** +** QTestLiteWindow +**************************************************************************/ + +QTestLiteWindow::QTestLiteWindow(QTestLiteIntegration *platformIntegration, + QTestLiteScreen */*screen*/, QWidget *window) + :QPlatformWindow(window) +{ + xw = new MyWindow(platformIntegration->xd, 0,0,300,300); + setWindowFlags(window->windowFlags()); //##### This should not be the plugin's responsibility + + xw->windowTL = this; +} + + +QTestLiteWindow::~QTestLiteWindow() +{ + delete xw; +} + + + + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Mouse event stuff @@ -220,7 +241,7 @@ static Qt::KeyboardModifiers translateModifiers(int s) return ret; } -void QTestLiteWindowSurface::handleMouseEvent(QEvent::Type type, void *ev) +void QTestLiteWindow::handleMouseEvent(QEvent::Type type, void *ev) { static QPoint mousePoint; @@ -245,7 +266,7 @@ void QTestLiteWindowSurface::handleMouseEvent(QEvent::Type type, void *ev) bool hor = (((e->button == Button4 || e->button == Button5) && (modifiers & Qt::AltModifier)) || (e->button == 6 || e->button == 7)); - QWindowSystemInterface::handleWheelEvent(window(), e->time, + QWindowSystemInterface::handleWheelEvent(widget(), e->time, QPoint(e->x, e->y), QPoint(e->x_root, e->y_root), delta, hor ? Qt::Horizontal : Qt::Vertical); @@ -258,33 +279,33 @@ void QTestLiteWindowSurface::handleMouseEvent(QEvent::Type type, void *ev) buttons ^= button; // X event uses state *before*, Qt uses state *after* - QWindowSystemInterface::handleMouseEvent(window(), e->time, QPoint(e->x, e->y), + QWindowSystemInterface::handleMouseEvent(widget(), e->time, QPoint(e->x, e->y), QPoint(e->x_root, e->y_root), buttons); mousePoint = QPoint(e->x_root, e->y_root); } -void QTestLiteWindowSurface::handleGeometryChange(int x, int y, int w, int h) +void QTestLiteWindow::handleGeometryChange(int x, int y, int w, int h) { - QWindowSystemInterface::handleGeometryChange(window(), QRect(x,y,w,h)); + QWindowSystemInterface::handleGeometryChange(widget(), QRect(x,y,w,h)); } -void QTestLiteWindowSurface::handleCloseEvent() +void QTestLiteWindow::handleCloseEvent() { - QWindowSystemInterface::handleCloseEvent(window()); + QWindowSystemInterface::handleCloseEvent(widget()); } -void QTestLiteWindowSurface::handleEnterEvent() +void QTestLiteWindow::handleEnterEvent() { - QWindowSystemInterface::handleEnterEvent(window()); + QWindowSystemInterface::handleEnterEvent(widget()); } -void QTestLiteWindowSurface::handleLeaveEvent() +void QTestLiteWindow::handleLeaveEvent() { - QWindowSystemInterface::handleLeaveEvent(window()); + QWindowSystemInterface::handleLeaveEvent(widget()); } @@ -568,7 +589,7 @@ static Qt::KeyboardModifiers modifierFromKeyCode(int qtcode) } } -void QTestLiteWindowSurface::handleKeyEvent(QEvent::Type type, void *ev) +void QTestLiteWindow::handleKeyEvent(QEvent::Type type, void *ev) { XKeyEvent *e = static_cast(ev); @@ -592,12 +613,12 @@ void QTestLiteWindowSurface::handleKeyEvent(QEvent::Type type, void *ev) modifiers ^= modifierFromKeyCode(qtcode); if (qtcode) { - QWindowSystemInterface::handleKeyEvent(window(), e->time, type, qtcode, modifiers); + QWindowSystemInterface::handleKeyEvent(widget(), e->time, type, qtcode, modifiers); } else if (chars[0]) { int qtcode = chars.toUpper()[0]; //Not exactly right... if (modifiers & Qt::ControlModifier && qtcode < ' ') qtcode = chars[0] + '@'; - QWindowSystemInterface::handleKeyEvent(window(), e->time, type, qtcode, modifiers, QString::fromLatin1(chars)); + QWindowSystemInterface::handleKeyEvent(widget(), e->time, type, qtcode, modifiers, QString::fromLatin1(chars)); } else { qWarning() << "unknown X keycode" << hex << e->keycode << keySym; } @@ -605,7 +626,19 @@ void QTestLiteWindowSurface::handleKeyEvent(QEvent::Type type, void *ev) -Qt::WindowFlags QTestLiteWindowSurface::setWindowFlags(Qt::WindowFlags flags) +void QTestLiteWindow::setGeometry(const QRect &rect) +{ + QRect oldRect = geometry(); + if (rect == oldRect) + return; + + //if unchanged ### + xw->setGeometry(rect.x(), rect.y(), rect.width(), rect.height()); +} + + + +Qt::WindowFlags QTestLiteWindow::setWindowFlags(Qt::WindowFlags flags) { Q_ASSERT(flags & Qt::Window); @@ -617,19 +650,19 @@ Qt::WindowFlags QTestLiteWindowSurface::setWindowFlags(Qt::WindowFlags flags) } -Qt::WindowFlags QTestLiteWindowSurface::windowFlags() const +Qt::WindowFlags QTestLiteWindow::windowFlags() const { return window_flags; } -void QTestLiteWindowSurface::setVisible(bool visible) +void QTestLiteWindow::setVisible(bool visible) { //qDebug() << "QTestLiteWindowSurface::setVisible" << visible << xw->window; xw->setVisible(visible); } -WId QTestLiteWindowSurface::winId() const +WId QTestLiteWindow::winId() const { if (xw) return (WId) xw->window; @@ -637,24 +670,24 @@ WId QTestLiteWindowSurface::winId() const return WId(0); } -void QTestLiteWindowSurface::raise() +void QTestLiteWindow::raise() { WId window = winId(); XRaiseWindow(mPlatformIntegration->xd->display, window); } -void QTestLiteWindowSurface::lower() +void QTestLiteWindow::lower() { WId window = winId(); XLowerWindow(mPlatformIntegration->xd->display, window); } -void QTestLiteWindowSurface::setWindowTitle(const QString &title) +void QTestLiteWindow::setWindowTitle(const QString &title) { xw->setWindowTitle(title); } -void QTestLiteWindowSurface::setCursor(QCursor *cursor) +void QTestLiteWindow::setCursor(QCursor *cursor) { xw->setCursor(cursor); } diff --git a/src/plugins/platforms/testlite/qwindowsurface_testlite.h b/src/plugins/platforms/testlite/qwindowsurface_testlite.h index ffd2d3a..d713cc2 100644 --- a/src/plugins/platforms/testlite/qwindowsurface_testlite.h +++ b/src/plugins/platforms/testlite/qwindowsurface_testlite.h @@ -43,6 +43,7 @@ #define QWINDOWSURFACE_TESTLITE_H #include +#include #include QT_BEGIN_NAMESPACE @@ -61,12 +62,28 @@ public: QPaintDevice *paintDevice(); void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void setGeometry(const QRect &rect); +// void resize(const QSize &size); bool scroll(const QRegion &area, int dx, int dy); void beginPaint(const QRegion ®ion); void endPaint(const QRegion ®ion); +private: + QTestLiteIntegration *mPlatformIntegration; + QTestLiteScreen *mScreen; + Qt::WindowFlags window_flags; + MyWindow *xw; +}; + + +class QTestLiteWindow : public QPlatformWindow +{ +public: + QTestLiteWindow(QTestLiteIntegration *platformIntegration, + QTestLiteScreen *screen, QWidget *window); + ~QTestLiteWindow(); + + void handleMouseEvent(QEvent::Type, void *); //forwarding X types is apparently impossible :( void handleKeyEvent(QEvent::Type, void *); void handleGeometryChange(int x, int y, int w, int h); @@ -74,6 +91,8 @@ public: void handleEnterEvent(); void handleLeaveEvent(); + void setGeometry(const QRect &rect); + Qt::WindowFlags setWindowFlags(Qt::WindowFlags type); Qt::WindowFlags windowFlags() const; void setVisible(bool visible); @@ -89,8 +108,11 @@ private: QTestLiteScreen *mScreen; Qt::WindowFlags window_flags; MyWindow *xw; + + friend class QTestLiteWindowSurface; //### needs refactoring }; + QT_END_NAMESPACE #endif diff --git a/src/plugins/platforms/testlite/x11util.cpp b/src/plugins/platforms/testlite/x11util.cpp index 6d2966f..a869347 100644 --- a/src/plugins/platforms/testlite/x11util.cpp +++ b/src/plugins/platforms/testlite/x11util.cpp @@ -511,7 +511,7 @@ GC MyWindow::createGC() void MyWindow::closeEvent() { - windowSurface->handleCloseEvent(); + windowTL->handleCloseEvent(); } void MyWindow::paintEvent() @@ -633,7 +633,7 @@ void MyWindow::resizeEvent(XConfigureEvent *e) qDebug() << hex << window << dec << "ConfigureNotify" << e->x << e->y << e->width << e->height << "geometry" << xpos << ypos << width << height << "img:" << shm_img.size(); #endif - windowSurface->handleGeometryChange(xpos, ypos, width, height); + windowTL->handleGeometryChange(xpos, ypos, width, height); } #if 0 @@ -657,7 +657,7 @@ void MyWindow::enterEvent(XCrossingEvent *) #ifdef MYX11_DEBUG qDebug() << "MyWindow::enterEvent" << hex << window; #endif - windowSurface->handleEnterEvent(); + windowTL->handleEnterEvent(); } void MyWindow::leaveEvent(XCrossingEvent *) @@ -665,7 +665,7 @@ void MyWindow::leaveEvent(XCrossingEvent *) #ifdef MYX11_DEBUG qDebug() << "MyWindow::enterEvent" << hex << window; #endif - windowSurface->handleLeaveEvent(); + windowTL->handleLeaveEvent(); } void MyWindow::mousePressEvent(XButtonEvent *e) @@ -688,17 +688,17 @@ void MyWindow::mousePressEvent(XButtonEvent *e) prevX = e->x; prevY = e->y; - windowSurface->handleMouseEvent(type, e); + windowTL->handleMouseEvent(type, e); } void MyWindow::mouseReleaseEvent(XButtonEvent *e) { - windowSurface->handleMouseEvent(QEvent::MouseButtonRelease, e); + windowTL->handleMouseEvent(QEvent::MouseButtonRelease, e); } void MyWindow::mouseMoveEvent(XButtonEvent *e) { - windowSurface->handleMouseEvent(QEvent::MouseMove, e); + windowTL->handleMouseEvent(QEvent::MouseMove, e); } #ifdef KeyPress @@ -707,7 +707,7 @@ void MyWindow::mouseMoveEvent(XButtonEvent *e) void MyWindow::keyPressEvent(XKeyEvent *e) { - windowSurface->handleKeyEvent(QEvent::KeyPress, e); + windowTL->handleKeyEvent(QEvent::KeyPress, e); } #ifdef KeyRelease @@ -716,7 +716,7 @@ void MyWindow::keyPressEvent(XKeyEvent *e) void MyWindow::keyReleaseEvent(XKeyEvent *e) { - windowSurface->handleKeyEvent(QEvent::KeyRelease, e); + windowTL->handleKeyEvent(QEvent::KeyRelease, e); } diff --git a/src/plugins/platforms/testlite/x11util.h b/src/plugins/platforms/testlite/x11util.h index 79e7461..b28d1e8 100644 --- a/src/plugins/platforms/testlite/x11util.h +++ b/src/plugins/platforms/testlite/x11util.h @@ -85,7 +85,7 @@ public: //### MyX11Cursors * cursors; }; -class QTestLiteWindowSurface; //### abstract callback interface, anyone? +class QTestLiteWindow; //### abstract callback interface, anyone? struct MyShmImageInfo; @@ -133,7 +133,7 @@ public: //### MyDisplay *xd; GC gc; - QTestLiteWindowSurface *windowSurface; + QTestLiteWindow *windowTL; int currentCursor; bool painted; -- cgit v0.12 From 9020859ae8cf450a8f32608d54adfde089128355 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 9 Apr 2010 12:53:32 +0200 Subject: This seems to fix the resize issues --- src/gui/kernel/qapplication_lite.cpp | 1 + src/gui/painting/qbackingstore.cpp | 19 ++++++++++++++----- .../platforms/testlite/qwindowsurface_testlite.cpp | 1 - 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qapplication_lite.cpp b/src/gui/kernel/qapplication_lite.cpp index c8d65ff..87fa933 100644 --- a/src/gui/kernel/qapplication_lite.cpp +++ b/src/gui/kernel/qapplication_lite.cpp @@ -767,6 +767,7 @@ void QApplicationPrivate::processGeometryChange(QWidget *tlw, const QRect &newRe if (isResize) { QResizeEvent e(tlw->data->crect.size(), cr.size()); QApplication::sendSpontaneousEvent(tlw, &e); + tlw->update(); } if (isMove) { diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index 30c042e..cc16fd0 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -419,9 +419,12 @@ void QWidgetBackingStore::endPaint(const QRegion &cleaned, QWindowSurface *windo QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const { const bool widgetDirty = widget && widget != tlw; -#if !defined(Q_WS_LITE) const QRect tlwRect(topLevelRect()); +#if defined(Q_WS_LITE) + const QRect surfaceGeometry(tlwRect.topLeft(), windowSurface->size()); +#else const QRect surfaceGeometry(windowSurface->geometry()); +#endif if (surfaceGeometry != tlwRect && surfaceGeometry.size() != tlwRect.size()) { if (widgetDirty) { const QRect dirtyTlwRect = QRect(QPoint(), tlwRect.size()); @@ -431,7 +434,6 @@ QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const } return QRect(QPoint(), tlwRect.size()); } -#endif // Calculate the region that needs repaint. QRegion r(dirty); @@ -1156,11 +1158,14 @@ void QWidgetBackingStore::sync() const bool updatesDisabled = !tlw->updatesEnabled(); bool repaintAllWidgets = false; -#if !defined(Q_WS_LITE) + const bool inTopLevelResize = tlwExtra->inTopLevelResize; const QRect tlwRect(topLevelRect()); +#ifdef Q_WS_LITE + const QRect surfaceGeometry(tlwRect.topLeft(), windowSurface->size()); +#else const QRect surfaceGeometry(windowSurface->geometry()); - +#endif if (inTopLevelResize || surfaceGeometry != tlwRect) { if ((inTopLevelResize || surfaceGeometry.size() != tlwRect.size()) && !updatesDisabled) { if (hasStaticContents()) { @@ -1180,9 +1185,13 @@ void QWidgetBackingStore::sync() repaintAllWidgets = true; } } +#ifdef Q_WS_LITE + windowSurface->resize(tlwRect.size()); +#else windowSurface->setGeometry(tlwRect); - } #endif + } + if (updatesDisabled) return; diff --git a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp index 801491c..81fa247 100644 --- a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp +++ b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp @@ -165,7 +165,6 @@ bool QTestLiteWindowSurface::scroll(const QRegion &area, int dx, int dy) void QTestLiteWindowSurface::beginPaint(const QRegion ®ion) { Q_UNUSED(region); - qDebug() << "QTestLiteWindowSurface::beginPaint" << size(); xw->resizeBuffer(size()); } -- cgit v0.12 From 6dd82100e43749e3bd43b127587aa16a0bc4bbac Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 9 Apr 2010 17:25:22 +0200 Subject: Refactoring TestLite The x11util classes stopped being generic a long time ago. Now that we have a clean separation between surface and window in the API, it makes sense to have the platform-specific logic in the derived classes, instead of having an extra level of indirection. --- .../testlite/qplatformintegration_testlite.cpp | 9 +- src/plugins/platforms/testlite/qtestlitewindow.cpp | 1558 ++++++++++++++++++++ src/plugins/platforms/testlite/qtestlitewindow.h | 157 ++ .../platforms/testlite/qwindowsurface_testlite.cpp | 671 ++------- .../platforms/testlite/qwindowsurface_testlite.h | 54 +- src/plugins/platforms/testlite/testlite.pro | 8 +- src/plugins/platforms/testlite/x11util.cpp | 1215 --------------- src/plugins/platforms/testlite/x11util.h | 204 --- 8 files changed, 1860 insertions(+), 2016 deletions(-) create mode 100644 src/plugins/platforms/testlite/qtestlitewindow.cpp create mode 100644 src/plugins/platforms/testlite/qtestlitewindow.h delete mode 100644 src/plugins/platforms/testlite/x11util.cpp delete mode 100644 src/plugins/platforms/testlite/x11util.h diff --git a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp index 3e73821..f9b3135 100644 --- a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp +++ b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp @@ -39,6 +39,8 @@ ** ****************************************************************************/ + + #include "qplatformintegration_testlite.h" #include "qwindowsurface_testlite.h" #include @@ -47,7 +49,7 @@ #include -#include "x11util.h" +#include "qtestlitewindow.h" QT_BEGIN_NAMESPACE @@ -105,12 +107,11 @@ QWindowSurface *QTestLiteIntegration::createWindowSurfaceForWindow(QWidget *widg { if (widget->windowType() == Qt::Desktop) return 0; // Don't create an explicit window surface for the destkop. - return new QTestLiteWindowSurface - (const_cast(this), mPrimaryScreen, widget); + return new QTestLiteWindowSurface(mPrimaryScreen, widget); } -QPlatformWindow *QTestLiteIntegration::createPlatformWindow(QWidget *widget, WId winId) const +QPlatformWindow *QTestLiteIntegration::createPlatformWindow(QWidget *widget, WId /*winId*/) const { return new QTestLiteWindow(const_cast(this), mPrimaryScreen, widget); } diff --git a/src/plugins/platforms/testlite/qtestlitewindow.cpp b/src/plugins/platforms/testlite/qtestlitewindow.cpp new file mode 100644 index 0000000..db3904f --- /dev/null +++ b/src/plugins/platforms/testlite/qtestlitewindow.cpp @@ -0,0 +1,1558 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwindowsurface_testlite.h" +#include "qplatformintegration_testlite.h" +#include + +#include "qtestlitewindow.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + + +#include + +#include + + + +//### remove stuff we don't want from qt_x11_p.h +#undef ATOM +#undef X11 + +QT_BEGIN_NAMESPACE + +static int (*original_x_errhandler)(Display *dpy, XErrorEvent *); +static bool seen_badwindow; + + +static Atom wmProtocolsAtom; +static Atom wmDeleteWindowAtom; + + + +class MyX11CursorNode +{ +public: + MyX11CursorNode(int id, Cursor c) { idValue = id; cursorValue = c; refCount = 1; } + QDateTime expiration() { return t; } + void setExpiration(QDateTime val) { t = val; } + MyX11CursorNode * ante() { return before; } + void setAnte(MyX11CursorNode *node) { before = node; } + MyX11CursorNode * post() { return after; } + void setPost(MyX11CursorNode *node) { after = node; } + Cursor cursor() { return cursorValue; } + int id() { return idValue; } + unsigned int refCount; + +private: + MyX11CursorNode *before; + MyX11CursorNode *after; + QDateTime t; + Cursor cursorValue; + int idValue; + + Display * display; +}; + + + + + +class MyX11Cursors : public QObject +{ + Q_OBJECT +public: + MyX11Cursors(Display * d); + ~MyX11Cursors() { timer.stop(); } + void incrementUseCount(int id); + void decrementUseCount(int id); + void createNode(int id, Cursor c); + bool exists(int id) { return lookupMap.contains(id); } + Cursor cursor(int id); +public slots: + void timeout(); + +private: + void removeNode(MyX11CursorNode *node); + void insertNode(MyX11CursorNode *node); + + // linked list of cursors currently not assigned to any window + MyX11CursorNode *firstExpired; + MyX11CursorNode *lastExpired; + + QHash lookupMap; + QTimer timer; + + Display *display; + + int removalDelay; +}; + + + + + +QTestLiteWindow::QTestLiteWindow(QTestLiteIntegration *platformIntegration, + QTestLiteScreen */*screen*/, QWidget *window) + :QPlatformWindow(window) +{ + xd = platformIntegration->xd; + xd->windowList.append(this); + { + int x = 0; + int y = 0; + int w = 300; + int h = 300; //### + + x_window = XCreateSimpleWindow(xd->display, xd->rootWindow(), + x, y, w, h, 0 /*border_width*/, + xd->blackPixel(), xd->whitePixel()); + + } + + width = -1; + height = -1; + xpos = -1; + ypos = -1; + + XSetWindowBackgroundPixmap(xd->display, x_window, XNone); + + XSelectInput(xd->display, x_window, ExposureMask | KeyPressMask | KeyReleaseMask | + EnterWindowMask | LeaveWindowMask | FocusChangeMask | + PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | + StructureNotifyMask); + + gc = createGC(); + + XChangeProperty (xd->display, x_window, + wmProtocolsAtom, + XA_ATOM, 32, PropModeAppend, + (unsigned char *) &wmDeleteWindowAtom, 1); + + + setWindowTitle(QLatin1String("Qt Lighthouse")); + + currentCursor = -1; + windowSurface = 0; + + setWindowFlags(window->windowFlags()); //##### This should not be the plugin's responsibility + + //xw->windowTL = this; +} + + +QTestLiteWindow::~QTestLiteWindow() +{ +#ifdef MYX11_DEBUG + qDebug() << "~QTestLiteWindow" << hex << x_window; +#endif + XFreeGC(xd->display, gc); + XDestroyWindow(xd->display, x_window); + + xd->windowList.removeAll(this); +} + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Mouse event stuff + + + + +static Qt::MouseButtons translateMouseButtons(int s) +{ + Qt::MouseButtons ret = 0; + if (s & Button1Mask) + ret |= Qt::LeftButton; + if (s & Button2Mask) + ret |= Qt::MidButton; + if (s & Button3Mask) + ret |= Qt::RightButton; + return ret; +} + + +static Qt::KeyboardModifiers translateModifiers(int s) +{ + const uchar qt_alt_mask = Mod1Mask; + const uchar qt_meta_mask = Mod4Mask; + + + Qt::KeyboardModifiers ret = 0; + if (s & ShiftMask) + ret |= Qt::ShiftModifier; + if (s & ControlMask) + ret |= Qt::ControlModifier; + if (s & qt_alt_mask) + ret |= Qt::AltModifier; + if (s & qt_meta_mask) + ret |= Qt::MetaModifier; +#if 0 + if (s & qt_mode_switch_mask) + ret |= Qt::GroupSwitchModifier; +#endif + return ret; +} + +void QTestLiteWindow::handleMouseEvent(QEvent::Type type, XButtonEvent *e) +{ + static QPoint mousePoint; + + Qt::MouseButton button = Qt::NoButton; + Qt::MouseButtons buttons = translateMouseButtons(e->state); + Qt::KeyboardModifiers modifiers = translateModifiers(e->state); + if (type != QEvent::MouseMove) { + switch (e->button) { + case Button1: button = Qt::LeftButton; break; + case Button2: button = Qt::MidButton; break; + case Button3: button = Qt::RightButton; break; + case Button4: + case Button5: + case 6: + case 7: { + //mouse wheel + if (type == QEvent::MouseButtonPress) { + //logic borrowed from qapplication_x11.cpp + int delta = 120 * ((e->button == Button4 || e->button == 6) ? 1 : -1); + bool hor = (((e->button == Button4 || e->button == Button5) + && (modifiers & Qt::AltModifier)) + || (e->button == 6 || e->button == 7)); + QWindowSystemInterface::handleWheelEvent(widget(), e->time, + QPoint(e->x, e->y), + QPoint(e->x_root, e->y_root), + delta, hor ? Qt::Horizontal : Qt::Vertical); + } + return; + } + default: break; + } + } + + buttons ^= button; // X event uses state *before*, Qt uses state *after* + + QWindowSystemInterface::handleMouseEvent(widget(), e->time, QPoint(e->x, e->y), + QPoint(e->x_root, e->y_root), + buttons); + + mousePoint = QPoint(e->x_root, e->y_root); +} + +void QTestLiteWindow::handleCloseEvent() +{ + QWindowSystemInterface::handleCloseEvent(widget()); +} + + +void QTestLiteWindow::handleEnterEvent() +{ + QWindowSystemInterface::handleEnterEvent(widget()); +} + +void QTestLiteWindow::handleLeaveEvent() +{ + QWindowSystemInterface::handleLeaveEvent(widget()); +} + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Key event stuff -- not pretty either +// +// What we want to do is to port Robert's keytable code properly + +// keyboard mapping table +static const unsigned int keyTbl[] = { + + // misc keys + + XK_Escape, Qt::Key_Escape, + XK_Tab, Qt::Key_Tab, + XK_ISO_Left_Tab, Qt::Key_Backtab, + XK_BackSpace, Qt::Key_Backspace, + XK_Return, Qt::Key_Return, + XK_Insert, Qt::Key_Insert, + XK_Delete, Qt::Key_Delete, + XK_Clear, Qt::Key_Delete, + XK_Pause, Qt::Key_Pause, + XK_Print, Qt::Key_Print, + 0x1005FF60, Qt::Key_SysReq, // hardcoded Sun SysReq + 0x1007ff00, Qt::Key_SysReq, // hardcoded X386 SysReq + + // cursor movement + + XK_Home, Qt::Key_Home, + XK_End, Qt::Key_End, + XK_Left, Qt::Key_Left, + XK_Up, Qt::Key_Up, + XK_Right, Qt::Key_Right, + XK_Down, Qt::Key_Down, + XK_Prior, Qt::Key_PageUp, + XK_Next, Qt::Key_PageDown, + + // modifiers + + XK_Shift_L, Qt::Key_Shift, + XK_Shift_R, Qt::Key_Shift, + XK_Shift_Lock, Qt::Key_Shift, + XK_Control_L, Qt::Key_Control, + XK_Control_R, Qt::Key_Control, + XK_Meta_L, Qt::Key_Meta, + XK_Meta_R, Qt::Key_Meta, + XK_Alt_L, Qt::Key_Alt, + XK_Alt_R, Qt::Key_Alt, + XK_Caps_Lock, Qt::Key_CapsLock, + XK_Num_Lock, Qt::Key_NumLock, + XK_Scroll_Lock, Qt::Key_ScrollLock, + XK_Super_L, Qt::Key_Super_L, + XK_Super_R, Qt::Key_Super_R, + XK_Menu, Qt::Key_Menu, + XK_Hyper_L, Qt::Key_Hyper_L, + XK_Hyper_R, Qt::Key_Hyper_R, + XK_Help, Qt::Key_Help, + 0x1000FF74, Qt::Key_Backtab, // hardcoded HP backtab + 0x1005FF10, Qt::Key_F11, // hardcoded Sun F36 (labeled F11) + 0x1005FF11, Qt::Key_F12, // hardcoded Sun F37 (labeled F12) + + // numeric and function keypad keys + + XK_KP_Space, Qt::Key_Space, + XK_KP_Tab, Qt::Key_Tab, + XK_KP_Enter, Qt::Key_Enter, + //XK_KP_F1, Qt::Key_F1, + //XK_KP_F2, Qt::Key_F2, + //XK_KP_F3, Qt::Key_F3, + //XK_KP_F4, Qt::Key_F4, + XK_KP_Home, Qt::Key_Home, + XK_KP_Left, Qt::Key_Left, + XK_KP_Up, Qt::Key_Up, + XK_KP_Right, Qt::Key_Right, + XK_KP_Down, Qt::Key_Down, + XK_KP_Prior, Qt::Key_PageUp, + XK_KP_Next, Qt::Key_PageDown, + XK_KP_End, Qt::Key_End, + XK_KP_Begin, Qt::Key_Clear, + XK_KP_Insert, Qt::Key_Insert, + XK_KP_Delete, Qt::Key_Delete, + XK_KP_Equal, Qt::Key_Equal, + XK_KP_Multiply, Qt::Key_Asterisk, + XK_KP_Add, Qt::Key_Plus, + XK_KP_Separator, Qt::Key_Comma, + XK_KP_Subtract, Qt::Key_Minus, + XK_KP_Decimal, Qt::Key_Period, + XK_KP_Divide, Qt::Key_Slash, + + // International input method support keys + + // International & multi-key character composition + XK_ISO_Level3_Shift, Qt::Key_AltGr, + XK_Multi_key, Qt::Key_Multi_key, + XK_Codeinput, Qt::Key_Codeinput, + XK_SingleCandidate, Qt::Key_SingleCandidate, + XK_MultipleCandidate, Qt::Key_MultipleCandidate, + XK_PreviousCandidate, Qt::Key_PreviousCandidate, + + // Misc Functions + XK_Mode_switch, Qt::Key_Mode_switch, + XK_script_switch, Qt::Key_Mode_switch, + + // Japanese keyboard support + XK_Kanji, Qt::Key_Kanji, + XK_Muhenkan, Qt::Key_Muhenkan, + //XK_Henkan_Mode, Qt::Key_Henkan_Mode, + XK_Henkan_Mode, Qt::Key_Henkan, + XK_Henkan, Qt::Key_Henkan, + XK_Romaji, Qt::Key_Romaji, + XK_Hiragana, Qt::Key_Hiragana, + XK_Katakana, Qt::Key_Katakana, + XK_Hiragana_Katakana, Qt::Key_Hiragana_Katakana, + XK_Zenkaku, Qt::Key_Zenkaku, + XK_Hankaku, Qt::Key_Hankaku, + XK_Zenkaku_Hankaku, Qt::Key_Zenkaku_Hankaku, + XK_Touroku, Qt::Key_Touroku, + XK_Massyo, Qt::Key_Massyo, + XK_Kana_Lock, Qt::Key_Kana_Lock, + XK_Kana_Shift, Qt::Key_Kana_Shift, + XK_Eisu_Shift, Qt::Key_Eisu_Shift, + XK_Eisu_toggle, Qt::Key_Eisu_toggle, + //XK_Kanji_Bangou, Qt::Key_Kanji_Bangou, + //XK_Zen_Koho, Qt::Key_Zen_Koho, + //XK_Mae_Koho, Qt::Key_Mae_Koho, + XK_Kanji_Bangou, Qt::Key_Codeinput, + XK_Zen_Koho, Qt::Key_MultipleCandidate, + XK_Mae_Koho, Qt::Key_PreviousCandidate, + +#ifdef XK_KOREAN + // Korean keyboard support + XK_Hangul, Qt::Key_Hangul, + XK_Hangul_Start, Qt::Key_Hangul_Start, + XK_Hangul_End, Qt::Key_Hangul_End, + XK_Hangul_Hanja, Qt::Key_Hangul_Hanja, + XK_Hangul_Jamo, Qt::Key_Hangul_Jamo, + XK_Hangul_Romaja, Qt::Key_Hangul_Romaja, + //XK_Hangul_Codeinput, Qt::Key_Hangul_Codeinput, + XK_Hangul_Codeinput, Qt::Key_Codeinput, + XK_Hangul_Jeonja, Qt::Key_Hangul_Jeonja, + XK_Hangul_Banja, Qt::Key_Hangul_Banja, + XK_Hangul_PreHanja, Qt::Key_Hangul_PreHanja, + XK_Hangul_PostHanja, Qt::Key_Hangul_PostHanja, + //XK_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate, + //XK_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate, + //XK_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate, + XK_Hangul_SingleCandidate, Qt::Key_SingleCandidate, + XK_Hangul_MultipleCandidate,Qt::Key_MultipleCandidate, + XK_Hangul_PreviousCandidate,Qt::Key_PreviousCandidate, + XK_Hangul_Special, Qt::Key_Hangul_Special, + //XK_Hangul_switch, Qt::Key_Hangul_switch, + XK_Hangul_switch, Qt::Key_Mode_switch, +#endif // XK_KOREAN + + // dead keys + XK_dead_grave, Qt::Key_Dead_Grave, + XK_dead_acute, Qt::Key_Dead_Acute, + XK_dead_circumflex, Qt::Key_Dead_Circumflex, + XK_dead_tilde, Qt::Key_Dead_Tilde, + XK_dead_macron, Qt::Key_Dead_Macron, + XK_dead_breve, Qt::Key_Dead_Breve, + XK_dead_abovedot, Qt::Key_Dead_Abovedot, + XK_dead_diaeresis, Qt::Key_Dead_Diaeresis, + XK_dead_abovering, Qt::Key_Dead_Abovering, + XK_dead_doubleacute, Qt::Key_Dead_Doubleacute, + XK_dead_caron, Qt::Key_Dead_Caron, + XK_dead_cedilla, Qt::Key_Dead_Cedilla, + XK_dead_ogonek, Qt::Key_Dead_Ogonek, + XK_dead_iota, Qt::Key_Dead_Iota, + XK_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound, + XK_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound, + XK_dead_belowdot, Qt::Key_Dead_Belowdot, + XK_dead_hook, Qt::Key_Dead_Hook, + XK_dead_horn, Qt::Key_Dead_Horn, + +#if 0 + // Special multimedia keys + // currently only tested with MS internet keyboard + + // browsing keys + XF86XK_Back, Qt::Key_Back, + XF86XK_Forward, Qt::Key_Forward, + XF86XK_Stop, Qt::Key_Stop, + XF86XK_Refresh, Qt::Key_Refresh, + XF86XK_Favorites, Qt::Key_Favorites, + XF86XK_AudioMedia, Qt::Key_LaunchMedia, + XF86XK_OpenURL, Qt::Key_OpenUrl, + XF86XK_HomePage, Qt::Key_HomePage, + XF86XK_Search, Qt::Key_Search, + + // media keys + XF86XK_AudioLowerVolume, Qt::Key_VolumeDown, + XF86XK_AudioMute, Qt::Key_VolumeMute, + XF86XK_AudioRaiseVolume, Qt::Key_VolumeUp, + XF86XK_AudioPlay, Qt::Key_MediaPlay, + XF86XK_AudioStop, Qt::Key_MediaStop, + XF86XK_AudioPrev, Qt::Key_MediaPrevious, + XF86XK_AudioNext, Qt::Key_MediaNext, + XF86XK_AudioRecord, Qt::Key_MediaRecord, + + // launch keys + XF86XK_Mail, Qt::Key_LaunchMail, + XF86XK_MyComputer, Qt::Key_Launch0, + XF86XK_Calculator, Qt::Key_Launch1, + XF86XK_Standby, Qt::Key_Standby, + + XF86XK_Launch0, Qt::Key_Launch2, + XF86XK_Launch1, Qt::Key_Launch3, + XF86XK_Launch2, Qt::Key_Launch4, + XF86XK_Launch3, Qt::Key_Launch5, + XF86XK_Launch4, Qt::Key_Launch6, + XF86XK_Launch5, Qt::Key_Launch7, + XF86XK_Launch6, Qt::Key_Launch8, + XF86XK_Launch7, Qt::Key_Launch9, + XF86XK_Launch8, Qt::Key_LaunchA, + XF86XK_Launch9, Qt::Key_LaunchB, + XF86XK_LaunchA, Qt::Key_LaunchC, + XF86XK_LaunchB, Qt::Key_LaunchD, + XF86XK_LaunchC, Qt::Key_LaunchE, + XF86XK_LaunchD, Qt::Key_LaunchF, +#endif + +#if 0 + // Qtopia keys + QTOPIAXK_Select, Qt::Key_Select, + QTOPIAXK_Yes, Qt::Key_Yes, + QTOPIAXK_No, Qt::Key_No, + QTOPIAXK_Cancel, Qt::Key_Cancel, + QTOPIAXK_Printer, Qt::Key_Printer, + QTOPIAXK_Execute, Qt::Key_Execute, + QTOPIAXK_Sleep, Qt::Key_Sleep, + QTOPIAXK_Play, Qt::Key_Play, + QTOPIAXK_Zoom, Qt::Key_Zoom, + QTOPIAXK_Context1, Qt::Key_Context1, + QTOPIAXK_Context2, Qt::Key_Context2, + QTOPIAXK_Context3, Qt::Key_Context3, + QTOPIAXK_Context4, Qt::Key_Context4, + QTOPIAXK_Call, Qt::Key_Call, + QTOPIAXK_Hangup, Qt::Key_Hangup, + QTOPIAXK_Flip, Qt::Key_Flip, +#endif + 0, 0 +}; + + +static int lookupCode(unsigned int xkeycode) +{ + if (xkeycode >= XK_F1 && xkeycode <= XK_F35) + return Qt::Key_F1 + (int(xkeycode) - XK_F1); + + const unsigned int *p = keyTbl; + while (*p) { + if (*p == xkeycode) + return *++p; + p += 2; + } + + return 0; +} + + +static Qt::KeyboardModifiers modifierFromKeyCode(int qtcode) +{ + switch (qtcode) { + case Qt::Key_Control: + return Qt::ControlModifier; + case Qt::Key_Alt: + return Qt::AltModifier; + case Qt::Key_Shift: + return Qt::ShiftModifier; + case Qt::Key_Meta: + return Qt::MetaModifier; + default: + return Qt::NoModifier; + } +} + +void QTestLiteWindow::handleKeyEvent(QEvent::Type type, void *ev) +{ + XKeyEvent *e = static_cast(ev); + + KeySym keySym; + QByteArray chars; + chars.resize(513); + + int count = XLookupString(e, chars.data(), chars.size(), &keySym, 0); + Q_UNUSED(count); +// qDebug() << "QTLWS::handleKeyEvent" << count << hex << "XKeysym:" << keySym; +// if (count) +// qDebug() << hex << int(chars[0]) << "String:" << chars; + + Qt::KeyboardModifiers modifiers = translateModifiers(e->state); + + int qtcode = lookupCode(keySym); +// qDebug() << "lookup: " << hex << keySym << qtcode << "mod" << modifiers; + + //X11 specifies state *before*, Qt expects state *after* the event + + modifiers ^= modifierFromKeyCode(qtcode); + + if (qtcode) { + QWindowSystemInterface::handleKeyEvent(widget(), e->time, type, qtcode, modifiers); + } else if (chars[0]) { + int qtcode = chars.toUpper()[0]; //Not exactly right... + if (modifiers & Qt::ControlModifier && qtcode < ' ') + qtcode = chars[0] + '@'; + QWindowSystemInterface::handleKeyEvent(widget(), e->time, type, qtcode, modifiers, QString::fromLatin1(chars)); + } else { + qWarning() << "unknown X keycode" << hex << e->keycode << keySym; + } +} + +void QTestLiteWindow::setGeometry(const QRect &rect) +{ + QRect oldRect = geometry(); + if (rect == oldRect) + return; + + //if unchanged ### + XMoveResizeWindow(xd->display, x_window, rect.x(), rect.y(), rect.width(), rect.height()); +} + + +Qt::WindowFlags QTestLiteWindow::windowFlags() const +{ + return window_flags; +} + +WId QTestLiteWindow::winId() const +{ + return x_window; +} + +void QTestLiteWindow::raise() +{ + XRaiseWindow(mPlatformIntegration->xd->display, x_window); +} + +void QTestLiteWindow::lower() +{ + XLowerWindow(mPlatformIntegration->xd->display, x_window); +} + +void QTestLiteWindow::setWindowTitle(const QString &title) +{ + QByteArray ba = title.toLatin1(); //We're not making a general solution here... + XTextProperty windowName; + windowName.value = (unsigned char *)ba.constData(); + windowName.encoding = XA_STRING; + windowName.format = 8; + windowName.nitems = ba.length(); + + XSetWMName(xd->display, x_window, &windowName); +} + + + +GC QTestLiteWindow::createGC() +{ + GC gc; + + gc = XCreateGC(xd->display, x_window, 0, 0); + if (gc < 0) { + qWarning("QTestLiteWindow::createGC() could not create GC"); + } + return gc; +} + + +void QTestLiteWindow::paintEvent() +{ +#ifdef MYX11_DEBUG + qDebug() << "QTestLiteWindow::paintEvent" << shm_img.size() << painted; +#endif + + windowSurface->flush(windowSurface->window(), QRect(xpos,ypos,width, height), QPoint()); +} + + +void QTestLiteWindow::resizeEvent(XConfigureEvent *e) +{ + + if ((e->width != width || e->height != height) && e->x == 0 && e->y == 0) { + //qDebug() << "resize with bogus pos" << e->x << e->y << e->width << e->height << "window"<< hex << window; + } else { + //qDebug() << "geometry change" << e->x << e->y << e->width << e->height << "window"<< hex << window; + xpos = e->x; + ypos = e->y; + } + width = e->width; + height = e->height; + +#ifdef MYX11_DEBUG + qDebug() << hex << window << dec << "ConfigureNotify" << e->x << e->y << e->width << e->height << "geometry" << xpos << ypos << width << height << "img:" << shm_img.size(); +#endif + + QWindowSystemInterface::handleGeometryChange(widget(), QRect(xpos, ypos, width, height)); +} + + +void QTestLiteWindow::mousePressEvent(XButtonEvent *e) +{ + static long prevTime = 0; + static Window prevWindow; + static int prevX = -999; + static int prevY = -999; + + QEvent::Type type = QEvent::MouseButtonPress; + + if (e->window == prevWindow && long(e->time) - prevTime < QApplication::doubleClickInterval() + && qAbs(e->x - prevX) < 5 && qAbs(e->y - prevY) < 5) { + type = QEvent::MouseButtonDblClick; + prevTime = e->time - QApplication::doubleClickInterval(); //no double click next time + } else { + prevTime = e->time; + } + prevWindow = e->window; + prevX = e->x; + prevY = e->y; + + handleMouseEvent(type, e); +} + + + +// WindowFlag stuff, lots of copied code from qwidget_x11.cpp... + +//We're hacking here... + + +// MWM support +struct QtMWMHints { + ulong flags, functions, decorations; + long input_mode; + ulong status; +}; + +enum { + MWM_HINTS_FUNCTIONS = (1L << 0), + + MWM_FUNC_ALL = (1L << 0), + MWM_FUNC_RESIZE = (1L << 1), + MWM_FUNC_MOVE = (1L << 2), + MWM_FUNC_MINIMIZE = (1L << 3), + MWM_FUNC_MAXIMIZE = (1L << 4), + MWM_FUNC_CLOSE = (1L << 5), + + MWM_HINTS_DECORATIONS = (1L << 1), + + MWM_DECOR_ALL = (1L << 0), + MWM_DECOR_BORDER = (1L << 1), + MWM_DECOR_RESIZEH = (1L << 2), + MWM_DECOR_TITLE = (1L << 3), + MWM_DECOR_MENU = (1L << 4), + MWM_DECOR_MINIMIZE = (1L << 5), + MWM_DECOR_MAXIMIZE = (1L << 6), + + MWM_HINTS_INPUT_MODE = (1L << 2), + + MWM_INPUT_MODELESS = 0L, + MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L, + MWM_INPUT_FULL_APPLICATION_MODAL = 3L +}; + +static Atom mwm_hint_atom = XNone; + +#if 0 +static QtMWMHints GetMWMHints(Display *display, Window window) +{ + QtMWMHints mwmhints; + + Atom type; + int format; + ulong nitems, bytesLeft; + uchar *data = 0; + if ((XGetWindowProperty(display, window, mwm_hint_atom, 0, 5, false, + mwm_hint_atom, &type, &format, &nitems, &bytesLeft, + &data) == Success) + && (type == mwm_hint_atom + && format == 32 + && nitems >= 5)) { + mwmhints = *(reinterpret_cast(data)); + } else { + mwmhints.flags = 0L; + mwmhints.functions = MWM_FUNC_ALL; + mwmhints.decorations = MWM_DECOR_ALL; + mwmhints.input_mode = 0L; + mwmhints.status = 0L; + } + + if (data) + XFree(data); + + return mwmhints; +} +#endif + +static void SetMWMHints(Display *display, Window window, const QtMWMHints &mwmhints) +{ + if (mwmhints.flags != 0l) { + XChangeProperty(display, window, mwm_hint_atom, mwm_hint_atom, 32, + PropModeReplace, (unsigned char *) &mwmhints, 5); + } else { + XDeleteProperty(display, window, mwm_hint_atom); + } +} + +// Returns true if we should set WM_TRANSIENT_FOR on \a w +static inline bool isTransient(const QWidget *w) +{ + return ((w->windowType() == Qt::Dialog + || w->windowType() == Qt::Sheet + || w->windowType() == Qt::Tool + || w->windowType() == Qt::SplashScreen + || w->windowType() == Qt::ToolTip + || w->windowType() == Qt::Drawer + || w->windowType() == Qt::Popup) + && !w->testAttribute(Qt::WA_X11BypassTransientForHint)); +} + + + +Qt::WindowFlags QTestLiteWindow::setWindowFlags(Qt::WindowFlags flags) +{ + Q_ASSERT(flags & Qt::Window); + window_flags = flags; + + if (mwm_hint_atom == XNone) { + mwm_hint_atom = XInternAtom(xd->display, "_MOTIF_WM_HINTS\0", False); + } + +#ifdef MYX11_DEBUG + qDebug() << "QTestLiteWindow::setWindowFlags" << hex << window << "flags" << flags; +#endif + Qt::WindowType type = static_cast(int(flags & Qt::WindowType_Mask)); + + if (type == Qt::ToolTip) + flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint; + if (type == Qt::Popup) + flags |= Qt::X11BypassWindowManagerHint; + + bool topLevel = (flags & Qt::Window); + bool popup = (type == Qt::Popup); + bool dialog = (type == Qt::Dialog + || type == Qt::Sheet); + bool desktop = (type == Qt::Desktop); + bool tool = (type == Qt::Tool || type == Qt::SplashScreen + || type == Qt::ToolTip || type == Qt::Drawer); + + + Q_UNUSED(topLevel); + Q_UNUSED(dialog); + Q_UNUSED(desktop); + + + bool tooltip = (type == Qt::ToolTip); + + XSetWindowAttributes wsa; + + QtMWMHints mwmhints; + mwmhints.flags = 0L; + mwmhints.functions = 0L; + mwmhints.decorations = 0; + mwmhints.input_mode = 0L; + mwmhints.status = 0L; + + + ulong wsa_mask = 0; + if (type != Qt::SplashScreen) { // && customize) { + mwmhints.flags |= MWM_HINTS_DECORATIONS; + + bool customize = flags & Qt::CustomizeWindowHint; + if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) { + mwmhints.decorations |= MWM_DECOR_BORDER; + mwmhints.decorations |= MWM_DECOR_RESIZEH; + + if (flags & Qt::WindowTitleHint) + mwmhints.decorations |= MWM_DECOR_TITLE; + + if (flags & Qt::WindowSystemMenuHint) + mwmhints.decorations |= MWM_DECOR_MENU; + + if (flags & Qt::WindowMinimizeButtonHint) { + mwmhints.decorations |= MWM_DECOR_MINIMIZE; + mwmhints.functions |= MWM_FUNC_MINIMIZE; + } + + if (flags & Qt::WindowMaximizeButtonHint) { + mwmhints.decorations |= MWM_DECOR_MAXIMIZE; + mwmhints.functions |= MWM_FUNC_MAXIMIZE; + } + + if (flags & Qt::WindowCloseButtonHint) + mwmhints.functions |= MWM_FUNC_CLOSE; + } + } else { + // if type == Qt::SplashScreen + mwmhints.decorations = MWM_DECOR_ALL; + } + + if (tool) { + wsa.save_under = True; + wsa_mask |= CWSaveUnder; + } + + if (flags & Qt::X11BypassWindowManagerHint) { + wsa.override_redirect = True; + wsa_mask |= CWOverrideRedirect; + } +#if 0 + if (wsa_mask && initializeWindow) { + Q_ASSERT(id); + XChangeWindowAttributes(dpy, id, wsa_mask, &wsa); + } +#endif + if (mwmhints.functions != 0) { + mwmhints.flags |= MWM_HINTS_FUNCTIONS; + mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE; + } else { + mwmhints.functions = MWM_FUNC_ALL; + } + + if (!(flags & Qt::FramelessWindowHint) + && flags & Qt::CustomizeWindowHint + && flags & Qt::WindowTitleHint + && !(flags & + (Qt::WindowMinimizeButtonHint + | Qt::WindowMaximizeButtonHint + | Qt::WindowCloseButtonHint))) { + // a special case - only the titlebar without any button + mwmhints.flags = MWM_HINTS_FUNCTIONS; + mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE; + mwmhints.decorations = 0; + } + + SetMWMHints(xd->display, x_window, mwmhints); + +//##### only if initializeWindow??? + + if (popup || tooltip) { // popup widget +#ifdef MYX11_DEBUG + qDebug() << "Doing XChangeWindowAttributes for popup" << wsa.override_redirect; +#endif + // set EWMH window types + // setNetWmWindowTypes(); + + wsa.override_redirect = True; + wsa.save_under = True; + XChangeWindowAttributes(xd->display, x_window, CWOverrideRedirect | CWSaveUnder, + &wsa); + } else { +#ifdef MYX11_DEBUG + qDebug() << "Doing XChangeWindowAttributes for non-popup"; +#endif + } + + return flags; +} + +void QTestLiteWindow::setVisible(bool visible) +{ +#ifdef MYX11_DEBUG + qDebug() << "QTestLiteWindow::setVisible" << visible << hex << window; +#endif + if (visible) + XMapWindow(xd->display, x_window); + else + XUnmapWindow(xd->display, x_window); +} + + +void QTestLiteWindow::setCursor(QCursor * cursor) +{ + int id = cursor->handle(); + if (id == currentCursor) + return; + Cursor c; + if (!xd->cursors->exists(id)) { + if (cursor->shape() == Qt::BitmapCursor) + c = createCursorBitmap(cursor); + else + c = createCursorShape(cursor->shape()); + if (!c) { + return; + } + xd->cursors->createNode(id, c); + } else { + xd->cursors->incrementUseCount(id); + c = xd->cursors->cursor(id); + } + + if (currentCursor != -1) + xd->cursors->decrementUseCount(currentCursor); + currentCursor = id; + + XDefineCursor(xd->display, x_window, c); + XFlush(xd->display); +} + +Cursor QTestLiteWindow::createCursorBitmap(QCursor * cursor) +{ + XColor bg, fg; + bg.red = 255 << 8; + bg.green = 255 << 8; + bg.blue = 255 << 8; + fg.red = 0; + fg.green = 0; + fg.blue = 0; + QPoint spot = cursor->hotSpot(); + Window rootwin = x_window; + + QImage mapImage = cursor->bitmap()->toImage().convertToFormat(QImage::Format_MonoLSB); + QImage maskImage = cursor->mask()->toImage().convertToFormat(QImage::Format_MonoLSB); + + int width = cursor->bitmap()->width(); + int height = cursor->bitmap()->height(); + int bytesPerLine = mapImage.bytesPerLine(); + int destLineSize = width / 8; + if (width % 8) + destLineSize++; + + const uchar * map = mapImage.bits(); + const uchar * mask = maskImage.bits(); + + char * mapBits = new char[height * destLineSize]; + char * maskBits = new char[height * destLineSize]; + for (int i = 0; i < height; i++) { + memcpy(mapBits + (destLineSize * i),map + (bytesPerLine * i), destLineSize); + memcpy(maskBits + (destLineSize * i),mask + (bytesPerLine * i), destLineSize); + } + + Pixmap cp = XCreateBitmapFromData(xd->display, rootwin, mapBits, width, height); + Pixmap mp = XCreateBitmapFromData(xd->display, rootwin, maskBits, width, height); + Cursor c = XCreatePixmapCursor(xd->display, cp, mp, &fg, &bg, spot.x(), spot.y()); + XFreePixmap(xd->display, cp); + XFreePixmap(xd->display, mp); + delete[] mapBits; + delete[] maskBits; + + return c; +} + +Cursor QTestLiteWindow::createCursorShape(int cshape) +{ + Cursor cursor = 0; + + if (cshape < 0 || cshape > Qt::LastCursor) + return 0; + + switch (cshape) { + case Qt::ArrowCursor: + cursor = XCreateFontCursor(xd->display, XC_left_ptr); + break; + case Qt::UpArrowCursor: + cursor = XCreateFontCursor(xd->display, XC_center_ptr); + break; + case Qt::CrossCursor: + cursor = XCreateFontCursor(xd->display, XC_crosshair); + break; + case Qt::WaitCursor: + cursor = XCreateFontCursor(xd->display, XC_watch); + break; + case Qt::IBeamCursor: + cursor = XCreateFontCursor(xd->display, XC_xterm); + break; + case Qt::SizeAllCursor: + cursor = XCreateFontCursor(xd->display, XC_fleur); + break; + case Qt::PointingHandCursor: + cursor = XCreateFontCursor(xd->display, XC_hand2); + break; + case Qt::SizeBDiagCursor: + cursor = XCreateFontCursor(xd->display, XC_top_right_corner); + break; + case Qt::SizeFDiagCursor: + cursor = XCreateFontCursor(xd->display, XC_bottom_right_corner); + break; + case Qt::SizeVerCursor: + case Qt::SplitVCursor: + cursor = XCreateFontCursor(xd->display, XC_sb_v_double_arrow); + break; + case Qt::SizeHorCursor: + case Qt::SplitHCursor: + cursor = XCreateFontCursor(xd->display, XC_sb_h_double_arrow); + break; + case Qt::WhatsThisCursor: + cursor = XCreateFontCursor(xd->display, XC_question_arrow); + break; + case Qt::ForbiddenCursor: + cursor = XCreateFontCursor(xd->display, XC_circle); + break; + case Qt::BusyCursor: + cursor = XCreateFontCursor(xd->display, XC_watch); + break; + + default: //default cursor for all the rest + break; + } + return cursor; +} + + +MyX11Cursors::MyX11Cursors(Display * d) : firstExpired(0), lastExpired(0), display(d), removalDelay(3) +{ + connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); +} + +void MyX11Cursors::insertNode(MyX11CursorNode * node) +{ + QDateTime now = QDateTime::currentDateTime(); + QDateTime timeout = now.addSecs(removalDelay); + node->setExpiration(timeout); + node->setPost(0); + if (lastExpired) { + lastExpired->setPost(node); + node->setAnte(lastExpired); + } + lastExpired = node; + if (!firstExpired) { + firstExpired = node; + node->setAnte(0); + int interval = removalDelay * 1000; + timer.setInterval(interval); + timer.start(); + } +} + +void MyX11Cursors::removeNode(MyX11CursorNode * node) +{ + MyX11CursorNode *pre = node->ante(); + MyX11CursorNode *post = node->post(); + if (pre) + pre->setPost(post); + if (post) + post->setAnte(pre); + if (node == lastExpired) + lastExpired = pre; + if (node == firstExpired) { + firstExpired = post; + if (!firstExpired) { + timer.stop(); + return; + } + int interval = QDateTime::currentDateTime().secsTo(firstExpired->expiration()) * 1000; + timer.stop(); + timer.setInterval(interval); + timer.start(); + } +} + +void MyX11Cursors::incrementUseCount(int id) +{ + MyX11CursorNode * node = lookupMap.value(id); + Q_ASSERT(node); + if (!node->refCount) + removeNode(node); + node->refCount++; +} + +void MyX11Cursors::decrementUseCount(int id) +{ + MyX11CursorNode * node = lookupMap.value(id); + Q_ASSERT(node); + node->refCount--; + if (!node->refCount) + insertNode(node); +} + +void MyX11Cursors::createNode(int id, Cursor c) +{ + MyX11CursorNode * node = new MyX11CursorNode(id, c); + lookupMap.insert(id, node); +} + +void MyX11Cursors::timeout() +{ + MyX11CursorNode * node; + node = firstExpired; + QDateTime now = QDateTime::currentDateTime(); + while (node && now.secsTo(node->expiration()) < 1) { + Cursor c = node->cursor(); + int id = node->id(); + lookupMap.take(id); + MyX11CursorNode * tmp = node; + node = node->post(); + delete tmp; + XFreeCursor(display, c); + } + firstExpired = node; + if (node == 0) { + timer.stop(); + lastExpired = 0; + } + else { + int interval = QDateTime::currentDateTime().secsTo(firstExpired->expiration()) * 1000; + timer.setInterval(interval); + timer.start(); + } +} + +Cursor MyX11Cursors::cursor(int id) +{ + MyX11CursorNode * node = lookupMap.value(id); + Q_ASSERT(node); + return node->cursor(); +} + + + +/******************************************************************** + +MyDisplay class - perhaps better placed in qplatformintegration_testlite? + +*********************************************************************/ + +//### copied from qapplication_x11.cpp + +static int qt_x_errhandler(Display *dpy, XErrorEvent *err) +{ + +qDebug() << "qt_x_errhandler" << err->error_code; + + switch (err->error_code) { + case BadAtom: +#if 0 + if (err->request_code == 20 /* X_GetProperty */ + && (err->resourceid == XA_RESOURCE_MANAGER + || err->resourceid == XA_RGB_DEFAULT_MAP + || err->resourceid == ATOM(_NET_SUPPORTED) + || err->resourceid == ATOM(_NET_SUPPORTING_WM_CHECK) + || err->resourceid == ATOM(KDE_FULL_SESSION) + || err->resourceid == ATOM(KWIN_RUNNING) + || err->resourceid == ATOM(XdndProxy) + || err->resourceid == ATOM(XdndAware)) + + + ) { + // Perhaps we're running under SECURITY reduction? :/ + return 0; + } +#endif + qDebug() << "BadAtom"; + break; + + case BadWindow: + if (err->request_code == 2 /* X_ChangeWindowAttributes */ + || err->request_code == 38 /* X_QueryPointer */) { + for (int i = 0; i < ScreenCount(dpy); ++i) { + if (err->resourceid == RootWindow(dpy, i)) { + // Perhaps we're running under SECURITY reduction? :/ + return 0; + } + } + } + seen_badwindow = true; + if (err->request_code == 25 /* X_SendEvent */) { + for (int i = 0; i < ScreenCount(dpy); ++i) { + if (err->resourceid == RootWindow(dpy, i)) { + // Perhaps we're running under SECURITY reduction? :/ + return 0; + } + } +#if 0 + if (X11->xdndHandleBadwindow()) { + qDebug("xdndHandleBadwindow returned true"); + return 0; + } +#endif + } +#if 0 + if (X11->ignore_badwindow) + return 0; +#endif + break; + + case BadMatch: + if (err->request_code == 42 /* X_SetInputFocus */) + return 0; + break; + + default: +#if 0 //!defined(QT_NO_XINPUT) + if (err->request_code == X11->xinput_major + && err->error_code == (X11->xinput_errorbase + XI_BadDevice) + && err->minor_code == 3 /* X_OpenDevice */) { + return 0; + } +#endif + break; + } + + char errstr[256]; + XGetErrorText( dpy, err->error_code, errstr, 256 ); + char buffer[256]; + char request_str[256]; + qsnprintf(buffer, 256, "%d", err->request_code); + XGetErrorDatabaseText(dpy, "XRequest", buffer, "", request_str, 256); + if (err->request_code < 128) { + // X error for a normal protocol request + qWarning( "X Error: %s %d\n" + " Major opcode: %d (%s)\n" + " Resource id: 0x%lx", + errstr, err->error_code, + err->request_code, + request_str, + err->resourceid ); + } else { + // X error for an extension request + const char *extensionName = 0; +#if 0 + if (err->request_code == X11->xrender_major) + extensionName = "RENDER"; + else if (err->request_code == X11->xrandr_major) + extensionName = "RANDR"; + else if (err->request_code == X11->xinput_major) + extensionName = "XInputExtension"; + else if (err->request_code == X11->mitshm_major) + extensionName = "MIT-SHM"; +#endif + char minor_str[256]; + if (extensionName) { + qsnprintf(buffer, 256, "%s.%d", extensionName, err->minor_code); + XGetErrorDatabaseText(dpy, "XRequest", buffer, "", minor_str, 256); + } else { + extensionName = "Uknown extension"; + qsnprintf(minor_str, 256, "Unknown request"); + } + qWarning( "X Error: %s %d\n" + " Extension: %d (%s)\n" + " Minor opcode: %d (%s)\n" + " Resource id: 0x%lx", + errstr, err->error_code, + err->request_code, + extensionName, + err->minor_code, + minor_str, + err->resourceid ); + } + + // ### we really should distinguish between severe, non-severe and + // ### application specific errors + + return 0; +} + + +#ifdef KeyPress +#undef KeyPress +#endif +#ifdef KeyRelease +#undef KeyRelease +#endif + +bool MyDisplay::handleEvent(XEvent *xe) +{ + //qDebug() << "handleEvent" << xe->xany.type << xe->xany.window; + int quit = false; + QTestLiteWindow *xw = 0; + foreach (QTestLiteWindow *w, windowList) { + if (w->winId() == xe->xany.window) { + xw = w; + break; + } + } + if (!xw) { +#ifdef MYX11_DEBUG + qWarning() << "Unknown window" << hex << xe->xany.window << "received event" << xe->type; +#endif + return quit; + } + + switch (xe->type) { + + case ClientMessage: + if (xe->xclient.format == 32 && xe->xclient.message_type == wmProtocolsAtom) { + Atom a = xe->xclient.data.l[0]; + if (a == wmDeleteWindowAtom) + xw->handleCloseEvent(); +#ifdef MYX11_DEBUG + qDebug() << "ClientMessage WM_PROTOCOLS" << a; +#endif + } +#ifdef MYX11_DEBUG + else + qDebug() << "ClientMessage" << xe->xclient.format << xe->xclient.message_type; +#endif + break; + + case Expose: + if (xw) + if (xe->xexpose.count == 0) + xw->paintEvent(); + break; + case ConfigureNotify: + if (xw) + xw->resizeEvent(&xe->xconfigure); + break; + + case ButtonPress: + xw->mousePressEvent(&xe->xbutton); + break; + + case ButtonRelease: + xw->handleMouseEvent(QEvent::MouseButtonRelease, &xe->xbutton); + break; + + case MotionNotify: + xw->handleMouseEvent(QEvent::MouseMove, &xe->xbutton); + break; + + case XKeyPress: + xw->handleKeyEvent(QEvent::KeyPress, &xe->xkey); + break; + + case XKeyRelease: + xw->handleKeyEvent(QEvent::KeyRelease, &xe->xkey); + break; + + case EnterNotify: + xw->handleEnterEvent(); + break; + + case LeaveNotify: + xw->handleLeaveEvent(); + break; + + default: +#ifdef MYX11_DEBUG + qDebug() << hex << xe->xany.window << "Other X event" << xe->type; +#endif + break; + } + return quit; +}; + + + +MyDisplay::MyDisplay() +{ + char *display_name = getenv("DISPLAY"); + display = XOpenDisplay(display_name); + if (!display) { + fprintf(stderr, "Cannot connect to X server: %s\n", + display_name); + exit(1); + } + +#ifndef DONT_USE_MIT_SHM + Status MIT_SHM_extension_supported = XShmQueryExtension (display); + Q_ASSERT(MIT_SHM_extension_supported == True); +#endif + original_x_errhandler = XSetErrorHandler(qt_x_errhandler); + + if (qgetenv("DO_X_SYNCHRONIZE").toInt()) + XSynchronize(display, true); + + screen = DefaultScreen(display); + width = DisplayWidth(display, screen); + height = DisplayHeight(display, screen); + physicalWidth = DisplayWidthMM(display, screen); + physicalHeight = DisplayHeightMM(display, screen); + + int xSocketNumber = XConnectionNumber(display); +#ifdef MYX11_DEBUG + qDebug() << "X socket:"<< xSocketNumber; +#endif + QSocketNotifier *sock = new QSocketNotifier(xSocketNumber, QSocketNotifier::Read, this); + connect(sock, SIGNAL(activated(int)), this, SLOT(eventDispatcher())); + + wmProtocolsAtom = XInternAtom (display, "WM_PROTOCOLS", False); + wmDeleteWindowAtom = XInternAtom (display, "WM_DELETE_WINDOW", False); + + cursors = new MyX11Cursors(display); +} + + +MyDisplay::~MyDisplay() +{ + XCloseDisplay(display); +} + + +void MyDisplay::eventDispatcher() +{ +// qDebug() << "eventDispatcher"; + + + ulong marker = XNextRequest(display); +// int i = 0; + while (XPending(display)) { + XEvent event; + XNextEvent(display, &event); + /* done = */ + handleEvent(&event); + + if (event.xany.serial >= marker) { +#ifdef MYX11_DEBUG + qDebug() << "potential livelock averted"; +#endif +#if 0 + if (XEventsQueued(display, QueuedAfterFlush)) { + qDebug() << " with events queued"; + QTimer::singleShot(0, this, SLOT(eventDispatcher())); + } +#endif + break; + } + } +} + + +QImage MyDisplay::grabWindow(Window window, int x, int y, int w, int h) +{ + if (w == 0 || h ==0) + return QImage(); + + //WinId 0 means the desktop widget + if (!window) + window = rootWindow(); + + XWindowAttributes window_attr; + if (!XGetWindowAttributes(display, window, &window_attr)) + return QImage(); + + if (w < 0) + w = window_attr.width - x; + if (h < 0) + h = window_attr.height - y; + + // Ideally, we should also limit ourselves to the screen area, but the Qt docs say + // that it's "unsafe" to go outside the screen, so we can ignore that problem. + + //We're definitely not optimizing for speed... + XImage *xi = XGetImage(display, window, x, y, w, h, AllPlanes, ZPixmap); + + if (!xi) + return QImage(); + + //taking a copy to make sure we have ownership -- not fast + QImage result = QImage( (uchar*) xi->data, xi->width, xi->height, xi->bytes_per_line, QImage::Format_RGB32 ).copy(); + + XDestroyImage(xi); + + return result; +} + + + + + + + +QT_END_NAMESPACE +#include "qtestlitewindow.moc" diff --git a/src/plugins/platforms/testlite/qtestlitewindow.h b/src/plugins/platforms/testlite/qtestlitewindow.h new file mode 100644 index 0000000..6fb7ed2 --- /dev/null +++ b/src/plugins/platforms/testlite/qtestlitewindow.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTESTLITEWINDOW_H +#define QTESTLITEWINDOW_H + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + + + +class QTestLiteIntegration; +class QTestLiteScreen; +class QTestLiteWindowSurface; +class MyX11Cursors; +class QTestLiteWindow; + +class MyDisplay : public QObject +{ + Q_OBJECT; +public: + MyDisplay(); + ~MyDisplay(); + + Window rootWindow() { return RootWindow(display, screen); } + unsigned long blackPixel() { return BlackPixel(display, screen); } + unsigned long whitePixel() { return WhitePixel(display, screen); } + + bool handleEvent(XEvent *xe); + QImage grabWindow(Window window, int x, int y, int w, int h); + +public slots: + void eventDispatcher(); + +public: //### + Display * display; + int screen; + int width, height; + int physicalWidth; + int physicalHeight; + + QList windowList; + + MyX11Cursors * cursors; +}; + +struct MyShmImageInfo; + +class QWindowSurface; + +class QTestLiteWindow : public QPlatformWindow +{ +public: + QTestLiteWindow(QTestLiteIntegration *platformIntegration, + QTestLiteScreen *screen, QWidget *window); + ~QTestLiteWindow(); + + + void mousePressEvent(XButtonEvent*); + void handleMouseEvent(QEvent::Type, XButtonEvent *ev); + + void handleKeyEvent(QEvent::Type, void *); + void handleCloseEvent(); + void handleEnterEvent(); + void handleLeaveEvent(); + + void resizeEvent(XConfigureEvent *configure_event); + void paintEvent(); + + + void setGeometry(const QRect &rect); + + Qt::WindowFlags setWindowFlags(Qt::WindowFlags type); + Qt::WindowFlags windowFlags() const; + void setVisible(bool visible); + WId winId() const; + void raise(); + void lower(); + void setWindowTitle(const QString &title); + + void setCursor(QCursor * cursor); + +private: + int xpos, ypos; + int width, height; + Window x_window; + GC gc; + + GC createGC(); + Cursor createCursorShape(int cshape); + Cursor createCursorBitmap(QCursor * cursor); + + int currentCursor; + + QWindowSurface *windowSurface; + MyDisplay *xd; + + QTestLiteIntegration *mPlatformIntegration; + QTestLiteScreen *mScreen; + Qt::WindowFlags window_flags; + + friend class QTestLiteWindowSurface; // x_window, gc and windowSurface +}; + + + + + +#endif diff --git a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp index 81fa247..b5a0f74 100644 --- a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp +++ b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp @@ -45,36 +45,108 @@ #include #include -#include "x11util.h" +#include "qtestlitewindow.h" + +# include +# include +# include QT_BEGIN_NAMESPACE -QTestLiteWindowSurface::QTestLiteWindowSurface - (QTestLiteIntegration *platformIntegration, - QTestLiteScreen *screen, QWidget *window) - : QWindowSurface(window), - mPlatformIntegration(platformIntegration), - mScreen(screen), - xw(0) + +struct MyShmImageInfo { + MyShmImageInfo(Display *xdisplay) : image(0), display(xdisplay) {} + ~MyShmImageInfo() { destroy(); } + + void destroy(); + + XShmSegmentInfo shminfo; + XImage *image; + Display *display; +}; + +//void QTestLiteWindowSurface::flush() + + +#ifndef DONT_USE_MIT_SHM +void MyShmImageInfo::destroy() +{ + XShmDetach (display, &shminfo); + XDestroyImage (image); + shmdt (shminfo.shmaddr); + shmctl (shminfo.shmid, IPC_RMID, 0); +} +#endif + +void QTestLiteWindowSurface::resizeShmImage(int width, int height) { + MyDisplay *xd = xw->xd; - xw = static_cast(window->platformWindow())->xw; -// xw = new MyWindow(platformIntegration->xd, 0,0,300,300); +#ifdef DONT_USE_MIT_SHM + shm_img = QImage(width, height, QImage::Format_RGB32); +#else + if (image_info) + image_info->destroy(); + else + image_info = new MyShmImageInfo(xd->display); -// qDebug() << "QTestLiteWindowSurface::QTestLiteWindowSurface:" << xw->window; + Visual *visual = DefaultVisual(xd->display, xd->screen); + + + XImage *image = XShmCreateImage (xd->display, visual, 24, ZPixmap, 0, + &image_info->shminfo, width, height); + + + image_info->shminfo.shmid = shmget (IPC_PRIVATE, + image->bytes_per_line * image->height, IPC_CREAT|0777); + + image_info->shminfo.shmaddr = image->data = (char*)shmat (image_info->shminfo.shmid, 0, 0); + image_info->shminfo.readOnly = False; + image_info->image = image; + + Status shm_attach_status = XShmAttach(xd->display, &image_info->shminfo); + + Q_ASSERT(shm_attach_status == True); + + shm_img = QImage( (uchar*) image->data, image->width, image->height, image->bytes_per_line, QImage::Format_RGB32 ); +#endif + painted = false; +} + + +void QTestLiteWindowSurface::resizeBuffer(QSize s) +{ + if (shm_img.size() != s) + resizeShmImage(s.width(), s.height()); +} + +QSize QTestLiteWindowSurface::bufferSize() const +{ + return shm_img.size(); +} + +QTestLiteWindowSurface::QTestLiteWindowSurface (QTestLiteScreen */*screen*/, QWidget *window) + : QWindowSurface(window), + painted(false), image_info(0) +{ + xw = static_cast(window->platformWindow()); + xw->windowSurface = this; +// qDebug() << "QTestLiteWindowSurface::QTestLiteWindowSurface:" << xw->window; } QTestLiteWindowSurface::~QTestLiteWindowSurface() { -// qDebug() << "~QTestLiteWindowSurface" << xw->window; + qDebug() << "~QTestLiteWindowSurface"; + delete image_info; } QPaintDevice *QTestLiteWindowSurface::paintDevice() { - return xw->image(); + return &shm_img; } + void QTestLiteWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { Q_UNUSED(widget); @@ -83,22 +155,48 @@ void QTestLiteWindowSurface::flush(QWidget *widget, const QRegion ®ion, const // qDebug() << "QTestLiteWindowSurface::flush:" << (long)this; - xw->paintEvent(); -} - + if (!painted) + return; -// void QTestLiteWindowSurface::resize(const QSize &s) -// { -// if (s == size()) -// return; + MyDisplay *xd = xw->xd; + GC gc = xw->gc; + Window window = xw->x_window; +#ifdef DONT_USE_MIT_SHM + // just convert the image every time... + if (!shm_img.isNull()) { + Visual *visual = DefaultVisual(xd->display, xd->screen); -// QWindowSurface::resize(size); + QImage image = shm_img; + //img.convertToFormat( + XImage *xi = XCreateImage(xd->display, visual, 24, ZPixmap, + 0, (char *) image.scanLine(0), image.width(), image.height(), + 32, image.bytesPerLine()); -// //if unchanged ### -// // xw->setSize(rect.width(), rect.height()); + int x = 0; + int y = 0; + /*int r =*/ XPutImage(xd->display, window, gc, xi, 0, 0, x, y, image.width(), image.height()); -// } + xi->data = 0; // QImage owns these bits + XDestroyImage(xi); + } +#else + // Use MIT_SHM + if (image_info->image) { + //qDebug() << "Here we go" << image_info->image->width << image_info->image->height; + int x = 0; + int y = 0; + + // We could set send_event to true, and then use the ShmCompletion to synchronize, + // but let's do like Qt/11 and just use XSync + XShmPutImage (xd->display, window, gc, image_info->image, 0, 0, + x, y, image_info->image->width, image_info->image->height, + /*send_event*/ False); + + XSync(xd->display, False); + } +#endif +} //### scroll logic copied from QRasterWindowSurface, we should make better API for this @@ -151,12 +249,12 @@ void copied_qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &o bool QTestLiteWindowSurface::scroll(const QRegion &area, int dx, int dy) { - if (!xw->image() || xw->image()->isNull()) + if (shm_img.isNull()) return false; const QVector rects = area.rects(); for (int i = 0; i < rects.size(); ++i) - copied_qt_scrollRectInImage(*xw->image(), rects.at(i), QPoint(dx, dy)); + copied_qt_scrollRectInImage(shm_img, rects.at(i), QPoint(dx, dy)); return true; } @@ -165,529 +263,12 @@ bool QTestLiteWindowSurface::scroll(const QRegion &area, int dx, int dy) void QTestLiteWindowSurface::beginPaint(const QRegion ®ion) { Q_UNUSED(region); - xw->resizeBuffer(size()); + resizeBuffer(size()); } void QTestLiteWindowSurface::endPaint(const QRegion ®ion) { Q_UNUSED(region); - xw->painted = true; //there is content in the buffer -} - - -/************************************************************************** -** QTestLiteWindow -**************************************************************************/ - -QTestLiteWindow::QTestLiteWindow(QTestLiteIntegration *platformIntegration, - QTestLiteScreen */*screen*/, QWidget *window) - :QPlatformWindow(window) -{ - xw = new MyWindow(platformIntegration->xd, 0,0,300,300); - setWindowFlags(window->windowFlags()); //##### This should not be the plugin's responsibility - - xw->windowTL = this; -} - - -QTestLiteWindow::~QTestLiteWindow() -{ - delete xw; -} - - - - - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// Mouse event stuff - - - - -static Qt::MouseButtons translateMouseButtons(int s) -{ - Qt::MouseButtons ret = 0; - if (s & Button1Mask) - ret |= Qt::LeftButton; - if (s & Button2Mask) - ret |= Qt::MidButton; - if (s & Button3Mask) - ret |= Qt::RightButton; - return ret; -} - - -static Qt::KeyboardModifiers translateModifiers(int s) -{ - const uchar qt_alt_mask = Mod1Mask; - const uchar qt_meta_mask = Mod4Mask; - - - Qt::KeyboardModifiers ret = 0; - if (s & ShiftMask) - ret |= Qt::ShiftModifier; - if (s & ControlMask) - ret |= Qt::ControlModifier; - if (s & qt_alt_mask) - ret |= Qt::AltModifier; - if (s & qt_meta_mask) - ret |= Qt::MetaModifier; -#if 0 - if (s & qt_mode_switch_mask) - ret |= Qt::GroupSwitchModifier; -#endif - return ret; -} - -void QTestLiteWindow::handleMouseEvent(QEvent::Type type, void *ev) -{ - static QPoint mousePoint; - - XButtonEvent *e = static_cast(ev); - - Qt::MouseButton button = Qt::NoButton; - Qt::MouseButtons buttons = translateMouseButtons(e->state); - Qt::KeyboardModifiers modifiers = translateModifiers(e->state); - if (type != QEvent::MouseMove) { - switch (e->button) { - case Button1: button = Qt::LeftButton; break; - case Button2: button = Qt::MidButton; break; - case Button3: button = Qt::RightButton; break; - case Button4: - case Button5: - case 6: - case 7: { - //mouse wheel - if (type == QEvent::MouseButtonPress) { - //logic borrowed from qapplication_x11.cpp - int delta = 120 * ((e->button == Button4 || e->button == 6) ? 1 : -1); - bool hor = (((e->button == Button4 || e->button == Button5) - && (modifiers & Qt::AltModifier)) - || (e->button == 6 || e->button == 7)); - QWindowSystemInterface::handleWheelEvent(widget(), e->time, - QPoint(e->x, e->y), - QPoint(e->x_root, e->y_root), - delta, hor ? Qt::Horizontal : Qt::Vertical); - } - return; - } - default: break; - } - } - - buttons ^= button; // X event uses state *before*, Qt uses state *after* - - QWindowSystemInterface::handleMouseEvent(widget(), e->time, QPoint(e->x, e->y), - QPoint(e->x_root, e->y_root), - buttons); - - mousePoint = QPoint(e->x_root, e->y_root); -} - -void QTestLiteWindow::handleGeometryChange(int x, int y, int w, int h) -{ - QWindowSystemInterface::handleGeometryChange(widget(), QRect(x,y,w,h)); -} - - -void QTestLiteWindow::handleCloseEvent() -{ - QWindowSystemInterface::handleCloseEvent(widget()); -} - - -void QTestLiteWindow::handleEnterEvent() -{ - QWindowSystemInterface::handleEnterEvent(widget()); -} - -void QTestLiteWindow::handleLeaveEvent() -{ - QWindowSystemInterface::handleLeaveEvent(widget()); -} - - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// Key event stuff -- not pretty either -// -// What we want to do is to port Robert's keytable code properly - - - - - - - -// keyboard mapping table -static const unsigned int keyTbl[] = { - - // misc keys - - XK_Escape, Qt::Key_Escape, - XK_Tab, Qt::Key_Tab, - XK_ISO_Left_Tab, Qt::Key_Backtab, - XK_BackSpace, Qt::Key_Backspace, - XK_Return, Qt::Key_Return, - XK_Insert, Qt::Key_Insert, - XK_Delete, Qt::Key_Delete, - XK_Clear, Qt::Key_Delete, - XK_Pause, Qt::Key_Pause, - XK_Print, Qt::Key_Print, - 0x1005FF60, Qt::Key_SysReq, // hardcoded Sun SysReq - 0x1007ff00, Qt::Key_SysReq, // hardcoded X386 SysReq - - // cursor movement - - XK_Home, Qt::Key_Home, - XK_End, Qt::Key_End, - XK_Left, Qt::Key_Left, - XK_Up, Qt::Key_Up, - XK_Right, Qt::Key_Right, - XK_Down, Qt::Key_Down, - XK_Prior, Qt::Key_PageUp, - XK_Next, Qt::Key_PageDown, - - // modifiers - - XK_Shift_L, Qt::Key_Shift, - XK_Shift_R, Qt::Key_Shift, - XK_Shift_Lock, Qt::Key_Shift, - XK_Control_L, Qt::Key_Control, - XK_Control_R, Qt::Key_Control, - XK_Meta_L, Qt::Key_Meta, - XK_Meta_R, Qt::Key_Meta, - XK_Alt_L, Qt::Key_Alt, - XK_Alt_R, Qt::Key_Alt, - XK_Caps_Lock, Qt::Key_CapsLock, - XK_Num_Lock, Qt::Key_NumLock, - XK_Scroll_Lock, Qt::Key_ScrollLock, - XK_Super_L, Qt::Key_Super_L, - XK_Super_R, Qt::Key_Super_R, - XK_Menu, Qt::Key_Menu, - XK_Hyper_L, Qt::Key_Hyper_L, - XK_Hyper_R, Qt::Key_Hyper_R, - XK_Help, Qt::Key_Help, - 0x1000FF74, Qt::Key_Backtab, // hardcoded HP backtab - 0x1005FF10, Qt::Key_F11, // hardcoded Sun F36 (labeled F11) - 0x1005FF11, Qt::Key_F12, // hardcoded Sun F37 (labeled F12) - - // numeric and function keypad keys - - XK_KP_Space, Qt::Key_Space, - XK_KP_Tab, Qt::Key_Tab, - XK_KP_Enter, Qt::Key_Enter, - //XK_KP_F1, Qt::Key_F1, - //XK_KP_F2, Qt::Key_F2, - //XK_KP_F3, Qt::Key_F3, - //XK_KP_F4, Qt::Key_F4, - XK_KP_Home, Qt::Key_Home, - XK_KP_Left, Qt::Key_Left, - XK_KP_Up, Qt::Key_Up, - XK_KP_Right, Qt::Key_Right, - XK_KP_Down, Qt::Key_Down, - XK_KP_Prior, Qt::Key_PageUp, - XK_KP_Next, Qt::Key_PageDown, - XK_KP_End, Qt::Key_End, - XK_KP_Begin, Qt::Key_Clear, - XK_KP_Insert, Qt::Key_Insert, - XK_KP_Delete, Qt::Key_Delete, - XK_KP_Equal, Qt::Key_Equal, - XK_KP_Multiply, Qt::Key_Asterisk, - XK_KP_Add, Qt::Key_Plus, - XK_KP_Separator, Qt::Key_Comma, - XK_KP_Subtract, Qt::Key_Minus, - XK_KP_Decimal, Qt::Key_Period, - XK_KP_Divide, Qt::Key_Slash, - - // International input method support keys - - // International & multi-key character composition - XK_ISO_Level3_Shift, Qt::Key_AltGr, - XK_Multi_key, Qt::Key_Multi_key, - XK_Codeinput, Qt::Key_Codeinput, - XK_SingleCandidate, Qt::Key_SingleCandidate, - XK_MultipleCandidate, Qt::Key_MultipleCandidate, - XK_PreviousCandidate, Qt::Key_PreviousCandidate, - - // Misc Functions - XK_Mode_switch, Qt::Key_Mode_switch, - XK_script_switch, Qt::Key_Mode_switch, - - // Japanese keyboard support - XK_Kanji, Qt::Key_Kanji, - XK_Muhenkan, Qt::Key_Muhenkan, - //XK_Henkan_Mode, Qt::Key_Henkan_Mode, - XK_Henkan_Mode, Qt::Key_Henkan, - XK_Henkan, Qt::Key_Henkan, - XK_Romaji, Qt::Key_Romaji, - XK_Hiragana, Qt::Key_Hiragana, - XK_Katakana, Qt::Key_Katakana, - XK_Hiragana_Katakana, Qt::Key_Hiragana_Katakana, - XK_Zenkaku, Qt::Key_Zenkaku, - XK_Hankaku, Qt::Key_Hankaku, - XK_Zenkaku_Hankaku, Qt::Key_Zenkaku_Hankaku, - XK_Touroku, Qt::Key_Touroku, - XK_Massyo, Qt::Key_Massyo, - XK_Kana_Lock, Qt::Key_Kana_Lock, - XK_Kana_Shift, Qt::Key_Kana_Shift, - XK_Eisu_Shift, Qt::Key_Eisu_Shift, - XK_Eisu_toggle, Qt::Key_Eisu_toggle, - //XK_Kanji_Bangou, Qt::Key_Kanji_Bangou, - //XK_Zen_Koho, Qt::Key_Zen_Koho, - //XK_Mae_Koho, Qt::Key_Mae_Koho, - XK_Kanji_Bangou, Qt::Key_Codeinput, - XK_Zen_Koho, Qt::Key_MultipleCandidate, - XK_Mae_Koho, Qt::Key_PreviousCandidate, - -#ifdef XK_KOREAN - // Korean keyboard support - XK_Hangul, Qt::Key_Hangul, - XK_Hangul_Start, Qt::Key_Hangul_Start, - XK_Hangul_End, Qt::Key_Hangul_End, - XK_Hangul_Hanja, Qt::Key_Hangul_Hanja, - XK_Hangul_Jamo, Qt::Key_Hangul_Jamo, - XK_Hangul_Romaja, Qt::Key_Hangul_Romaja, - //XK_Hangul_Codeinput, Qt::Key_Hangul_Codeinput, - XK_Hangul_Codeinput, Qt::Key_Codeinput, - XK_Hangul_Jeonja, Qt::Key_Hangul_Jeonja, - XK_Hangul_Banja, Qt::Key_Hangul_Banja, - XK_Hangul_PreHanja, Qt::Key_Hangul_PreHanja, - XK_Hangul_PostHanja, Qt::Key_Hangul_PostHanja, - //XK_Hangul_SingleCandidate,Qt::Key_Hangul_SingleCandidate, - //XK_Hangul_MultipleCandidate,Qt::Key_Hangul_MultipleCandidate, - //XK_Hangul_PreviousCandidate,Qt::Key_Hangul_PreviousCandidate, - XK_Hangul_SingleCandidate, Qt::Key_SingleCandidate, - XK_Hangul_MultipleCandidate,Qt::Key_MultipleCandidate, - XK_Hangul_PreviousCandidate,Qt::Key_PreviousCandidate, - XK_Hangul_Special, Qt::Key_Hangul_Special, - //XK_Hangul_switch, Qt::Key_Hangul_switch, - XK_Hangul_switch, Qt::Key_Mode_switch, -#endif // XK_KOREAN - - // dead keys - XK_dead_grave, Qt::Key_Dead_Grave, - XK_dead_acute, Qt::Key_Dead_Acute, - XK_dead_circumflex, Qt::Key_Dead_Circumflex, - XK_dead_tilde, Qt::Key_Dead_Tilde, - XK_dead_macron, Qt::Key_Dead_Macron, - XK_dead_breve, Qt::Key_Dead_Breve, - XK_dead_abovedot, Qt::Key_Dead_Abovedot, - XK_dead_diaeresis, Qt::Key_Dead_Diaeresis, - XK_dead_abovering, Qt::Key_Dead_Abovering, - XK_dead_doubleacute, Qt::Key_Dead_Doubleacute, - XK_dead_caron, Qt::Key_Dead_Caron, - XK_dead_cedilla, Qt::Key_Dead_Cedilla, - XK_dead_ogonek, Qt::Key_Dead_Ogonek, - XK_dead_iota, Qt::Key_Dead_Iota, - XK_dead_voiced_sound, Qt::Key_Dead_Voiced_Sound, - XK_dead_semivoiced_sound, Qt::Key_Dead_Semivoiced_Sound, - XK_dead_belowdot, Qt::Key_Dead_Belowdot, - XK_dead_hook, Qt::Key_Dead_Hook, - XK_dead_horn, Qt::Key_Dead_Horn, - -#if 0 - // Special multimedia keys - // currently only tested with MS internet keyboard - - // browsing keys - XF86XK_Back, Qt::Key_Back, - XF86XK_Forward, Qt::Key_Forward, - XF86XK_Stop, Qt::Key_Stop, - XF86XK_Refresh, Qt::Key_Refresh, - XF86XK_Favorites, Qt::Key_Favorites, - XF86XK_AudioMedia, Qt::Key_LaunchMedia, - XF86XK_OpenURL, Qt::Key_OpenUrl, - XF86XK_HomePage, Qt::Key_HomePage, - XF86XK_Search, Qt::Key_Search, - - // media keys - XF86XK_AudioLowerVolume, Qt::Key_VolumeDown, - XF86XK_AudioMute, Qt::Key_VolumeMute, - XF86XK_AudioRaiseVolume, Qt::Key_VolumeUp, - XF86XK_AudioPlay, Qt::Key_MediaPlay, - XF86XK_AudioStop, Qt::Key_MediaStop, - XF86XK_AudioPrev, Qt::Key_MediaPrevious, - XF86XK_AudioNext, Qt::Key_MediaNext, - XF86XK_AudioRecord, Qt::Key_MediaRecord, - - // launch keys - XF86XK_Mail, Qt::Key_LaunchMail, - XF86XK_MyComputer, Qt::Key_Launch0, - XF86XK_Calculator, Qt::Key_Launch1, - XF86XK_Standby, Qt::Key_Standby, - - XF86XK_Launch0, Qt::Key_Launch2, - XF86XK_Launch1, Qt::Key_Launch3, - XF86XK_Launch2, Qt::Key_Launch4, - XF86XK_Launch3, Qt::Key_Launch5, - XF86XK_Launch4, Qt::Key_Launch6, - XF86XK_Launch5, Qt::Key_Launch7, - XF86XK_Launch6, Qt::Key_Launch8, - XF86XK_Launch7, Qt::Key_Launch9, - XF86XK_Launch8, Qt::Key_LaunchA, - XF86XK_Launch9, Qt::Key_LaunchB, - XF86XK_LaunchA, Qt::Key_LaunchC, - XF86XK_LaunchB, Qt::Key_LaunchD, - XF86XK_LaunchC, Qt::Key_LaunchE, - XF86XK_LaunchD, Qt::Key_LaunchF, -#endif - -#if 0 - // Qtopia keys - QTOPIAXK_Select, Qt::Key_Select, - QTOPIAXK_Yes, Qt::Key_Yes, - QTOPIAXK_No, Qt::Key_No, - QTOPIAXK_Cancel, Qt::Key_Cancel, - QTOPIAXK_Printer, Qt::Key_Printer, - QTOPIAXK_Execute, Qt::Key_Execute, - QTOPIAXK_Sleep, Qt::Key_Sleep, - QTOPIAXK_Play, Qt::Key_Play, - QTOPIAXK_Zoom, Qt::Key_Zoom, - QTOPIAXK_Context1, Qt::Key_Context1, - QTOPIAXK_Context2, Qt::Key_Context2, - QTOPIAXK_Context3, Qt::Key_Context3, - QTOPIAXK_Context4, Qt::Key_Context4, - QTOPIAXK_Call, Qt::Key_Call, - QTOPIAXK_Hangup, Qt::Key_Hangup, - QTOPIAXK_Flip, Qt::Key_Flip, -#endif - 0, 0 -}; - - -static int lookupCode(unsigned int xkeycode) -{ - if (xkeycode >= XK_F1 && xkeycode <= XK_F35) - return Qt::Key_F1 + (int(xkeycode) - XK_F1); - - const unsigned int *p = keyTbl; - while (*p) { - if (*p == xkeycode) - return *++p; - p += 2; - } - - return 0; -} - - -static Qt::KeyboardModifiers modifierFromKeyCode(int qtcode) -{ - switch (qtcode) { - case Qt::Key_Control: - return Qt::ControlModifier; - case Qt::Key_Alt: - return Qt::AltModifier; - case Qt::Key_Shift: - return Qt::ShiftModifier; - case Qt::Key_Meta: - return Qt::MetaModifier; - default: - return Qt::NoModifier; - } -} - -void QTestLiteWindow::handleKeyEvent(QEvent::Type type, void *ev) -{ - XKeyEvent *e = static_cast(ev); - - KeySym keySym; - QByteArray chars; - chars.resize(513); - - int count = XLookupString(e, chars.data(), chars.size(), &keySym, 0); - -// qDebug() << "QTLWS::handleKeyEvent" << count << hex << "XKeysym:" << keySym; -// if (count) -// qDebug() << hex << int(chars[0]) << "String:" << chars; - - Qt::KeyboardModifiers modifiers = translateModifiers(e->state); - - int qtcode = lookupCode(keySym); -// qDebug() << "lookup: " << hex << keySym << qtcode << "mod" << modifiers; - - //X11 specifies state *before*, Qt expects state *after* the event - - modifiers ^= modifierFromKeyCode(qtcode); - - if (qtcode) { - QWindowSystemInterface::handleKeyEvent(widget(), e->time, type, qtcode, modifiers); - } else if (chars[0]) { - int qtcode = chars.toUpper()[0]; //Not exactly right... - if (modifiers & Qt::ControlModifier && qtcode < ' ') - qtcode = chars[0] + '@'; - QWindowSystemInterface::handleKeyEvent(widget(), e->time, type, qtcode, modifiers, QString::fromLatin1(chars)); - } else { - qWarning() << "unknown X keycode" << hex << e->keycode << keySym; - } -} - - - -void QTestLiteWindow::setGeometry(const QRect &rect) -{ - QRect oldRect = geometry(); - if (rect == oldRect) - return; - - //if unchanged ### - xw->setGeometry(rect.x(), rect.y(), rect.width(), rect.height()); -} - - - -Qt::WindowFlags QTestLiteWindow::setWindowFlags(Qt::WindowFlags flags) -{ - Q_ASSERT(flags & Qt::Window); - - window_flags = flags; - - xw->setWindowFlags(flags); - - return window_flags; - -} - -Qt::WindowFlags QTestLiteWindow::windowFlags() const -{ - return window_flags; -} - -void QTestLiteWindow::setVisible(bool visible) -{ - //qDebug() << "QTestLiteWindowSurface::setVisible" << visible << xw->window; - xw->setVisible(visible); -} - - -WId QTestLiteWindow::winId() const -{ - if (xw) - return (WId) xw->window; - else - return WId(0); -} - -void QTestLiteWindow::raise() -{ - WId window = winId(); - XRaiseWindow(mPlatformIntegration->xd->display, window); -} - -void QTestLiteWindow::lower() -{ - WId window = winId(); - XLowerWindow(mPlatformIntegration->xd->display, window); -} - -void QTestLiteWindow::setWindowTitle(const QString &title) -{ - xw->setWindowTitle(title); -} - -void QTestLiteWindow::setCursor(QCursor *cursor) -{ - xw->setCursor(cursor); + painted = true; //there is content in the buffer } QT_END_NAMESPACE diff --git a/src/plugins/platforms/testlite/qwindowsurface_testlite.h b/src/plugins/platforms/testlite/qwindowsurface_testlite.h index d713cc2..915e7fe 100644 --- a/src/plugins/platforms/testlite/qwindowsurface_testlite.h +++ b/src/plugins/platforms/testlite/qwindowsurface_testlite.h @@ -43,24 +43,23 @@ #define QWINDOWSURFACE_TESTLITE_H #include -#include -#include + QT_BEGIN_NAMESPACE -class MyWindow; +class QTestLiteWindow; class QTestLiteIntegration; class QTestLiteScreen; +class MyShmImageInfo; class QTestLiteWindowSurface : public QWindowSurface { public: - QTestLiteWindowSurface - (QTestLiteIntegration *platformIntegration, - QTestLiteScreen *screen, QWidget *window); + QTestLiteWindowSurface (QTestLiteScreen *screen, QWidget *window); ~QTestLiteWindowSurface(); QPaintDevice *paintDevice(); +// void flush(); void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); // void resize(const QSize &size); bool scroll(const QRegion &area, int dx, int dy); @@ -69,47 +68,18 @@ public: void endPaint(const QRegion ®ion); private: - QTestLiteIntegration *mPlatformIntegration; - QTestLiteScreen *mScreen; - Qt::WindowFlags window_flags; - MyWindow *xw; -}; - + bool painted; + void resizeBuffer(QSize); + QSize bufferSize() const; -class QTestLiteWindow : public QPlatformWindow -{ -public: - QTestLiteWindow(QTestLiteIntegration *platformIntegration, - QTestLiteScreen *screen, QWidget *window); - ~QTestLiteWindow(); + void resizeShmImage(int width, int height); - void handleMouseEvent(QEvent::Type, void *); //forwarding X types is apparently impossible :( - void handleKeyEvent(QEvent::Type, void *); - void handleGeometryChange(int x, int y, int w, int h); - void handleCloseEvent(); - void handleEnterEvent(); - void handleLeaveEvent(); + QImage shm_img; + MyShmImageInfo *image_info; - void setGeometry(const QRect &rect); - - Qt::WindowFlags setWindowFlags(Qt::WindowFlags type); - Qt::WindowFlags windowFlags() const; - void setVisible(bool visible); - WId winId() const; - void raise(); - void lower(); - void setWindowTitle(const QString &title); - - void setCursor(QCursor * cursor); - -private: - QTestLiteIntegration *mPlatformIntegration; - QTestLiteScreen *mScreen; - Qt::WindowFlags window_flags; - MyWindow *xw; + QTestLiteWindow *xw; - friend class QTestLiteWindowSurface; //### needs refactoring }; diff --git a/src/plugins/platforms/testlite/testlite.pro b/src/plugins/platforms/testlite/testlite.pro index 442dd68..02122f1 100644 --- a/src/plugins/platforms/testlite/testlite.pro +++ b/src/plugins/platforms/testlite/testlite.pro @@ -3,12 +3,8 @@ include(../../qpluginbase.pri) QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms -SOURCES = main.cpp qplatformintegration_testlite.cpp qwindowsurface_testlite.cpp -HEADERS = qplatformintegration_testlite.h qwindowsurface_testlite.h - - -HEADERS += x11util.h -SOURCES += x11util.cpp +SOURCES = main.cpp qplatformintegration_testlite.cpp qwindowsurface_testlite.cpp qtestlitewindow.cpp +HEADERS = qplatformintegration_testlite.h qwindowsurface_testlite.h qtestlitewindow.h LIBS += -lX11 -lXext diff --git a/src/plugins/platforms/testlite/x11util.cpp b/src/plugins/platforms/testlite/x11util.cpp deleted file mode 100644 index a869347..0000000 --- a/src/plugins/platforms/testlite/x11util.cpp +++ /dev/null @@ -1,1215 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtOpenVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include -#include -#include - -#include "x11util.h" -#include "qwindowsurface_testlite.h" - -#include -#include - - -#include - -#include - -# include -# include -# include - - -#include -#include -#include -#include - -//### remove stuff we don't want from qt_x11_p.h -#undef ATOM -#undef X11 - -//#define MYX11_DEBUG - -//#define DONT_USE_MIT_SHM - -static int (*original_x_errhandler)(Display *dpy, XErrorEvent *); -static bool seen_badwindow; - - -static Atom wmProtocolsAtom; -static Atom wmDeleteWindowAtom; - -//### copied from qapplication_x11.cpp - -static int qt_x_errhandler(Display *dpy, XErrorEvent *err) -{ - -qDebug() << "qt_x_errhandler" << err->error_code; - - switch (err->error_code) { - case BadAtom: -#if 0 - if (err->request_code == 20 /* X_GetProperty */ - && (err->resourceid == XA_RESOURCE_MANAGER - || err->resourceid == XA_RGB_DEFAULT_MAP - || err->resourceid == ATOM(_NET_SUPPORTED) - || err->resourceid == ATOM(_NET_SUPPORTING_WM_CHECK) - || err->resourceid == ATOM(KDE_FULL_SESSION) - || err->resourceid == ATOM(KWIN_RUNNING) - || err->resourceid == ATOM(XdndProxy) - || err->resourceid == ATOM(XdndAware)) - - - ) { - // Perhaps we're running under SECURITY reduction? :/ - return 0; - } -#endif - qDebug() << "BadAtom"; - break; - - case BadWindow: - if (err->request_code == 2 /* X_ChangeWindowAttributes */ - || err->request_code == 38 /* X_QueryPointer */) { - for (int i = 0; i < ScreenCount(dpy); ++i) { - if (err->resourceid == RootWindow(dpy, i)) { - // Perhaps we're running under SECURITY reduction? :/ - return 0; - } - } - } - seen_badwindow = true; - if (err->request_code == 25 /* X_SendEvent */) { - for (int i = 0; i < ScreenCount(dpy); ++i) { - if (err->resourceid == RootWindow(dpy, i)) { - // Perhaps we're running under SECURITY reduction? :/ - return 0; - } - } -#if 0 - if (X11->xdndHandleBadwindow()) { - qDebug("xdndHandleBadwindow returned true"); - return 0; - } -#endif - } -#if 0 - if (X11->ignore_badwindow) - return 0; -#endif - break; - - case BadMatch: - if (err->request_code == 42 /* X_SetInputFocus */) - return 0; - break; - - default: -#if 0 //!defined(QT_NO_XINPUT) - if (err->request_code == X11->xinput_major - && err->error_code == (X11->xinput_errorbase + XI_BadDevice) - && err->minor_code == 3 /* X_OpenDevice */) { - return 0; - } -#endif - break; - } - - char errstr[256]; - XGetErrorText( dpy, err->error_code, errstr, 256 ); - char buffer[256]; - char request_str[256]; - qsnprintf(buffer, 256, "%d", err->request_code); - XGetErrorDatabaseText(dpy, "XRequest", buffer, "", request_str, 256); - if (err->request_code < 128) { - // X error for a normal protocol request - qWarning( "X Error: %s %d\n" - " Major opcode: %d (%s)\n" - " Resource id: 0x%lx", - errstr, err->error_code, - err->request_code, - request_str, - err->resourceid ); - } else { - // X error for an extension request - const char *extensionName = 0; -#if 0 - if (err->request_code == X11->xrender_major) - extensionName = "RENDER"; - else if (err->request_code == X11->xrandr_major) - extensionName = "RANDR"; - else if (err->request_code == X11->xinput_major) - extensionName = "XInputExtension"; - else if (err->request_code == X11->mitshm_major) - extensionName = "MIT-SHM"; -#endif - char minor_str[256]; - if (extensionName) { - qsnprintf(buffer, 256, "%s.%d", extensionName, err->minor_code); - XGetErrorDatabaseText(dpy, "XRequest", buffer, "", minor_str, 256); - } else { - extensionName = "Uknown extension"; - qsnprintf(minor_str, 256, "Unknown request"); - } - qWarning( "X Error: %s %d\n" - " Extension: %d (%s)\n" - " Minor opcode: %d (%s)\n" - " Resource id: 0x%lx", - errstr, err->error_code, - err->request_code, - extensionName, - err->minor_code, - minor_str, - err->resourceid ); - } - - // ### we really should distinguish between severe, non-severe and - // ### application specific errors - - return 0; -} - - - - - - - - - -bool MyDisplay::handleEvent(XEvent *xe) -{ - //qDebug() << "handleEvent" << xe->xany.type << xe->xany.window; - int quit = false; - MyWindow *xw = 0; - foreach (MyWindow *w, windowList) { - if (w->window == xe->xany.window) { - xw = w; - break; - } - } - if (!xw) { -#ifdef MYX11_DEBUG - qWarning() << "Unknown window" << hex << xe->xany.window << "received event" << xe->type; -#endif - return quit; - } - - switch (xe->type) { - - case ClientMessage: - if (xe->xclient.format == 32 && xe->xclient.message_type == wmProtocolsAtom) { - Atom a = xe->xclient.data.l[0]; - if (a == wmDeleteWindowAtom) - xw->closeEvent(); -#ifdef MYX11_DEBUG - qDebug() << "ClientMessage WM_PROTOCOLS" << a; -#endif - } -#ifdef MYX11_DEBUG - else - qDebug() << "ClientMessage" << xe->xclient.format << xe->xclient.message_type; -#endif - break; - - case Expose: - if (xw) - if (xe->xexpose.count == 0) - xw->paintEvent(); - break; - case ConfigureNotify: - if (xw) - xw->resizeEvent(&xe->xconfigure); - break; - - case ButtonPress: - xw->mousePressEvent(&xe->xbutton); - break; - - case ButtonRelease: - xw->mouseReleaseEvent(&xe->xbutton); - break; - - case MotionNotify: - xw->mouseMoveEvent(&xe->xbutton); - break; - - case XKeyPress: - xw->keyPressEvent(&xe->xkey); - break; - - case XKeyRelease: - xw->keyReleaseEvent(&xe->xkey); - break; - - case EnterNotify: - xw->enterEvent(&xe->xcrossing); - break; - - case LeaveNotify: - xw->leaveEvent(&xe->xcrossing); - break; - - default: -#ifdef MYX11_DEBUG - qDebug() << hex << xe->xany.window << "Other X event" << xe->type; -#endif - break; - } - return quit; -}; - - - -MyDisplay::MyDisplay() -{ - char *display_name = getenv("DISPLAY"); - display = XOpenDisplay(display_name); - if (!display) { - fprintf(stderr, "Cannot connect to X server: %s\n", - display_name); - exit(1); - } - -#ifndef DONT_USE_MIT_SHM - Status MIT_SHM_extension_supported = XShmQueryExtension (display); - Q_ASSERT(MIT_SHM_extension_supported == True); -#endif - original_x_errhandler = XSetErrorHandler(qt_x_errhandler); - - if (qgetenv("DO_X_SYNCHRONIZE").toInt()) - XSynchronize(display, true); - - screen = DefaultScreen(display); - width = DisplayWidth(display, screen); - height = DisplayHeight(display, screen); - physicalWidth = DisplayWidthMM(display, screen); - physicalHeight = DisplayHeightMM(display, screen); - - int xSocketNumber = XConnectionNumber(display); -#ifdef MYX11_DEBUG - qDebug() << "X socket:"<< xSocketNumber; -#endif - QSocketNotifier *sock = new QSocketNotifier(xSocketNumber, QSocketNotifier::Read, this); - connect(sock, SIGNAL(activated(int)), this, SLOT(eventDispatcher())); - - wmProtocolsAtom = XInternAtom (display, "WM_PROTOCOLS", False); - wmDeleteWindowAtom = XInternAtom (display, "WM_DELETE_WINDOW", False); - - cursors = new MyX11Cursors(display); -} - - -MyDisplay::~MyDisplay() -{ - XCloseDisplay(display); -} - - -void MyDisplay::eventDispatcher() -{ -// qDebug() << "eventDispatcher"; - - - ulong marker = XNextRequest(display); -// int i = 0; - while (XPending(display)) { - XEvent event; - XNextEvent(display, &event); - /* done = */ - handleEvent(&event); - - if (event.xany.serial >= marker) { -#ifdef MYX11_DEBUG - qDebug() << "potential livelock averted"; -#endif -#if 0 - if (XEventsQueued(display, QueuedAfterFlush)) { - qDebug() << " with events queued"; - QTimer::singleShot(0, this, SLOT(eventDispatcher())); - } -#endif - break; - } - } -} - - -QImage MyDisplay::grabWindow(Window window, int x, int y, int w, int h) -{ - if (w == 0 || h ==0) - return QImage(); - - //WinId 0 means the desktop widget - if (!window) - window = rootWindow(); - - XWindowAttributes window_attr; - if (!XGetWindowAttributes(display, window, &window_attr)) - return QImage(); - - if (w < 0) - w = window_attr.width - x; - if (h < 0) - h = window_attr.height - y; - - // Ideally, we should also limit ourselves to the screen area, but the Qt docs say - // that it's "unsafe" to go outside the screen, so we can ignore that problem. - - //We're definitely not optimizing for speed... - XImage *xi = XGetImage(display, window, x, y, w, h, AllPlanes, ZPixmap); - - if (!xi) - return QImage(); - - //taking a copy to make sure we have ownership -- not fast - QImage result = QImage( (uchar*) xi->data, xi->width, xi->height, xi->bytes_per_line, QImage::Format_RGB32 ).copy(); - - XDestroyImage(xi); - - return result; -} - - - - -struct MyShmImageInfo { - MyShmImageInfo(Display *xdisplay) : image(0), display(xdisplay) {} - ~MyShmImageInfo() { destroy(); } - - void destroy(); - - XShmSegmentInfo shminfo; - XImage *image; - Display *display; -}; - -MyWindow::MyWindow(MyDisplay *display, int x, int y, int w, int h) -{ - xd = display; - - xd->windowList.append(this); - - window = XCreateSimpleWindow(xd->display, xd->rootWindow(), - x, y, w, h, 0 /*border_width*/, - xd->blackPixel(), xd->whitePixel()); - - -#ifdef MYX11_DEBUG - qDebug() << "MyWindow::MyWindow" << hex << window; -#endif - - - width = -1; - height = -1; - xpos = -1; - ypos = -1; - - XSetWindowBackgroundPixmap(xd->display, window, XNone); - - XSelectInput(xd->display, window, ExposureMask | KeyPressMask | KeyReleaseMask | - EnterWindowMask | LeaveWindowMask | FocusChangeMask | - PointerMotionMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | - StructureNotifyMask); - - gc = createGC(); - - XChangeProperty (xd->display, window, - wmProtocolsAtom, - XA_ATOM, 32, PropModeAppend, - (unsigned char *) &wmDeleteWindowAtom, 1); - - - setWindowTitle(QLatin1String("Qt Lighthouse")); - - currentCursor = -1; - - image_info = 0; - painted = false; -} - - -void MyWindow::setWindowTitle(const QString &title) - -{ - QByteArray ba = title.toLatin1(); //We're not making a general solution here... - XTextProperty windowName; - windowName.value = (unsigned char *)ba.constData(); - windowName.encoding = XA_STRING; - windowName.format = 8; - windowName.nitems = ba.length(); - - XSetWMName(xd->display, window, &windowName); -} - -MyWindow::~MyWindow() -{ -#ifdef MYX11_DEBUG - qDebug() << "~MyWindow" << hex << window; -#endif - XFreeGC(xd->display, gc); - XDestroyWindow(xd->display, window); - - xd->windowList.removeAll(this); - - delete image_info; -} - -GC MyWindow::createGC() -{ - GC gc; - - gc = XCreateGC(xd->display, window, 0, 0); - if (gc < 0) { - qWarning("MyWindow::createGC() could not create GC"); - } - return gc; -} - -void MyWindow::closeEvent() -{ - windowTL->handleCloseEvent(); -} - -void MyWindow::paintEvent() -{ -#ifdef MYX11_DEBUG - qDebug() << "MyWindow::paintEvent" << shm_img.size() << painted; -#endif - if (!painted) - return; - -#ifdef DONT_USE_MIT_SHM - // just convert the image every time... - if (!shm_img.isNull()) { - Visual *visual = DefaultVisual(xd->display, xd->screen); - - QImage image = shm_img; - //img.convertToFormat( - XImage *xi = XCreateImage(xd->display, visual, 24, ZPixmap, - 0, (char *) image.scanLine(0), image.width(), image.height(), - 32, image.bytesPerLine()); - - int x = 0; - int y = 0; - - /*int r =*/ XPutImage(xd->display, window, gc, xi, 0, 0, x, y, image.width(), image.height()); - - xi->data = 0; // QImage owns these bits - XDestroyImage(xi); - } -#else - // Use MIT_SHM - if (image_info->image) { - //qDebug() << "Here we go" << image_info->image->width << image_info->image->height; - int x = 0; - int y = 0; - - // We could set send_event to true, and then use the ShmCompletion to synchronize, - // but let's do like Qt/11 and just use XSync - XShmPutImage (xd->display, window, gc, image_info->image, 0, 0, - x, y, image_info->image->width, image_info->image->height, - /*send_event*/ False); - - XSync(xd->display, False); - } -#endif -} - -#ifndef DONT_USE_MIT_SHM -void MyShmImageInfo::destroy() -{ - XShmDetach (display, &shminfo); - XDestroyImage (image); - shmdt (shminfo.shmaddr); - shmctl (shminfo.shmid, IPC_RMID, 0); -} -#endif - -void MyWindow::resizeShmImage(int width, int height) -{ -#ifdef DONT_USE_MIT_SHM - shm_img = QImage(width, height, QImage::Format_RGB32); -#else - if (image_info) - image_info->destroy(); - else - image_info = new MyShmImageInfo(xd->display); - - Visual *visual = DefaultVisual(xd->display, xd->screen); - - - XImage *image = XShmCreateImage (xd->display, visual, 24, ZPixmap, 0, - &image_info->shminfo, width, height); - - - image_info->shminfo.shmid = shmget (IPC_PRIVATE, - image->bytes_per_line * image->height, IPC_CREAT|0777); - - image_info->shminfo.shmaddr = image->data = (char*)shmat (image_info->shminfo.shmid, 0, 0); - image_info->shminfo.readOnly = False; - - image_info->image = image; - - Status shm_attach_status = XShmAttach(xd->display, &image_info->shminfo); - - Q_ASSERT(shm_attach_status == True); - - shm_img = QImage( (uchar*) image->data, image->width, image->height, image->bytes_per_line, QImage::Format_RGB32 ); -#endif - painted = false; -} - - -void MyWindow::resizeBuffer(QSize s) -{ - if (shm_img.size() != s) - resizeShmImage(s.width(), s.height()); -} - -QSize MyWindow::bufferSize() const -{ - return shm_img.size(); -} - - -void MyWindow::resizeEvent(XConfigureEvent *e) -{ - - if ((e->width != width || e->height != height) && e->x == 0 && e->y == 0) { - //qDebug() << "resize with bogus pos" << e->x << e->y << e->width << e->height << "window"<< hex << window; - } else { - //qDebug() << "geometry change" << e->x << e->y << e->width << e->height << "window"<< hex << window; - xpos = e->x; - ypos = e->y; - } - width = e->width; - height = e->height; - -#ifdef MYX11_DEBUG - qDebug() << hex << window << dec << "ConfigureNotify" << e->x << e->y << e->width << e->height << "geometry" << xpos << ypos << width << height << "img:" << shm_img.size(); -#endif - - windowTL->handleGeometryChange(xpos, ypos, width, height); -} - -#if 0 -void MyWindow::setSize(int w, int h) -{ - XResizeWindow(xd->display, window, w, h); -} -#endif - -void MyWindow::setGeometry(int x, int y, int w, int h) -{ -#ifdef MYX11_DEBUG - qDebug() << "MyWindow::setGeometry" << hex << window << dec << x << y << w << h << "img:" << shm_img.size(); -#endif - XMoveResizeWindow(xd->display, window, x, y, w, h); -} - - -void MyWindow::enterEvent(XCrossingEvent *) -{ -#ifdef MYX11_DEBUG - qDebug() << "MyWindow::enterEvent" << hex << window; -#endif - windowTL->handleEnterEvent(); -} - -void MyWindow::leaveEvent(XCrossingEvent *) -{ -#ifdef MYX11_DEBUG - qDebug() << "MyWindow::enterEvent" << hex << window; -#endif - windowTL->handleLeaveEvent(); -} - -void MyWindow::mousePressEvent(XButtonEvent *e) -{ - static long prevTime = 0; - static Window prevWindow; - static int prevX = -999; - static int prevY = -999; - - QEvent::Type type = QEvent::MouseButtonPress; - - if (e->window == prevWindow && long(e->time) - prevTime < QApplication::doubleClickInterval() - && qAbs(e->x - prevX) < 5 && qAbs(e->y - prevY) < 5) { - type = QEvent::MouseButtonDblClick; - prevTime = e->time - QApplication::doubleClickInterval(); //no double click next time - } else { - prevTime = e->time; - } - prevWindow = e->window; - prevX = e->x; - prevY = e->y; - - windowTL->handleMouseEvent(type, e); -} - -void MyWindow::mouseReleaseEvent(XButtonEvent *e) -{ - windowTL->handleMouseEvent(QEvent::MouseButtonRelease, e); -} - -void MyWindow::mouseMoveEvent(XButtonEvent *e) -{ - windowTL->handleMouseEvent(QEvent::MouseMove, e); -} - -#ifdef KeyPress -#undef KeyPress -#endif - -void MyWindow::keyPressEvent(XKeyEvent *e) -{ - windowTL->handleKeyEvent(QEvent::KeyPress, e); -} - -#ifdef KeyRelease -#undef KeyRelease -#endif - -void MyWindow::keyReleaseEvent(XKeyEvent *e) -{ - windowTL->handleKeyEvent(QEvent::KeyRelease, e); -} - - -// WindowFlag stuff, lots of copied code from qwidget_x11.cpp... - -//We're hacking here... - - -// MWM support -struct QtMWMHints { - ulong flags, functions, decorations; - long input_mode; - ulong status; -}; - -enum { - MWM_HINTS_FUNCTIONS = (1L << 0), - - MWM_FUNC_ALL = (1L << 0), - MWM_FUNC_RESIZE = (1L << 1), - MWM_FUNC_MOVE = (1L << 2), - MWM_FUNC_MINIMIZE = (1L << 3), - MWM_FUNC_MAXIMIZE = (1L << 4), - MWM_FUNC_CLOSE = (1L << 5), - - MWM_HINTS_DECORATIONS = (1L << 1), - - MWM_DECOR_ALL = (1L << 0), - MWM_DECOR_BORDER = (1L << 1), - MWM_DECOR_RESIZEH = (1L << 2), - MWM_DECOR_TITLE = (1L << 3), - MWM_DECOR_MENU = (1L << 4), - MWM_DECOR_MINIMIZE = (1L << 5), - MWM_DECOR_MAXIMIZE = (1L << 6), - - MWM_HINTS_INPUT_MODE = (1L << 2), - - MWM_INPUT_MODELESS = 0L, - MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L, - MWM_INPUT_FULL_APPLICATION_MODAL = 3L -}; - -static Atom mwm_hint_atom = XNone; - -static QtMWMHints GetMWMHints(Display *display, Window window) -{ - QtMWMHints mwmhints; - - Atom type; - int format; - ulong nitems, bytesLeft; - uchar *data = 0; - if ((XGetWindowProperty(display, window, mwm_hint_atom, 0, 5, false, - mwm_hint_atom, &type, &format, &nitems, &bytesLeft, - &data) == Success) - && (type == mwm_hint_atom - && format == 32 - && nitems >= 5)) { - mwmhints = *(reinterpret_cast(data)); - } else { - mwmhints.flags = 0L; - mwmhints.functions = MWM_FUNC_ALL; - mwmhints.decorations = MWM_DECOR_ALL; - mwmhints.input_mode = 0L; - mwmhints.status = 0L; - } - - if (data) - XFree(data); - - return mwmhints; -} - -static void SetMWMHints(Display *display, Window window, const QtMWMHints &mwmhints) -{ - if (mwmhints.flags != 0l) { - XChangeProperty(display, window, mwm_hint_atom, mwm_hint_atom, 32, - PropModeReplace, (unsigned char *) &mwmhints, 5); - } else { - XDeleteProperty(display, window, mwm_hint_atom); - } -} - -// Returns true if we should set WM_TRANSIENT_FOR on \a w -static inline bool isTransient(const QWidget *w) -{ - return ((w->windowType() == Qt::Dialog - || w->windowType() == Qt::Sheet - || w->windowType() == Qt::Tool - || w->windowType() == Qt::SplashScreen - || w->windowType() == Qt::ToolTip - || w->windowType() == Qt::Drawer - || w->windowType() == Qt::Popup) - && !w->testAttribute(Qt::WA_X11BypassTransientForHint)); -} - - - -Qt::WindowFlags MyWindow::setWindowFlags(Qt::WindowFlags flags) -{ - - if (mwm_hint_atom == XNone) { - mwm_hint_atom = XInternAtom(xd->display, "_MOTIF_WM_HINTS\0", False); - } - -#ifdef MYX11_DEBUG - qDebug() << "MyWindow::setWindowFlags" << hex << window << "flags" << flags; -#endif - Qt::WindowType type = static_cast(int(flags & Qt::WindowType_Mask)); - - if (type == Qt::ToolTip) - flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint; - if (type == Qt::Popup) - flags |= Qt::X11BypassWindowManagerHint; - - bool topLevel = (flags & Qt::Window); - bool popup = (type == Qt::Popup); - bool dialog = (type == Qt::Dialog - || type == Qt::Sheet); - bool desktop = (type == Qt::Desktop); - bool tool = (type == Qt::Tool || type == Qt::SplashScreen - || type == Qt::ToolTip || type == Qt::Drawer); - - bool tooltip = (type == Qt::ToolTip); - - XSetWindowAttributes wsa; - - QtMWMHints mwmhints; - mwmhints.flags = 0L; - mwmhints.functions = 0L; - mwmhints.decorations = 0; - mwmhints.input_mode = 0L; - mwmhints.status = 0L; - - - ulong wsa_mask = 0; - if (type != Qt::SplashScreen) { // && customize) { - mwmhints.flags |= MWM_HINTS_DECORATIONS; - - bool customize = flags & Qt::CustomizeWindowHint; - if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) { - mwmhints.decorations |= MWM_DECOR_BORDER; - mwmhints.decorations |= MWM_DECOR_RESIZEH; - - if (flags & Qt::WindowTitleHint) - mwmhints.decorations |= MWM_DECOR_TITLE; - - if (flags & Qt::WindowSystemMenuHint) - mwmhints.decorations |= MWM_DECOR_MENU; - - if (flags & Qt::WindowMinimizeButtonHint) { - mwmhints.decorations |= MWM_DECOR_MINIMIZE; - mwmhints.functions |= MWM_FUNC_MINIMIZE; - } - - if (flags & Qt::WindowMaximizeButtonHint) { - mwmhints.decorations |= MWM_DECOR_MAXIMIZE; - mwmhints.functions |= MWM_FUNC_MAXIMIZE; - } - - if (flags & Qt::WindowCloseButtonHint) - mwmhints.functions |= MWM_FUNC_CLOSE; - } - } else { - // if type == Qt::SplashScreen - mwmhints.decorations = MWM_DECOR_ALL; - } - - if (tool) { - wsa.save_under = True; - wsa_mask |= CWSaveUnder; - } - - if (flags & Qt::X11BypassWindowManagerHint) { - wsa.override_redirect = True; - wsa_mask |= CWOverrideRedirect; - } -#if 0 - if (wsa_mask && initializeWindow) { - Q_ASSERT(id); - XChangeWindowAttributes(dpy, id, wsa_mask, &wsa); - } -#endif - if (mwmhints.functions != 0) { - mwmhints.flags |= MWM_HINTS_FUNCTIONS; - mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE; - } else { - mwmhints.functions = MWM_FUNC_ALL; - } - - if (!(flags & Qt::FramelessWindowHint) - && flags & Qt::CustomizeWindowHint - && flags & Qt::WindowTitleHint - && !(flags & - (Qt::WindowMinimizeButtonHint - | Qt::WindowMaximizeButtonHint - | Qt::WindowCloseButtonHint))) { - // a special case - only the titlebar without any button - mwmhints.flags = MWM_HINTS_FUNCTIONS; - mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE; - mwmhints.decorations = 0; - } - - SetMWMHints(xd->display, window, mwmhints); - -//##### only if initializeWindow??? - - if (popup || tooltip) { // popup widget -#ifdef MYX11_DEBUG - qDebug() << "Doing XChangeWindowAttributes for popup" << wsa.override_redirect; -#endif - // set EWMH window types - // setNetWmWindowTypes(); - - wsa.override_redirect = True; - wsa.save_under = True; - XChangeWindowAttributes(xd->display, window, CWOverrideRedirect | CWSaveUnder, - &wsa); - } else { -#ifdef MYX11_DEBUG - qDebug() << "Doing XChangeWindowAttributes for non-popup"; -#endif - } - - return flags; -} - -void MyWindow::setVisible(bool visible) -{ -#ifdef MYX11_DEBUG - qDebug() << "MyWindow::setVisible" << visible << hex << window; -#endif - if (visible) - XMapWindow(xd->display, window); - else - XUnmapWindow(xd->display, window); -} - -MyX11Cursors::MyX11Cursors(Display * d) : firstExpired(0), lastExpired(0), display(d), removalDelay(3) -{ - connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); -} - -void MyX11Cursors::insertNode(MyX11CursorNode * node) -{ - QDateTime now = QDateTime::currentDateTime(); - QDateTime timeout = now.addSecs(removalDelay); - node->setExpiration(timeout); - node->setPost(0); - if (lastExpired) { - lastExpired->setPost(node); - node->setAnte(lastExpired); - } - lastExpired = node; - if (!firstExpired) { - firstExpired = node; - node->setAnte(0); - int interval = removalDelay * 1000; - timer.setInterval(interval); - timer.start(); - } -} - -void MyX11Cursors::removeNode(MyX11CursorNode * node) -{ - MyX11CursorNode *pre = node->ante(); - MyX11CursorNode *post = node->post(); - if (pre) - pre->setPost(post); - if (post) - post->setAnte(pre); - if (node == lastExpired) - lastExpired = pre; - if (node == firstExpired) { - firstExpired = post; - if (!firstExpired) { - timer.stop(); - return; - } - int interval = QDateTime::currentDateTime().secsTo(firstExpired->expiration()) * 1000; - timer.stop(); - timer.setInterval(interval); - timer.start(); - } -} - -void MyX11Cursors::incrementUseCount(int id) -{ - MyX11CursorNode * node = lookupMap.value(id); - Q_ASSERT(node); - if (!node->refCount) - removeNode(node); - node->refCount++; -} - -void MyX11Cursors::decrementUseCount(int id) -{ - MyX11CursorNode * node = lookupMap.value(id); - Q_ASSERT(node); - node->refCount--; - if (!node->refCount) - insertNode(node); -} - -void MyX11Cursors::createNode(int id, Cursor c) -{ - MyX11CursorNode * node = new MyX11CursorNode(id, c); - lookupMap.insert(id, node); -} - -void MyX11Cursors::timeout() -{ - MyX11CursorNode * node; - node = firstExpired; - QDateTime now = QDateTime::currentDateTime(); - while (node && now.secsTo(node->expiration()) < 1) { - Cursor c = node->cursor(); - int id = node->id(); - lookupMap.take(id); - MyX11CursorNode * tmp = node; - node = node->post(); - delete tmp; - XFreeCursor(display, c); - } - firstExpired = node; - if (node == 0) { - timer.stop(); - lastExpired = 0; - } - else { - int interval = QDateTime::currentDateTime().secsTo(firstExpired->expiration()) * 1000; - timer.setInterval(interval); - timer.start(); - } -} - -Cursor MyX11Cursors::cursor(int id) -{ - MyX11CursorNode * node = lookupMap.value(id); - Q_ASSERT(node); - return node->cursor(); -} - -void MyWindow::setCursor(QCursor * cursor) -{ - int id = cursor->handle(); - if (id == currentCursor) - return; - Cursor c; - if (!xd->cursors->exists(id)) { - if (cursor->shape() == Qt::BitmapCursor) - c = createCursorBitmap(cursor); - else - c = createCursorShape(cursor->shape()); - if (!c) { - return; - } - xd->cursors->createNode(id, c); - } else { - xd->cursors->incrementUseCount(id); - c = xd->cursors->cursor(id); - } - - if (currentCursor != -1) - xd->cursors->decrementUseCount(currentCursor); - currentCursor = id; - - XDefineCursor(xd->display, window, c); - XFlush(xd->display); -} - -Cursor MyWindow::createCursorBitmap(QCursor * cursor) -{ - XColor bg, fg; - bg.red = 255 << 8; - bg.green = 255 << 8; - bg.blue = 255 << 8; - fg.red = 0; - fg.green = 0; - fg.blue = 0; - QPoint spot = cursor->hotSpot(); - Window rootwin = window; - - QImage mapImage = cursor->bitmap()->toImage().convertToFormat(QImage::Format_MonoLSB); - QImage maskImage = cursor->mask()->toImage().convertToFormat(QImage::Format_MonoLSB); - - int width = cursor->bitmap()->width(); - int height = cursor->bitmap()->height(); - int bytesPerLine = mapImage.bytesPerLine(); - int destLineSize = width / 8; - if (width % 8) - destLineSize++; - - const uchar * map = mapImage.bits(); - const uchar * mask = maskImage.bits(); - - char * mapBits = new char[height * destLineSize]; - char * maskBits = new char[height * destLineSize]; - for (int i = 0; i < height; i++) { - memcpy(mapBits + (destLineSize * i),map + (bytesPerLine * i), destLineSize); - memcpy(maskBits + (destLineSize * i),mask + (bytesPerLine * i), destLineSize); - } - - Pixmap cp = XCreateBitmapFromData(xd->display, rootwin, mapBits, width, height); - Pixmap mp = XCreateBitmapFromData(xd->display, rootwin, maskBits, width, height); - Cursor c = XCreatePixmapCursor(xd->display, cp, mp, &fg, &bg, spot.x(), spot.y()); - XFreePixmap(xd->display, cp); - XFreePixmap(xd->display, mp); - delete[] mapBits; - delete[] maskBits; - - return c; -} - -Cursor MyWindow::createCursorShape(int cshape) -{ - Cursor cursor = 0; - - if (cshape < 0 || cshape > Qt::LastCursor) - return 0; - - switch (cshape) { - case Qt::ArrowCursor: - cursor = XCreateFontCursor(xd->display, XC_left_ptr); - break; - case Qt::UpArrowCursor: - cursor = XCreateFontCursor(xd->display, XC_center_ptr); - break; - case Qt::CrossCursor: - cursor = XCreateFontCursor(xd->display, XC_crosshair); - break; - case Qt::WaitCursor: - cursor = XCreateFontCursor(xd->display, XC_watch); - break; - case Qt::IBeamCursor: - cursor = XCreateFontCursor(xd->display, XC_xterm); - break; - case Qt::SizeAllCursor: - cursor = XCreateFontCursor(xd->display, XC_fleur); - break; - case Qt::PointingHandCursor: - cursor = XCreateFontCursor(xd->display, XC_hand2); - break; - case Qt::SizeBDiagCursor: - cursor = XCreateFontCursor(xd->display, XC_top_right_corner); - break; - case Qt::SizeFDiagCursor: - cursor = XCreateFontCursor(xd->display, XC_bottom_right_corner); - break; - case Qt::SizeVerCursor: - case Qt::SplitVCursor: - cursor = XCreateFontCursor(xd->display, XC_sb_v_double_arrow); - break; - case Qt::SizeHorCursor: - case Qt::SplitHCursor: - cursor = XCreateFontCursor(xd->display, XC_sb_h_double_arrow); - break; - case Qt::WhatsThisCursor: - cursor = XCreateFontCursor(xd->display, XC_question_arrow); - break; - case Qt::ForbiddenCursor: - cursor = XCreateFontCursor(xd->display, XC_circle); - break; - case Qt::BusyCursor: - cursor = XCreateFontCursor(xd->display, XC_watch); - break; - - default: //default cursor for all the rest - break; - } - return cursor; -} - - -#if 0 - - - switch (cshape) { // map Q cursor to X cursor - case Qt::BlankCursor: - XColor bg, fg; - bg.red = 255 << 8; - bg.green = 255 << 8; - bg.blue = 255 << 8; - fg.red = 0; - fg.green = 0; - fg.blue = 0; - pm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16); - pmm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16); - hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8); - return; - break; - default: - qWarning("QCursor::update: Invalid cursor shape %d", cshape); - return; - } -#endif diff --git a/src/plugins/platforms/testlite/x11util.h b/src/plugins/platforms/testlite/x11util.h deleted file mode 100644 index b28d1e8..0000000 --- a/src/plugins/platforms/testlite/x11util.h +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtOpenVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MYX11UTIL_H -#define MYX11UTIL_H - -#include -#include -#include -#include - -#include - -#include -#include - - -class MyWindow; -class MyX11Cursors; - -class MyDisplay : public QObject -{ - Q_OBJECT; -public: - MyDisplay(); - ~MyDisplay(); - - Window rootWindow() { return RootWindow(display, screen); } - unsigned long blackPixel() { return BlackPixel(display, screen); } - unsigned long whitePixel() { return WhitePixel(display, screen); } - - bool handleEvent(XEvent *xe); - QImage grabWindow(Window window, int x, int y, int w, int h); - -public slots: - void eventDispatcher(); - -public: //### - Display * display; - int screen; - int width, height; - int physicalWidth; - int physicalHeight; - - QList windowList; - - MyX11Cursors * cursors; -}; - -class QTestLiteWindow; //### abstract callback interface, anyone? - -struct MyShmImageInfo; - -class MyWindow : public QObject -{ - Q_OBJECT; -public: - MyWindow(MyDisplay *xd, int x, int y, int w, int h); - ~MyWindow(); - - - void mousePressEvent(XButtonEvent*); - void mouseReleaseEvent(XButtonEvent*); - void mouseMoveEvent(XButtonEvent*); - - void keyPressEvent(XKeyEvent*); - void keyReleaseEvent(XKeyEvent*); - - void enterEvent(XCrossingEvent*); - void leaveEvent(XCrossingEvent*); - - void closeEvent(); - void paintEvent(); - void resizeEvent(XConfigureEvent *configure_event); -// void setSize(int w, int h); - void setGeometry(int x, int y, int w, int h); - - GC createGC(); - - Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags); - void setVisible(bool visible); - void setCursor(QCursor * cursor); - Cursor createCursorShape(int cshape); - Cursor createCursorBitmap(QCursor * cursor); - - void setWindowTitle(const QString &title); - - QImage *image() { return &shm_img; } - -public: //### - - int xpos, ypos; - int width, height; - Window window; - MyDisplay *xd; - GC gc; - - QTestLiteWindow *windowTL; - - int currentCursor; - bool painted; - void resizeBuffer(QSize); - QSize bufferSize() const; - -private: - void resizeShmImage(int width, int height); - - QImage shm_img; - MyShmImageInfo *image_info; -}; - -class MyX11CursorNode -{ -public: - MyX11CursorNode(int id, Cursor c) { idValue = id; cursorValue = c; refCount = 1; } - QDateTime expiration() { return t; } - void setExpiration(QDateTime val) { t = val; } - MyX11CursorNode * ante() { return before; } - void setAnte(MyX11CursorNode *node) { before = node; } - MyX11CursorNode * post() { return after; } - void setPost(MyX11CursorNode *node) { after = node; } - Cursor cursor() { return cursorValue; } - int id() { return idValue; } - unsigned int refCount; - -private: - MyX11CursorNode *before; - MyX11CursorNode *after; - QDateTime t; - Cursor cursorValue; - int idValue; - - Display * display; -}; - -class MyX11Cursors : public QObject -{ - Q_OBJECT -public: - MyX11Cursors(Display * d); - ~MyX11Cursors() { timer.stop(); } - void incrementUseCount(int id); - void decrementUseCount(int id); - void createNode(int id, Cursor c); - bool exists(int id) { return lookupMap.contains(id); } - Cursor cursor(int id); -public slots: - void timeout(); - -private: - void removeNode(MyX11CursorNode *node); - void insertNode(MyX11CursorNode *node); - - // linked list of cursors currently not assigned to any window - MyX11CursorNode *firstExpired; - MyX11CursorNode *lastExpired; - - QHash lookupMap; - QTimer timer; - - Display *display; - - int removalDelay; -}; - -#endif // MYX11UTIL_H -- cgit v0.12 From b260d7b806c239505324d6a4762d3755e74a1b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 12 Apr 2010 12:33:25 +0200 Subject: Fix forward declaration in qplatformwindow_lite.h --- src/gui/kernel/qplatformwindow_lite.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qplatformwindow_lite.h b/src/gui/kernel/qplatformwindow_lite.h index 8771cfe..583ac28 100644 --- a/src/gui/kernel/qplatformwindow_lite.h +++ b/src/gui/kernel/qplatformwindow_lite.h @@ -47,13 +47,13 @@ #include #include -class QPlatformWindowPrivate; -class QWidget; QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +class QPlatformWindowPrivate; +class QWidget; class Q_GUI_EXPORT QPlatformWindow { Q_DECLARE_PRIVATE(QPlatformWindow); -- cgit v0.12 From 0851bd20f126a7dafec776771795e08de5ac9fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 12 Apr 2010 12:46:34 +0200 Subject: Cleaned up Blitter Paint engine and fixed a couple of bugs --- src/gui/painting/qpaintengine_blitter.cpp | 111 ++++++++++----------- src/gui/painting/qpaintengine_blitter_p.h | 1 - .../platforms/directfb/qblitter_directfb.cpp | 5 +- 3 files changed, 56 insertions(+), 61 deletions(-) diff --git a/src/gui/painting/qpaintengine_blitter.cpp b/src/gui/painting/qpaintengine_blitter.cpp index 0b74a4d..54a146f 100644 --- a/src/gui/painting/qpaintengine_blitter.cpp +++ b/src/gui/painting/qpaintengine_blitter.cpp @@ -30,14 +30,20 @@ static inline void updateStateBits(uint *state, uint mask, bool on) *state = on ? (*state | mask) : (*state & ~mask); } +static inline bool checkStateAgainstMask(uint state, uint mask) +{ + return !state || (state & mask && !(state & ~mask)); +} + class CapabilitiesToStateMask { public: CapabilitiesToStateMask(QBlittable::Capabilities capabilities) : m_capabilities(capabilities), - fillRectMask(0), fillRectState(0), - drawRectMask(0), drawRectState(0), - drawPixmapMask(0), drawPixmapState(0) + fillRectMask(0), + drawRectMask(0), + drawPixmapMask(0), + capabillitiesState(0) { if (capabilities & QBlittable::SolidRectCapability) { setFillRectMask(); @@ -48,23 +54,26 @@ public: if (capabilities & QBlittable::SourceOverPixmapCapability) { setSourceOverPixmapMask(); } + if (capabilities & QBlittable::SourceOverScaledPixmapCapability) { + setSourceOverScaledPixmapMask(); + } } inline bool canBlitterFillRect() const { - return !fillRectState || (fillRectState & fillRectMask); + return checkStateAgainstMask(capabillitiesState,fillRectMask); } inline bool canBlitterDrawRectMask() const { - return drawRectState & drawRectMask; + return checkStateAgainstMask(capabillitiesState,drawRectMask); } bool canBlitterDrawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) const { if (pm.pixmapData()->classId() != QPixmapData::BlitterClass) return false; - if ((!drawPixmapState) || drawPixmapState & drawPixmapMask) { + if (checkStateAgainstMask(capabillitiesState,drawPixmapMask)) { if (m_capabilities & (QBlittable::SourceOverPixmapCapability | QBlittable::SourceOverScaledPixmapCapability)) { if (r.size() != sr.size()) { @@ -80,21 +89,8 @@ public: return false; } - inline void updateFillRectBits(uint mask, bool on) { - updateStateBits(&fillRectState,mask,on); - } - - inline void updateDrawRectBits(uint mask, bool on) { - updateStateBits(&drawRectState,mask,on); - } - - inline void updateDrawPixmapBits(uint mask, bool on) { - updateStateBits(&drawPixmapState,mask,on); - } - inline void updateAllWithBits(uint mask, bool on) { - updateStateBits(&fillRectState,mask,on); - updateStateBits(&drawRectState,mask,on); - updateStateBits(&drawPixmapState,mask,on); + inline void updateState(uint mask, bool on) { + updateStateBits(&capabillitiesState,mask,on); } public: @@ -138,17 +134,21 @@ public: setSourcePixmapMask(); } + void setSourceOverScaledPixmapMask() { + setSourceOverPixmapMask(); + updateStateBits(&drawRectMask, STATE_XFORM_SCALE, true); + } + QBlittable::Capabilities m_capabilities; uint fillRectMask; - uint fillRectState; uint drawRectMask; - uint drawRectState; uint drawPixmapMask; - uint drawPixmapState; + uint capabillitiesState; }; class QBlitterPaintEnginePrivate : public QPaintEngineExPrivate { + Q_DECLARE_PUBLIC(QBlitterPaintEngine); public: QBlitterPaintEnginePrivate(QBlittablePixmapData *p) : QPaintEngineExPrivate(), @@ -176,12 +176,13 @@ public: } void fillRect(const QRectF &rect, const QColor &color) { + Q_Q(QBlitterPaintEngine); pmData->unmarkRasterOverlay(rect); QRectF targetRect = rect; if (hasXForm) { - targetRect = state->matrix.mapRect(rect); + targetRect = q->state()->matrix.mapRect(rect); } - const QClipData *clipData = raster->d_func()->clip();; + const QClipData *clipData = q->clip(); if (clipData) { if (clipData->hasRectClip) { unlock(); @@ -214,23 +215,23 @@ public: QRectF intersectedRect = clip.intersected(target); if (intersectedRect.isEmpty()) return; - QRectF source = sr; if(intersectedRect.size() != target.size()) { qreal deltaTop = target.top() - intersectedRect.top(); qreal deltaLeft = target.left() - intersectedRect.left(); qreal deltaBottom = target.bottom() - intersectedRect.bottom(); qreal deltaRight = target.right() - intersectedRect.right(); - source.adjust(-deltaLeft,-deltaTop,deltaRight,deltaBottom); + source.adjust(-deltaLeft,-deltaTop,-deltaRight,-deltaBottom); } pmData->unmarkRasterOverlay(intersectedRect); pmData->blittable()->drawPixmap(intersectedRect, pm, source); } void updateClip() { - const QClipData *clip = raster->d_func()->clip(); - bool complex = clip != 0 && !(clip->hasRectClip || clip->hasRegionClip); - capabillities->updateAllWithBits(STATE_CLIP_COMPLEX, complex); + Q_Q(QBlitterPaintEngine); + const QClipData *clip = q->clip(); + bool complex = clip && !(clip->hasRectClip || clip->hasRegionClip); + capabillities->updateState(STATE_CLIP_COMPLEX, complex); } void systemStateChanged() { @@ -238,7 +239,6 @@ public: } QRasterPaintEngine *raster; - QRasterPaintEngineState *state; QBlittablePixmapData *pmData; bool isBlitterLocked; @@ -267,8 +267,6 @@ bool QBlitterPaintEngine::begin(QPaintDevice *pdev) { Q_D(QBlitterPaintEngine); - d->raster->setSystemRect(systemRect()); - d->raster->setSystemClip(systemClip()); setActive(true); bool ok = d->raster->begin(pdev); #ifdef QT_BLITTER_RASTEROVERLAY @@ -282,8 +280,6 @@ bool QBlitterPaintEngine::end() { Q_D(QBlitterPaintEngine); - d->raster->setPaintDevice(0); - d->raster->setActive(false); setActive(false); #ifdef QT_BLITTER_RASTEROVERLAY d->pmData->mergeOverlay(); @@ -321,7 +317,9 @@ void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) { if(rect.size().isEmpty()) return; + Q_D(QBlitterPaintEngine); + if (qbrush_style(brush) == Qt::SolidPattern && qbrush_color(brush).alpha() == 0xff && d->capabillities->canBlitterFillRect()) @@ -336,11 +334,11 @@ void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) qreal y = transformedRect.y(); QPixmap pm = brush.texture(); d->unlock(); - int srcX = (int)(rect.x() - d->raster->state()->brushOrigin.x()) % pm.width(); + int srcX = int(rect.x() - state()->brushOrigin.x()) % pm.width(); if (srcX < 0) srcX = pm.width() + srcX; const int startX = srcX; - int srcY = (int)(rect.y() - d->raster->state()->brushOrigin.y())% pm.height(); + int srcY = int(rect.y() - state()->brushOrigin.y()) % pm.height(); if (srcY < 0) srcY = pm.height() + srcY; while (!rectIsFilled) { @@ -350,7 +348,7 @@ void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) blitWidth = transformedRect.right() -x; if (y + blitHeight > transformedRect.bottom()) blitHeight = transformedRect.bottom() - y; - const QClipData *clipData = d->raster->d_func()->clip(); + const QClipData *clipData = clip(); if (clipData->hasRectClip) { QRect targetRect = QRect(x,y,blitWidth,blitHeight).intersected(clipData->clipRect); if (targetRect.isValid()) { @@ -434,7 +432,7 @@ void QBlitterPaintEngine::penChanged() Q_D(QBlitterPaintEngine); d->lock(); d->raster->penChanged(); - d->capabillities->updateDrawRectBits(STATE_PEN_ENABLED,qpen_style(d->state->pen) != Qt::NoPen); + d->capabillities->updateState(STATE_PEN_ENABLED,qpen_style(state()->pen) != Qt::NoPen); } void QBlitterPaintEngine::brushChanged() @@ -442,11 +440,11 @@ void QBlitterPaintEngine::brushChanged() Q_D(QBlitterPaintEngine); d->raster->brushChanged(); - bool solid = qbrush_style(d->state->brush) == Qt::SolidPattern; + bool solid = qbrush_style(state()->brush) == Qt::SolidPattern; - d->capabillities->updateDrawRectBits(STATE_BRUSH_PATTERN, !solid); - d->capabillities->updateDrawRectBits(STATE_BRUSH_ALPHA, - qbrush_color(d->state->brush).alpha() < 255); + d->capabillities->updateState(STATE_BRUSH_PATTERN, !solid); + d->capabillities->updateState(STATE_BRUSH_ALPHA, + qbrush_color(state()->brush).alpha() < 255); } void QBlitterPaintEngine::brushOriginChanged() @@ -460,8 +458,8 @@ void QBlitterPaintEngine::opacityChanged() Q_D(QBlitterPaintEngine); d->raster->opacityChanged(); - bool translucent = d->state->opacity < 1; - d->capabillities->updateAllWithBits(STATE_ALPHA,translucent); + bool translucent = state()->opacity < 1; + d->capabillities->updateState(STATE_ALPHA,translucent); } void QBlitterPaintEngine::compositionModeChanged() @@ -469,10 +467,10 @@ void QBlitterPaintEngine::compositionModeChanged() Q_D(QBlitterPaintEngine); d->raster->compositionModeChanged(); - bool nonTrivial = d->state->composition_mode != QPainter::CompositionMode_SourceOver - && d->state->composition_mode != QPainter::CompositionMode_Source; + bool nonTrivial = state()->composition_mode != QPainter::CompositionMode_SourceOver + && state()->composition_mode != QPainter::CompositionMode_Source; - d->capabillities->updateAllWithBits(STATE_BLENDING_COMPLEX,nonTrivial); + d->capabillities->updateState(STATE_BLENDING_COMPLEX,nonTrivial); } void QBlitterPaintEngine::renderHintsChanged() @@ -480,9 +478,8 @@ void QBlitterPaintEngine::renderHintsChanged() Q_D(QBlitterPaintEngine); d->raster->renderHintsChanged(); - bool aa = d->state->renderHints & QPainter::Antialiasing; - d->capabillities->updateFillRectBits(STATE_ANTIALIASING, aa); - d->capabillities->updateDrawRectBits(STATE_ANTIALIASING, aa); + bool aa = state()->renderHints & QPainter::Antialiasing; + d->capabillities->updateState(STATE_ANTIALIASING, aa); } @@ -491,9 +488,10 @@ void QBlitterPaintEngine::transformChanged() Q_D(QBlitterPaintEngine); d->raster->transformChanged(); - QTransform::TransformationType type = d->state->matrix.type(); + QTransform::TransformationType type = state()->matrix.type(); - d->capabillities->updateAllWithBits(STATE_XFORM_COMPLEX, type > QTransform::TxScale); + d->capabillities->updateState(STATE_XFORM_COMPLEX, type > QTransform::TxScale); + d->capabillities->updateState(STATE_XFORM_SCALE, type > QTransform::TxTranslate); d->hasXForm = type >= QTransform::TxTranslate; @@ -504,7 +502,7 @@ void QBlitterPaintEngine::drawRects(const QRect *rects, int rectCount) Q_D(QBlitterPaintEngine); if (d->capabillities->canBlitterDrawRectMask()) { for (int i=0; ifillRect(rects[i], qbrush_color(d->state->brush)); + d->fillRect(rects[i], qbrush_color(state()->brush)); } } else { d->pmData->markRasterOverlay(rects,rectCount); @@ -517,7 +515,7 @@ void QBlitterPaintEngine::drawRects(const QRectF *rects, int rectCount) Q_D(QBlitterPaintEngine); if (d->capabillities->canBlitterDrawRectMask()) { for (int i=0; ifillRect(rects[i], qbrush_color(d->state->brush)); + d->fillRect(rects[i], qbrush_color(state()->brush)); } } else { d->pmData->markRasterOverlay(rects,rectCount); @@ -600,7 +598,6 @@ void QBlitterPaintEngine::setState(QPainterState *s) d->lock(); QPaintEngineEx::setState(s); d->raster->setState(s); - d->state = (QRasterPaintEngineState *) s; clipEnabledChanged(); penChanged(); diff --git a/src/gui/painting/qpaintengine_blitter_p.h b/src/gui/painting/qpaintengine_blitter_p.h index d436993..3a2fce5 100644 --- a/src/gui/painting/qpaintengine_blitter_p.h +++ b/src/gui/painting/qpaintengine_blitter_p.h @@ -64,7 +64,6 @@ public: private: QRasterPaintEngine *raster() const; - }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/directfb/qblitter_directfb.cpp b/src/plugins/platforms/directfb/qblitter_directfb.cpp index 08dee0a..6525022 100644 --- a/src/plugins/platforms/directfb/qblitter_directfb.cpp +++ b/src/plugins/platforms/directfb/qblitter_directfb.cpp @@ -28,6 +28,7 @@ QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, IDirectFBSurface *surface) dfb->CreateSurface(dfb,&surfaceDesc, &m_surface); m_surface->Clear(m_surface,0,0,0,0); } + } QDirectFbBlitter::~QDirectFbBlitter() @@ -60,13 +61,11 @@ void QDirectFbBlitter::drawPixmap(const QRectF &rect, const QPixmap &pixmap, con IDirectFBSurface *s = dfbBlitter->m_surface; quint32 blittingFlags = pixmap.hasAlpha()? DSBLIT_BLEND_ALPHACHANNEL : DSBLIT_NOFX; - - s->SetBlittingFlags(s, DFBSurfaceBlittingFlags(blittingFlags)); m_surface->SetBlittingFlags(m_surface, DFBSurfaceBlittingFlags(blittingFlags)); m_surface->SetPorterDuff(m_surface,DSPD_SRC_OVER); m_surface->SetDstBlendFunction(m_surface,DSBF_INVSRCALPHA); - const DFBRectangle sRect = { srcRect.x(), srcRect.y(), rect.width(), rect.height() }; + const DFBRectangle sRect = { srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height() }; DFBResult result; if (rect.width() == srcRect.width() && rect.height() == srcRect.height()) -- cgit v0.12 From 3cf347414ce2203178893fb1fa1d005633d37526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 12 Apr 2010 13:47:52 +0200 Subject: Small optimalisation in DirectfbBlitter --- src/gui/painting/qpaintengine_blitter.cpp | 2 +- src/plugins/platforms/directfb/qblitter_directfb.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gui/painting/qpaintengine_blitter.cpp b/src/gui/painting/qpaintengine_blitter.cpp index 54a146f..4144696 100644 --- a/src/gui/painting/qpaintengine_blitter.cpp +++ b/src/gui/painting/qpaintengine_blitter.cpp @@ -533,7 +533,7 @@ void QBlitterPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const Q if (d->hasXForm) { targetRect = state()->matrix.mapRect(r); } - const QClipData *clipData = d->raster->d_func()->clip(); + const QClipData *clipData = clip(); if (clipData) { if (clipData->hasRectClip) { d->clipAndDrawPixmap(clipData->clipRect,targetRect,pm,sr); diff --git a/src/plugins/platforms/directfb/qblitter_directfb.cpp b/src/plugins/platforms/directfb/qblitter_directfb.cpp index 6525022..20f8741 100644 --- a/src/plugins/platforms/directfb/qblitter_directfb.cpp +++ b/src/plugins/platforms/directfb/qblitter_directfb.cpp @@ -60,9 +60,15 @@ void QDirectFbBlitter::drawPixmap(const QRectF &rect, const QPixmap &pixmap, con IDirectFBSurface *s = dfbBlitter->m_surface; - quint32 blittingFlags = pixmap.hasAlpha()? DSBLIT_BLEND_ALPHACHANNEL : DSBLIT_NOFX; + DFBSurfaceBlittingFlags blittingFlags = DSBLIT_NOFX; + DFBSurfacePorterDuffRule porterDuff = DSPD_SRC; + if (pixmap.hasAlpha()) { + blittingFlags = DSBLIT_BLEND_ALPHACHANNEL; + porterDuff = DSPD_SRC_OVER; + } + m_surface->SetBlittingFlags(m_surface, DFBSurfaceBlittingFlags(blittingFlags)); - m_surface->SetPorterDuff(m_surface,DSPD_SRC_OVER); + m_surface->SetPorterDuff(m_surface,porterDuff); m_surface->SetDstBlendFunction(m_surface,DSBF_INVSRCALPHA); const DFBRectangle sRect = { srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height() }; -- cgit v0.12 From 1d768c1deb98a8e32cdbd7790186e1d6a81acc29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 12 Apr 2010 14:20:39 +0200 Subject: Ifdef out QPlatformWindow implementation when not compiling lighthouse --- src/gui/kernel/qwidget.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 7eaf03c..07639ba 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11842,6 +11842,7 @@ QWindowSurface *QWidget::windowSurface() const return bs ? bs->windowSurface : 0; } +#if defined(Q_WS_LITE) /*! \preliminary @@ -11879,6 +11880,7 @@ QPlatformWindow *QWidget::platformWindow() const return 0; } +#endif //defined(Q_WS_LITE) void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const { -- cgit v0.12 From 80c3790501df2ce3a8edf022e469317bc6f66246 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Mon, 12 Apr 2010 15:21:35 +0200 Subject: Make the VNC plugin compile and largely work --- src/gui/kernel/qplatformscreen_lite.h | 4 +- src/gui/kernel/qwidget_lite.cpp | 18 +++- src/plugins/platforms/fb_base/fb_base.cpp | 98 ++++++++++++++++------ src/plugins/platforms/fb_base/fb_base.h | 58 ++++++++++--- src/plugins/platforms/testlite/qtestlitewindow.cpp | 1 + src/plugins/platforms/vnc/main.cpp | 8 +- src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp | 22 ++++- src/plugins/platforms/vnc/qgraphicssystem_vnc.h | 11 +-- src/plugins/platforms/vnc/vnc.pro | 4 +- 9 files changed, 168 insertions(+), 56 deletions(-) diff --git a/src/gui/kernel/qplatformscreen_lite.h b/src/gui/kernel/qplatformscreen_lite.h index da0e26b..cae5f42 100644 --- a/src/gui/kernel/qplatformscreen_lite.h +++ b/src/gui/kernel/qplatformscreen_lite.h @@ -44,6 +44,7 @@ #include #include +#include QT_BEGIN_HEADER @@ -51,8 +52,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Gui) -class Q_GUI_EXPORT QPlatformScreen +class Q_GUI_EXPORT QPlatformScreen : public QObject { + Q_OBJECT public: virtual ~QPlatformScreen() { } diff --git a/src/gui/kernel/qwidget_lite.cpp b/src/gui/kernel/qwidget_lite.cpp index cf93c5e..465dbee 100644 --- a/src/gui/kernel/qwidget_lite.cpp +++ b/src/gui/kernel/qwidget_lite.cpp @@ -90,10 +90,8 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO void QWidget::destroy(bool destroyWindow, bool destroySubWindows) { - Q_UNUSED(destroyWindow); + Q_D(QWidget); Q_UNUSED(destroySubWindows); - // XXX - if ((windowType() == Qt::Popup)) qApp->d_func()->closePopup(this); @@ -101,6 +99,20 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) //### we don't have proper focus event handling yet if (this == QApplicationPrivate::active_window) QApplication::setActiveWindow(0); + + if (windowType() != Qt::Desktop) { + if (destroyWindow && isWindow()) { + QTLWExtra *topData = d->maybeTopData(); + if (topData) { + delete topData->platformWindow; + topData->platformWindow = 0; + } + } else { + if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) { + d->hide_sys(); + } + } + } } void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) diff --git a/src/plugins/platforms/fb_base/fb_base.cpp b/src/plugins/platforms/fb_base/fb_base.cpp index d30746a..422222c 100644 --- a/src/plugins/platforms/fb_base/fb_base.cpp +++ b/src/plugins/platforms/fb_base/fb_base.cpp @@ -6,7 +6,7 @@ #include #include -QGraphicsSystemSoftwareCursor::QGraphicsSystemSoftwareCursor(QGraphicsSystemScreen *scr) +QGraphicsSystemSoftwareCursor::QGraphicsSystemSoftwareCursor(QPlatformScreen *scr) : QGraphicsSystemCursor(scr), currentRect(QRect()), prevRect(QRect()) { graphic = new QGraphicsSystemCursorImage(0, 0, 0, 0, 0, 0); @@ -126,6 +126,8 @@ QGraphicsSystemFbScreen::~QGraphicsSystemFbScreen() void QGraphicsSystemFbScreen::setDirty(const QRect &rect) { + +// qDebug() << "QGraphicsSystemFbScreen::setDirty" << rect; repaintRegion += rect; if (!redrawTimer.isActive()) { redrawTimer.start(); @@ -140,7 +142,7 @@ void QGraphicsSystemFbScreen::generateRects() for (int i = 0; i < windowStack.length(); i++) { if (remainingScreen.isEmpty()) break; - if (!windowStack[i]->window()->testAttribute(Qt::WA_TranslucentBackground)) { + if (!windowStack[i]->widget()->testAttribute(Qt::WA_TranslucentBackground)) { remainingScreen -= windowStack[i]->geometry(); QRegion windowRegion(windowStack[i]->geometry()); windowRegion -= remainingScreen; @@ -197,12 +199,13 @@ QRegion QGraphicsSystemFbScreen::doRedraw() for (int layerIndex = layer; layerIndex != -1; layerIndex--) { if (!windowStack[layerIndex]->visible()) continue; - if (windowStack[layerIndex]->window()->isMinimized()) + if (windowStack[layerIndex]->widget()->isMinimized()) continue; QRect windowRect = windowStack[layerIndex]->geometry(); QRect windowIntersect = rect.translated(-windowRect.left(), -windowRect.top()); - compositePainter->drawImage(rect, windowStack[layerIndex]->image(), +// qDebug() << " compositing" << layerIndex << windowStack[layerIndex]->surface->image().size(); + compositePainter->drawImage(rect, windowStack[layerIndex]->surface->image(), windowIntersect); if (firstLayer) { firstLayer = false; @@ -224,24 +227,29 @@ QRegion QGraphicsSystemFbScreen::doRedraw() touchedRegion += repaintRegion; repaintRegion = QRegion(); + + +// qDebug() << "QGraphicsSystemFbScreen::doRedraw" << windowStack.size() << mScreenImage->size() << touchedRegion; + + return touchedRegion; } -void QGraphicsSystemFbScreen::removeWindowSurface(QGraphicsSystemFbWindowSurface * surface) +void QGraphicsSystemFbScreen::removeWindow(QFbWindow * surface) { windowStack.removeOne(surface); invalidateRectCache(); setDirty(surface->geometry()); } -void QGraphicsSystemFbWindowSurface::raise() +void QFbWindow::raise() { mScreen->raise(this); } -void QGraphicsSystemFbScreen::raise(QWindowSurface * surface) +void QGraphicsSystemFbScreen::raise(QPlatformWindow * surface) { - QGraphicsSystemFbWindowSurface *s = static_cast(surface); + QFbWindow *s = static_cast(surface); int index = windowStack.indexOf(s); if (index <= 0) return; @@ -250,14 +258,14 @@ void QGraphicsSystemFbScreen::raise(QWindowSurface * surface) setDirty(s->geometry()); } -void QGraphicsSystemFbWindowSurface::lower() +void QFbWindow::lower() { mScreen->lower(this); } -void QGraphicsSystemFbScreen::lower(QWindowSurface * surface) +void QGraphicsSystemFbScreen::lower(QPlatformWindow * surface) { - QGraphicsSystemFbWindowSurface *s = static_cast(surface); + QFbWindow *s = static_cast(surface); int index = windowStack.indexOf(s); if (index == -1 || index == (windowStack.size() - 1)) return; @@ -271,34 +279,61 @@ QWidget * QGraphicsSystemFbScreen::topLevelAt(const QPoint & p) const for(int i = 0; i < windowStack.size(); i++) { if (windowStack[i]->geometry().contains(p, false) && windowStack[i]->visible() && - !windowStack[i]->window()->isMinimized()) { - return windowStack[i]->window(); + !windowStack[i]->widget()->isMinimized()) { + return windowStack[i]->widget(); } } return 0; } -QGraphicsSystemFbWindowSurface::QGraphicsSystemFbWindowSurface(QGraphicsSystemFbScreen *screen, QWidget *window) - : QWindowSurface(window), + + +QFbWindow::QFbWindow(QGraphicsSystemFbScreen *screen, QWidget *window) + :QPlatformWindow(window), mScreen(screen), visibleFlag(false) { static QAtomicInt winIdGenerator(1); + windowId = winIdGenerator.fetchAndAddRelaxed(1); +} + + +QFbWindow::~QFbWindow() +{ + mScreen->removeWindow(this); +} + +QGraphicsSystemFbWindowSurface::QGraphicsSystemFbWindowSurface(QGraphicsSystemFbScreen *screen, QWidget *window) + : QWindowSurface(window), + mScreen(screen) +{ mImage = QImage(window->size(), mScreen->format()); - windowId = winIdGenerator.fetchAndAddRelaxed(1); + + platformWindow = static_cast(window->platformWindow()); + platformWindow->surface = this; } QGraphicsSystemFbWindowSurface::~QGraphicsSystemFbWindowSurface() { - mScreen->removeWindowSurface(this); } + void QGraphicsSystemFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { Q_UNUSED(widget); Q_UNUSED(offset); + +// qDebug() << "QGraphicsSystemFbWindowSurface::flush" << region; + + + platformWindow->repaint(region); +} + + +void QFbWindow::repaint(const QRegion ®ion) +{ QRect currentGeometry = geometry(); // If this is a move, redraw the previous location if (oldGeometry != currentGeometry) { @@ -314,21 +349,30 @@ void QGraphicsSystemFbWindowSurface::flush(QWidget *widget, const QRegion ®io mScreen->setDirty(dirtyRegion); } -void QGraphicsSystemFbWindowSurface::setGeometry(const QRect &rect) +void QGraphicsSystemFbWindowSurface::resize(const QSize &size) { - // store previous geometry for screen update + // change the widget's QImage if this is a resize + if (mImage.size() != size) + mImage = QImage(size, mScreen->format()); + QWindowSurface::resize(size); +} + +void QFbWindow::setGeometry(const QRect &rect) +{ +// store previous geometry for screen update oldGeometry = geometry(); - // change the widget's QImage if this is a resize - if (mImage.size() != rect.size()) - mImage = QImage(rect.size(), mScreen->format()); mScreen->invalidateRectCache(); - QWindowSystemInterface::handleGeometryChange(window(), rect); +//### QWindowSystemInterface::handleGeometryChange(window(), rect); - QWindowSurface::setGeometry(rect); + QPlatformWindow::setGeometry(rect); } + + + + bool QGraphicsSystemFbWindowSurface::scroll(const QRegion &area, int dx, int dy) { return QWindowSurface::scroll(area, dx, dy); @@ -344,21 +388,21 @@ void QGraphicsSystemFbWindowSurface::endPaint(const QRegion ®ion) Q_UNUSED(region); } -void QGraphicsSystemFbWindowSurface::setVisible(bool visible) +void QFbWindow::setVisible(bool visible) { visibleFlag = visible; mScreen->invalidateRectCache(); mScreen->setDirty(geometry()); } -Qt::WindowFlags QGraphicsSystemFbWindowSurface::setWindowFlags(Qt::WindowFlags type) +Qt::WindowFlags QFbWindow::setWindowFlags(Qt::WindowFlags type) { flags = type; mScreen->invalidateRectCache(); return flags; } -Qt::WindowFlags QGraphicsSystemFbWindowSurface::windowFlags() const +Qt::WindowFlags QFbWindow::windowFlags() const { return flags; } diff --git a/src/plugins/platforms/fb_base/fb_base.h b/src/plugins/platforms/fb_base/fb_base.h index 7f9b005..8df6b8e 100644 --- a/src/plugins/platforms/fb_base/fb_base.h +++ b/src/plugins/platforms/fb_base/fb_base.h @@ -1,12 +1,14 @@ #ifndef QLIGHTHOUSEGRAPHICSSCREEN_H #define QLIGHTHOUSEGRAPHICSSCREEN_H -#include +//#include #include #include #include #include #include +#include +#include class QMouseEvent; class QSize; @@ -17,7 +19,7 @@ class QGraphicsSystemFbScreen; class QGraphicsSystemSoftwareCursor : public QGraphicsSystemCursor { public: - QGraphicsSystemSoftwareCursor(QGraphicsSystemScreen * scr); + QGraphicsSystemSoftwareCursor(QPlatformScreen * scr); // output methods QRect dirtyRect(); @@ -39,6 +41,9 @@ private: QRect getCurrentRect(); }; + +class QFbWindow; + class QGraphicsSystemFbWindowSurface : public QWindowSurface { public: @@ -51,30 +56,58 @@ public: virtual void beginPaint(const QRegion ®ion); virtual void endPaint(const QRegion ®ion); - virtual void setVisible(bool visible); - virtual bool visible() { return visibleFlag; } + const QImage image() { return mImage; } - void setGeometry(const QRect &rect); + void resize(const QSize &size); + +protected: + friend class QFbWindow; + QFbWindow *platformWindow; + + QGraphicsSystemFbScreen *mScreen; + QImage mImage; +}; + + +class QFbWindow : public QPlatformWindow +{ +public: + + QFbWindow(QGraphicsSystemFbScreen *screen, QWidget *window); + ~QFbWindow(); + + + virtual void setVisible(bool visible); + virtual bool visible() { return visibleFlag; } virtual void raise(); virtual void lower(); + void setGeometry(const QRect &rect); + virtual Qt::WindowFlags setWindowFlags(Qt::WindowFlags type); virtual Qt::WindowFlags windowFlags() const; WId winId() const { return windowId; } + + virtual void repaint(const QRegion&); + protected: + friend class QGraphicsSystemFbWindowSurface; + friend class QGraphicsSystemFbScreen; + QGraphicsSystemFbWindowSurface *surface; QGraphicsSystemFbScreen *mScreen; QRect oldGeometry; - QImage mImage; bool visibleFlag; Qt::WindowFlags flags; + WId windowId; }; -class QGraphicsSystemFbScreen : public QGraphicsSystemScreen + +class QGraphicsSystemFbScreen : public QPlatformScreen { Q_OBJECT public: @@ -93,18 +126,18 @@ public: virtual void setDirty(const QRect &rect); - virtual void removeWindowSurface(QGraphicsSystemFbWindowSurface * surface); - virtual void addWindowSurface(QGraphicsSystemFbWindowSurface * surface) { + virtual void removeWindow(QFbWindow * surface); + virtual void addWindow(QFbWindow * surface) { windowStack.prepend(surface); invalidateRectCache(); } - virtual void raise(QWindowSurface * surface); - virtual void lower(QWindowSurface * surface); + virtual void raise(QPlatformWindow * surface); + virtual void lower(QPlatformWindow * surface); virtual QWidget * topLevelAt(const QPoint & p) const; QImage * image() const { return mScreenImage; } QPaintDevice * paintDevice() const { return mScreenImage; } protected: - QList windowStack; + QList windowStack; QRegion repaintRegion; QGraphicsSystemSoftwareCursor * cursor; QTimer redrawTimer; @@ -126,6 +159,7 @@ private: void invalidateRectCache() { isUpToDate = false; } friend class QGraphicsSystemFbWindowSurface; + friend class QFbWindow; bool isUpToDate; }; diff --git a/src/plugins/platforms/testlite/qtestlitewindow.cpp b/src/plugins/platforms/testlite/qtestlitewindow.cpp index db3904f..0b215e3 100644 --- a/src/plugins/platforms/testlite/qtestlitewindow.cpp +++ b/src/plugins/platforms/testlite/qtestlitewindow.cpp @@ -622,6 +622,7 @@ void QTestLiteWindow::setGeometry(const QRect &rect) //if unchanged ### XMoveResizeWindow(xd->display, x_window, rect.x(), rect.y(), rect.width(), rect.height()); + QPlatformWindow::setGeometry(rect); } diff --git a/src/plugins/platforms/vnc/main.cpp b/src/plugins/platforms/vnc/main.cpp index f10748a..9de33eb 100644 --- a/src/plugins/platforms/vnc/main.cpp +++ b/src/plugins/platforms/vnc/main.cpp @@ -39,17 +39,17 @@ ** ****************************************************************************/ -#include #include "qgraphicssystem_vnc.h" #include +#include QT_BEGIN_NAMESPACE -class QVNCGraphicsSystemPlugin : public QGraphicsSystemPlugin +class QVNCGraphicsSystemPlugin : public QPlatformIntegrationPlugin { public: QStringList keys() const; - QGraphicsSystem *create(const QString&); + QPlatformIntegration *create(const QString&); }; QStringList QVNCGraphicsSystemPlugin::keys() const @@ -59,7 +59,7 @@ QStringList QVNCGraphicsSystemPlugin::keys() const return list; } -QGraphicsSystem* QVNCGraphicsSystemPlugin::create(const QString& system) +QPlatformIntegration* QVNCGraphicsSystemPlugin::create(const QString& system) { if (system.toLower() == "vnc") return new QVNCGraphicsSystem; diff --git a/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp b/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp index 7815f24..ef50230 100644 --- a/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp +++ b/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp @@ -104,12 +104,30 @@ QPixmapData *QVNCGraphicsSystem::createPixmapData(QPixmapData::PixelType type) c return new QRasterPixmapData(type); } -QWindowSurface *QVNCGraphicsSystem::createWindowSurface(QWidget *widget) const +// QWindowSurface *QVNCGraphicsSystem::createWindowSurface(QWidget *widget) const +// { +// if (widget->windowType() == Qt::Desktop) +// return 0; // Don't create an explicit window surface for the destkop. +// QGraphicsSystemFbWindowSurface * surface; +// surface = new QGraphicsSystemFbWindowSurface(mPrimaryScreen, widget); +// mPrimaryScreen->addWindowSurface(surface); +// return surface; +// } + +QWindowSurface *QVNCGraphicsSystem::createWindowSurfaceForWindow(QWidget *widget, WId) const { if (widget->windowType() == Qt::Desktop) return 0; // Don't create an explicit window surface for the destkop. QGraphicsSystemFbWindowSurface * surface; surface = new QGraphicsSystemFbWindowSurface(mPrimaryScreen, widget); - mPrimaryScreen->addWindowSurface(surface); return surface; } + + +QPlatformWindow *QVNCGraphicsSystem::createPlatformWindow(QWidget *widget, WId /*winId*/) const +{ + QFbWindow *w = new QFbWindow(mPrimaryScreen, widget); + mPrimaryScreen->addWindow(w); + return w; +} + diff --git a/src/plugins/platforms/vnc/qgraphicssystem_vnc.h b/src/plugins/platforms/vnc/qgraphicssystem_vnc.h index b3349b7..3205872 100644 --- a/src/plugins/platforms/vnc/qgraphicssystem_vnc.h +++ b/src/plugins/platforms/vnc/qgraphicssystem_vnc.h @@ -42,9 +42,9 @@ #ifndef QGRAPHICSSYSTEM_VNC_H #define QGRAPHICSSYSTEM_VNC_H -#include #include "qvnccursor.h" #include "../fb_base/fb_base.h" +#include QT_BEGIN_NAMESPACE @@ -73,20 +73,21 @@ private: class QVNCGraphicsSystemPrivate; -class QVNCGraphicsSystem : public QGraphicsSystem +class QVNCGraphicsSystem : public QPlatformIntegration { public: QVNCGraphicsSystem(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; - QList screens() const { return mScreens; } + QList screens() const { return mScreens; } private: QVNCGraphicsSystemScreen *mPrimaryScreen; - QList mScreens; + QList mScreens; }; diff --git a/src/plugins/platforms/vnc/vnc.pro b/src/plugins/platforms/vnc/vnc.pro index 0b73b5b..b1da572 100644 --- a/src/plugins/platforms/vnc/vnc.pro +++ b/src/plugins/platforms/vnc/vnc.pro @@ -1,7 +1,7 @@ TARGET = qvncgraphicssystem include(../../qpluginbase.pri) -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/graphicssystems +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms SOURCES = main.cpp qgraphicssystem_vnc.cpp HEADERS = qgraphicssystem_vnc.h @@ -14,6 +14,6 @@ SOURCES += qvnccursor.cpp include(../fb_base/fb_base.pri) -target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems +target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target -- cgit v0.12 From a87d8966946c47e234b8d5268c287ac96f1ea4c4 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Mon, 12 Apr 2010 15:44:57 +0200 Subject: Make hide() work. --- src/plugins/platforms/fb_base/fb_base.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/platforms/fb_base/fb_base.cpp b/src/plugins/platforms/fb_base/fb_base.cpp index 422222c..25426eb 100644 --- a/src/plugins/platforms/fb_base/fb_base.cpp +++ b/src/plugins/platforms/fb_base/fb_base.cpp @@ -142,6 +142,9 @@ void QGraphicsSystemFbScreen::generateRects() for (int i = 0; i < windowStack.length(); i++) { if (remainingScreen.isEmpty()) break; + if (!windowStack[i]->visible()) + continue; + if (!windowStack[i]->widget()->testAttribute(Qt::WA_TranslucentBackground)) { remainingScreen -= windowStack[i]->geometry(); QRegion windowRegion(windowStack[i]->geometry()); -- cgit v0.12 From 3a8b3299d7c956e3a9f4733bc7d459757081bdc2 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Mon, 12 Apr 2010 16:55:56 +0200 Subject: Make LinuxFb work --- src/gui/kernel/qapplication_lite.cpp | 11 +++++++++++ src/plugins/platforms/linuxfb/linuxfb.pro | 4 ++-- src/plugins/platforms/linuxfb/main.cpp | 8 ++++---- .../platforms/linuxfb/qgraphicssystem_linuxfb.cpp | 16 ++++++++++++++-- src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h | 11 ++++++----- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qapplication_lite.cpp b/src/gui/kernel/qapplication_lite.cpp index 87fa933..867c2dc 100644 --- a/src/gui/kernel/qapplication_lite.cpp +++ b/src/gui/kernel/qapplication_lite.cpp @@ -422,6 +422,15 @@ static void init_platform(const QString &name) } + +static void cleanup_platform() +{ + delete QApplicationPrivate::platform_integration; + QApplicationPrivate::platform_integration = 0; + delete QApplicationPrivate::graphics_system; + QApplicationPrivate::graphics_system = 0; +} + static void init_plugins(const QList pluginList) { for (int i = 0; i < pluginList.count(); ++i) { @@ -520,6 +529,8 @@ void qt_init(QApplicationPrivate *priv, int type) void qt_cleanup() { + cleanup_platform(); + QPixmapCache::clear(); #ifndef QT_NO_CURSOR QCursorData::cleanup(); diff --git a/src/plugins/platforms/linuxfb/linuxfb.pro b/src/plugins/platforms/linuxfb/linuxfb.pro index 031b843..2633a10 100644 --- a/src/plugins/platforms/linuxfb/linuxfb.pro +++ b/src/plugins/platforms/linuxfb/linuxfb.pro @@ -1,12 +1,12 @@ TARGET = qlinuxfbgraphicssystem include(../../qpluginbase.pri) -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/graphicssystems +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms SOURCES = main.cpp qgraphicssystem_linuxfb.cpp HEADERS = qgraphicssystem_linuxfb.h include(../fb_base/fb_base.pri) -target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems +target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target diff --git a/src/plugins/platforms/linuxfb/main.cpp b/src/plugins/platforms/linuxfb/main.cpp index 4d03fe5..15305ed 100644 --- a/src/plugins/platforms/linuxfb/main.cpp +++ b/src/plugins/platforms/linuxfb/main.cpp @@ -39,16 +39,16 @@ ** ****************************************************************************/ -#include +#include #include "qgraphicssystem_linuxfb.h" QT_BEGIN_NAMESPACE -class QLinuxFbGraphicsSystemPlugin : public QGraphicsSystemPlugin +class QLinuxFbGraphicsSystemPlugin : public QPlatformIntegrationPlugin { public: QStringList keys() const; - QGraphicsSystem *create(const QString&); + QPlatformIntegration *create(const QString&); }; QStringList QLinuxFbGraphicsSystemPlugin::keys() const @@ -58,7 +58,7 @@ QStringList QLinuxFbGraphicsSystemPlugin::keys() const return list; } -QGraphicsSystem* QLinuxFbGraphicsSystemPlugin::create(const QString& system) +QPlatformIntegration* QLinuxFbGraphicsSystemPlugin::create(const QString& system) { if (system.toLower() == "linuxfb") return new QLinuxFbGraphicsSystem; diff --git a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp index 44960bb..cca567c 100644 --- a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp +++ b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp @@ -786,16 +786,28 @@ QPixmapData *QLinuxFbGraphicsSystem::createPixmapData(QPixmapData::PixelType typ return new QRasterPixmapData(type); } -QWindowSurface *QLinuxFbGraphicsSystem::createWindowSurface(QWidget *widget) const +QWindowSurface *QLinuxFbGraphicsSystem::createWindowSurfaceForWindow(QWidget *widget, WId) const { if (widget->windowType() == Qt::Desktop) return 0; // Don't create an explicit window surface for the destkop. QGraphicsSystemFbWindowSurface * surface = new QGraphicsSystemFbWindowSurface(mPrimaryScreen, widget); - mPrimaryScreen->addWindowSurface(surface); return surface; } + + +QPlatformWindow *QLinuxFbGraphicsSystem::createPlatformWindow(QWidget *widget, WId /*winId*/) const +{ + QFbWindow *w = new QFbWindow(mPrimaryScreen, widget); + mPrimaryScreen->addWindow(w); + return w; +} + + + + + QLinuxFbGraphicsSystemScreen::QLinuxFbGraphicsSystemScreen(uchar * d, int w, int h, int lstep, QImage::Format screenFormat) : compositePainter(0) { diff --git a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h index cc8ce7e..873b463 100644 --- a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h +++ b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h @@ -42,7 +42,7 @@ #ifndef QGRAPHICSSYSTEM_LINUXFB_H #define QGRAPHICSSYSTEM_LINUXFB_H -#include +#include #include "../fb_base/fb_base.h" QT_BEGIN_NAMESPACE @@ -70,20 +70,21 @@ struct fb_cmap; struct fb_var_screeninfo; struct fb_fix_screeninfo; -class QLinuxFbGraphicsSystem : public QGraphicsSystem +class QLinuxFbGraphicsSystem : public QPlatformIntegration { public: QLinuxFbGraphicsSystem(); ~QLinuxFbGraphicsSystem(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId WinId) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId WinId) const; - QList screens() const { return mScreens; } + QList screens() const { return mScreens; } private: QLinuxFbGraphicsSystemScreen *mPrimaryScreen; - QList mScreens; + QList mScreens; QLinuxFbGraphicsSystemPrivate *d_ptr; enum PixelType { NormalPixel, BGRPixel }; -- cgit v0.12 From c8f86b525a6eabb91ad4da2dfdd423a32263359a Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 13 Apr 2010 10:57:50 +0200 Subject: Rename classes to get rid of "GraphicsSystem" --- src/plugins/platforms/fb_base/fb_base.cpp | 48 ++++++++-------- src/plugins/platforms/fb_base/fb_base.h | 28 +++++----- src/plugins/platforms/linuxfb/main.cpp | 10 ++-- .../platforms/linuxfb/qgraphicssystem_linuxfb.cpp | 64 +++++++++++----------- .../platforms/linuxfb/qgraphicssystem_linuxfb.h | 16 +++--- src/plugins/platforms/vnc/main.cpp | 10 ++-- src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp | 32 +++++------ src/plugins/platforms/vnc/qgraphicssystem_vnc.h | 16 +++--- src/plugins/platforms/vnc/qvnccursor.cpp | 2 +- src/plugins/platforms/vnc/qvnccursor.h | 4 +- src/plugins/platforms/vnc/qvncserver.cpp | 16 +++--- src/plugins/platforms/vnc/qvncserver.h | 26 ++++----- 12 files changed, 136 insertions(+), 136 deletions(-) diff --git a/src/plugins/platforms/fb_base/fb_base.cpp b/src/plugins/platforms/fb_base/fb_base.cpp index 25426eb..1a6d04e 100644 --- a/src/plugins/platforms/fb_base/fb_base.cpp +++ b/src/plugins/platforms/fb_base/fb_base.cpp @@ -81,7 +81,7 @@ void QGraphicsSystemSoftwareCursor::changeCursor(QCursor * widgetCursor, QWidget screen->setDirty(currentRect); } -QGraphicsSystemFbScreen::QGraphicsSystemFbScreen() : cursor(0), mGeometry(), mDepth(16), mFormat(QImage::Format_RGB16), mScreenImage(0), compositePainter(0), isUpToDate(false) +QFbScreen::QFbScreen() : cursor(0), mGeometry(), mDepth(16), mFormat(QImage::Format_RGB16), mScreenImage(0), compositePainter(0), isUpToDate(false) { mScreenImage = new QImage(mGeometry.size(), mFormat); redrawTimer.setSingleShot(true); @@ -89,7 +89,7 @@ QGraphicsSystemFbScreen::QGraphicsSystemFbScreen() : cursor(0), mGeometry(), mDe QObject::connect(&redrawTimer, SIGNAL(timeout()), this, SLOT(doRedraw())); } -void QGraphicsSystemFbScreen::setGeometry(QRect rect) +void QFbScreen::setGeometry(QRect rect) { delete mScreenImage; mGeometry = rect; @@ -99,17 +99,17 @@ void QGraphicsSystemFbScreen::setGeometry(QRect rect) invalidateRectCache(); } -void QGraphicsSystemFbScreen::setDepth(int depth) +void QFbScreen::setDepth(int depth) { mDepth = depth; } -void QGraphicsSystemFbScreen::setPhysicalSize(QSize size) +void QFbScreen::setPhysicalSize(QSize size) { mPhysicalSize = size; } -void QGraphicsSystemFbScreen::setFormat(QImage::Format format) +void QFbScreen::setFormat(QImage::Format format) { mFormat = format; delete mScreenImage; @@ -118,23 +118,23 @@ void QGraphicsSystemFbScreen::setFormat(QImage::Format format) compositePainter = 0; } -QGraphicsSystemFbScreen::~QGraphicsSystemFbScreen() +QFbScreen::~QFbScreen() { delete compositePainter; delete mScreenImage; } -void QGraphicsSystemFbScreen::setDirty(const QRect &rect) +void QFbScreen::setDirty(const QRect &rect) { -// qDebug() << "QGraphicsSystemFbScreen::setDirty" << rect; +// qDebug() << "QFbScreen::setDirty" << rect; repaintRegion += rect; if (!redrawTimer.isActive()) { redrawTimer.start(); } } -void QGraphicsSystemFbScreen::generateRects() +void QFbScreen::generateRects() { cachedRects.clear(); QRegion remainingScreen(mGeometry); @@ -162,7 +162,7 @@ void QGraphicsSystemFbScreen::generateRects() -QRegion QGraphicsSystemFbScreen::doRedraw() +QRegion QFbScreen::doRedraw() { QRegion touchedRegion; if (cursor) @@ -232,13 +232,13 @@ QRegion QGraphicsSystemFbScreen::doRedraw() -// qDebug() << "QGraphicsSystemFbScreen::doRedraw" << windowStack.size() << mScreenImage->size() << touchedRegion; +// qDebug() << "QFbScreen::doRedraw" << windowStack.size() << mScreenImage->size() << touchedRegion; return touchedRegion; } -void QGraphicsSystemFbScreen::removeWindow(QFbWindow * surface) +void QFbScreen::removeWindow(QFbWindow * surface) { windowStack.removeOne(surface); invalidateRectCache(); @@ -250,7 +250,7 @@ void QFbWindow::raise() mScreen->raise(this); } -void QGraphicsSystemFbScreen::raise(QPlatformWindow * surface) +void QFbScreen::raise(QPlatformWindow * surface) { QFbWindow *s = static_cast(surface); int index = windowStack.indexOf(s); @@ -266,7 +266,7 @@ void QFbWindow::lower() mScreen->lower(this); } -void QGraphicsSystemFbScreen::lower(QPlatformWindow * surface) +void QFbScreen::lower(QPlatformWindow * surface) { QFbWindow *s = static_cast(surface); int index = windowStack.indexOf(s); @@ -277,7 +277,7 @@ void QGraphicsSystemFbScreen::lower(QPlatformWindow * surface) setDirty(s->geometry()); } -QWidget * QGraphicsSystemFbScreen::topLevelAt(const QPoint & p) const +QWidget * QFbScreen::topLevelAt(const QPoint & p) const { for(int i = 0; i < windowStack.size(); i++) { if (windowStack[i]->geometry().contains(p, false) && @@ -291,7 +291,7 @@ QWidget * QGraphicsSystemFbScreen::topLevelAt(const QPoint & p) const -QFbWindow::QFbWindow(QGraphicsSystemFbScreen *screen, QWidget *window) +QFbWindow::QFbWindow(QFbScreen *screen, QWidget *window) :QPlatformWindow(window), mScreen(screen), visibleFlag(false) @@ -307,7 +307,7 @@ QFbWindow::~QFbWindow() } -QGraphicsSystemFbWindowSurface::QGraphicsSystemFbWindowSurface(QGraphicsSystemFbScreen *screen, QWidget *window) +QFbWindowSurface::QFbWindowSurface(QFbScreen *screen, QWidget *window) : QWindowSurface(window), mScreen(screen) { @@ -317,18 +317,18 @@ QGraphicsSystemFbWindowSurface::QGraphicsSystemFbWindowSurface(QGraphicsSystemFb platformWindow->surface = this; } -QGraphicsSystemFbWindowSurface::~QGraphicsSystemFbWindowSurface() +QFbWindowSurface::~QFbWindowSurface() { } -void QGraphicsSystemFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) +void QFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { Q_UNUSED(widget); Q_UNUSED(offset); -// qDebug() << "QGraphicsSystemFbWindowSurface::flush" << region; +// qDebug() << "QFbWindowSurface::flush" << region; platformWindow->repaint(region); @@ -352,7 +352,7 @@ void QFbWindow::repaint(const QRegion ®ion) mScreen->setDirty(dirtyRegion); } -void QGraphicsSystemFbWindowSurface::resize(const QSize &size) +void QFbWindowSurface::resize(const QSize &size) { // change the widget's QImage if this is a resize if (mImage.size() != size) @@ -376,17 +376,17 @@ void QFbWindow::setGeometry(const QRect &rect) -bool QGraphicsSystemFbWindowSurface::scroll(const QRegion &area, int dx, int dy) +bool QFbWindowSurface::scroll(const QRegion &area, int dx, int dy) { return QWindowSurface::scroll(area, dx, dy); } -void QGraphicsSystemFbWindowSurface::beginPaint(const QRegion ®ion) +void QFbWindowSurface::beginPaint(const QRegion ®ion) { Q_UNUSED(region); } -void QGraphicsSystemFbWindowSurface::endPaint(const QRegion ®ion) +void QFbWindowSurface::endPaint(const QRegion ®ion) { Q_UNUSED(region); } diff --git a/src/plugins/platforms/fb_base/fb_base.h b/src/plugins/platforms/fb_base/fb_base.h index 8df6b8e..2738768 100644 --- a/src/plugins/platforms/fb_base/fb_base.h +++ b/src/plugins/platforms/fb_base/fb_base.h @@ -14,7 +14,7 @@ class QMouseEvent; class QSize; class QPainter; -class QGraphicsSystemFbScreen; +class QFbScreen; class QGraphicsSystemSoftwareCursor : public QGraphicsSystemCursor { @@ -44,11 +44,11 @@ private: class QFbWindow; -class QGraphicsSystemFbWindowSurface : public QWindowSurface +class QFbWindowSurface : public QWindowSurface { public: - QGraphicsSystemFbWindowSurface(QGraphicsSystemFbScreen *screen, QWidget *window); - ~QGraphicsSystemFbWindowSurface(); + QFbWindowSurface(QFbScreen *screen, QWidget *window); + ~QFbWindowSurface(); virtual QPaintDevice *paintDevice() { return &mImage; } virtual void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); @@ -65,7 +65,7 @@ protected: friend class QFbWindow; QFbWindow *platformWindow; - QGraphicsSystemFbScreen *mScreen; + QFbScreen *mScreen; QImage mImage; }; @@ -74,7 +74,7 @@ class QFbWindow : public QPlatformWindow { public: - QFbWindow(QGraphicsSystemFbScreen *screen, QWidget *window); + QFbWindow(QFbScreen *screen, QWidget *window); ~QFbWindow(); @@ -94,10 +94,10 @@ public: virtual void repaint(const QRegion&); protected: - friend class QGraphicsSystemFbWindowSurface; - friend class QGraphicsSystemFbScreen; - QGraphicsSystemFbWindowSurface *surface; - QGraphicsSystemFbScreen *mScreen; + friend class QFbWindowSurface; + friend class QFbScreen; + QFbWindowSurface *surface; + QFbScreen *mScreen; QRect oldGeometry; bool visibleFlag; Qt::WindowFlags flags; @@ -107,12 +107,12 @@ protected: }; -class QGraphicsSystemFbScreen : public QPlatformScreen +class QFbScreen : public QPlatformScreen { Q_OBJECT public: - QGraphicsSystemFbScreen(); - ~QGraphicsSystemFbScreen(); + QFbScreen(); + ~QFbScreen(); virtual QRect geometry() const { return mGeometry; } virtual int depth() const { return mDepth; } @@ -158,7 +158,7 @@ private: QList > cachedRects; void invalidateRectCache() { isUpToDate = false; } - friend class QGraphicsSystemFbWindowSurface; + friend class QFbWindowSurface; friend class QFbWindow; bool isUpToDate; }; diff --git a/src/plugins/platforms/linuxfb/main.cpp b/src/plugins/platforms/linuxfb/main.cpp index 15305ed..1ee24b6 100644 --- a/src/plugins/platforms/linuxfb/main.cpp +++ b/src/plugins/platforms/linuxfb/main.cpp @@ -44,28 +44,28 @@ QT_BEGIN_NAMESPACE -class QLinuxFbGraphicsSystemPlugin : public QPlatformIntegrationPlugin +class QLinuxFbIntegrationPlugin : public QPlatformIntegrationPlugin { public: QStringList keys() const; QPlatformIntegration *create(const QString&); }; -QStringList QLinuxFbGraphicsSystemPlugin::keys() const +QStringList QLinuxFbIntegrationPlugin::keys() const { QStringList list; list << "LinuxFb"; return list; } -QPlatformIntegration* QLinuxFbGraphicsSystemPlugin::create(const QString& system) +QPlatformIntegration* QLinuxFbIntegrationPlugin::create(const QString& system) { if (system.toLower() == "linuxfb") - return new QLinuxFbGraphicsSystem; + return new QLinuxFbIntegration; return 0; } -Q_EXPORT_PLUGIN2(linuxfb, QLinuxFbGraphicsSystemPlugin) +Q_EXPORT_PLUGIN2(linuxfb, QLinuxFbIntegrationPlugin) QT_END_NAMESPACE diff --git a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp index cca567c..25cdc7b 100644 --- a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp +++ b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp @@ -69,11 +69,11 @@ QT_BEGIN_NAMESPACE -class QLinuxFbGraphicsSystemPrivate +class QLinuxFbIntegrationPrivate { public: - QLinuxFbGraphicsSystemPrivate(); - ~QLinuxFbGraphicsSystemPrivate(); + QLinuxFbIntegrationPrivate(); + ~QLinuxFbIntegrationPrivate(); void openTty(); void closeTty(); @@ -94,7 +94,7 @@ public: QString displaySpec; }; -QLinuxFbGraphicsSystemPrivate::QLinuxFbGraphicsSystemPrivate() +QLinuxFbIntegrationPrivate::QLinuxFbIntegrationPrivate() : fd(-1), blank(true), doGraphicsMode(true), #ifdef QT_QWS_DEPTH_GENERIC doGenericColors(false), @@ -103,12 +103,12 @@ QLinuxFbGraphicsSystemPrivate::QLinuxFbGraphicsSystemPrivate() { } -QLinuxFbGraphicsSystemPrivate::~QLinuxFbGraphicsSystemPrivate() +QLinuxFbIntegrationPrivate::~QLinuxFbIntegrationPrivate() { closeTty(); } -void QLinuxFbGraphicsSystemPrivate::openTty() +void QLinuxFbIntegrationPrivate::openTty() { const char *const devs[] = {"/dev/tty0", "/dev/tty", "/dev/console", 0}; @@ -139,7 +139,7 @@ void QLinuxFbGraphicsSystemPrivate::openTty() QT_WRITE(ttyfd, termctl, sizeof(termctl)); } -void QLinuxFbGraphicsSystemPrivate::closeTty() +void QLinuxFbIntegrationPrivate::closeTty() { if (ttyfd == -1) return; @@ -155,33 +155,33 @@ void QLinuxFbGraphicsSystemPrivate::closeTty() ttyfd = -1; } -QLinuxFbGraphicsSystem::QLinuxFbGraphicsSystem() +QLinuxFbIntegration::QLinuxFbIntegration() { - d_ptr = new QLinuxFbGraphicsSystemPrivate(); + d_ptr = new QLinuxFbIntegrationPrivate(); // XXX QString displaySpec = QString::fromLatin1(qgetenv("QWS_DISPLAY")); if (!connect(displaySpec)) - qFatal("QLinuxFbGraphicsSystem: could not initialize screen"); + qFatal("QLinuxFbIntegration: could not initialize screen"); initDevice(); // Create a QImage directly on the screen's framebuffer. // This is the blit target for copying windows to the screen. - mPrimaryScreen = new QLinuxFbGraphicsSystemScreen(data, w, h, lstep, + mPrimaryScreen = new QLinuxFbScreen(data, w, h, lstep, screenFormat); mPrimaryScreen->setPhysicalSize(QSize(physWidth, physHeight)); mScreens.append(mPrimaryScreen); } -QLinuxFbGraphicsSystem::~QLinuxFbGraphicsSystem() +QLinuxFbIntegration::~QLinuxFbIntegration() { delete mPrimaryScreen; delete d_ptr; } -bool QLinuxFbGraphicsSystem::connect(const QString &displaySpec) +bool QLinuxFbIntegration::connect(const QString &displaySpec) { const QStringList args = displaySpec.split(QLatin1Char(':')); @@ -237,7 +237,7 @@ bool QLinuxFbGraphicsSystem::connect(const QString &displaySpec) /* Get fixed screen information */ if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_FSCREENINFO, &finfo)) { - perror("QLinuxFbGraphicsSystem::connect"); + perror("QLinuxFbIntegration::connect"); qWarning("Error reading fixed information"); return false; } @@ -249,7 +249,7 @@ bool QLinuxFbGraphicsSystem::connect(const QString &displaySpec) /* Get variable screen information */ if (d_ptr->fd != -1 && ioctl(d_ptr->fd, FBIOGET_VSCREENINFO, &vinfo)) { - perror("QLinuxFbGraphicsSystem::connect"); + perror("QLinuxFbIntegration::connect"); qWarning("Error reading variable information"); return false; } @@ -295,7 +295,7 @@ bool QLinuxFbGraphicsSystem::connect(const QString &displaySpec) } if (w == 0 || h == 0) { - qWarning("QLinuxFbGraphicsSystem::connect(): Unable to find screen geometry, " + qWarning("QLinuxFbIntegration::connect(): Unable to find screen geometry, " "will use 320x240."); dw = w = 320; dh = h = 240; @@ -347,7 +347,7 @@ bool QLinuxFbGraphicsSystem::connect(const QString &displaySpec) MAP_SHARED, d_ptr->fd, 0); if ((long)data == -1) { - perror("QLinuxFbGraphicsSystem::connect"); + perror("QLinuxFbIntegration::connect"); qWarning("Error: failed to map framebuffer device to memory."); return false; } else { @@ -377,7 +377,7 @@ bool QLinuxFbGraphicsSystem::connect(const QString &displaySpec) startcmap.transp=(unsigned short int *) malloc(sizeof(unsigned short int)*screencols); if (d_ptr->fd == -1 || ioctl(d_ptr->fd, FBIOGETCMAP, &startcmap)) { - perror("QLinuxFbGraphicsSystem::connect"); + perror("QLinuxFbIntegration::connect"); qWarning("Error reading palette from framebuffer, using default palette"); createPalette(startcmap, vinfo, finfo); } @@ -411,7 +411,7 @@ bool QLinuxFbGraphicsSystem::connect(const QString &displaySpec) return true; } -bool QLinuxFbGraphicsSystem::initDevice() +bool QLinuxFbIntegration::initDevice() { d_ptr->openTty(); @@ -538,7 +538,7 @@ bool QLinuxFbGraphicsSystem::initDevice() return true; } -void QLinuxFbGraphicsSystem::setPixelFormat(struct fb_var_screeninfo info) +void QLinuxFbIntegration::setPixelFormat(struct fb_var_screeninfo info) { const fb_bitfield rgba[4] = { info.red, info.green, info.blue, info.transp }; @@ -626,7 +626,7 @@ void QLinuxFbGraphicsSystem::setPixelFormat(struct fb_var_screeninfo info) screenFormat = format; } -void QLinuxFbGraphicsSystem::createPalette(fb_cmap &cmap, fb_var_screeninfo &vinfo, fb_fix_screeninfo &finfo) +void QLinuxFbIntegration::createPalette(fb_cmap &cmap, fb_var_screeninfo &vinfo, fb_fix_screeninfo &finfo) { if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) { screencols= (vinfo.bits_per_pixel==8) ? 256 : 16; @@ -756,7 +756,7 @@ void QLinuxFbGraphicsSystem::createPalette(fb_cmap &cmap, fb_var_screeninfo &vin } } -void QLinuxFbGraphicsSystem::blank(bool on) +void QLinuxFbIntegration::blank(bool on) { if (d_ptr->blank == on) return; @@ -781,23 +781,23 @@ void QLinuxFbGraphicsSystem::blank(bool on) d_ptr->blank = on; } -QPixmapData *QLinuxFbGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const +QPixmapData *QLinuxFbIntegration::createPixmapData(QPixmapData::PixelType type) const { return new QRasterPixmapData(type); } -QWindowSurface *QLinuxFbGraphicsSystem::createWindowSurfaceForWindow(QWidget *widget, WId) const +QWindowSurface *QLinuxFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const { if (widget->windowType() == Qt::Desktop) return 0; // Don't create an explicit window surface for the destkop. - QGraphicsSystemFbWindowSurface * surface = - new QGraphicsSystemFbWindowSurface(mPrimaryScreen, widget); + QFbWindowSurface * surface = + new QFbWindowSurface(mPrimaryScreen, widget); return surface; } -QPlatformWindow *QLinuxFbGraphicsSystem::createPlatformWindow(QWidget *widget, WId /*winId*/) const +QPlatformWindow *QLinuxFbIntegration::createPlatformWindow(QWidget *widget, WId /*winId*/) const { QFbWindow *w = new QFbWindow(mPrimaryScreen, widget); mPrimaryScreen->addWindow(w); @@ -808,7 +808,7 @@ QPlatformWindow *QLinuxFbGraphicsSystem::createPlatformWindow(QWidget *widget, W -QLinuxFbGraphicsSystemScreen::QLinuxFbGraphicsSystemScreen(uchar * d, int w, +QLinuxFbScreen::QLinuxFbScreen(uchar * d, int w, int h, int lstep, QImage::Format screenFormat) : compositePainter(0) { data = d; @@ -823,7 +823,7 @@ QLinuxFbGraphicsSystemScreen::QLinuxFbGraphicsSystemScreen(uchar * d, int w, cursor = new QGraphicsSystemSoftwareCursor(this); } -void QLinuxFbGraphicsSystemScreen::setGeometry(QRect rect) +void QLinuxFbScreen::setGeometry(QRect rect) { mGeometry = rect; delete mFbScreenImage; @@ -837,7 +837,7 @@ void QLinuxFbGraphicsSystemScreen::setGeometry(QRect rect) mFormat); } -void QLinuxFbGraphicsSystemScreen::setFormat(QImage::Format format) +void QLinuxFbScreen::setFormat(QImage::Format format) { mFormat = format; delete mFbScreenImage; @@ -851,10 +851,10 @@ void QLinuxFbGraphicsSystemScreen::setFormat(QImage::Format format) mFormat); } -QRegion QLinuxFbGraphicsSystemScreen::doRedraw() +QRegion QLinuxFbScreen::doRedraw() { QRegion touched; - touched = QGraphicsSystemFbScreen::doRedraw(); + touched = QFbScreen::doRedraw(); if (!compositePainter) { compositePainter = new QPainter(mFbScreenImage); diff --git a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h index 873b463..7d4c031 100644 --- a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h +++ b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h @@ -47,10 +47,10 @@ QT_BEGIN_NAMESPACE -class QLinuxFbGraphicsSystemScreen : public QGraphicsSystemFbScreen +class QLinuxFbScreen : public QFbScreen { public: - QLinuxFbGraphicsSystemScreen(uchar * d, int w, int h, int lstep, QImage::Format screenFormat); + QLinuxFbScreen(uchar * d, int w, int h, int lstep, QImage::Format screenFormat); void setGeometry(QRect rect); void setFormat(QImage::Format format); @@ -65,16 +65,16 @@ private: QPainter *compositePainter; }; -class QLinuxFbGraphicsSystemPrivate; +class QLinuxFbIntegrationPrivate; struct fb_cmap; struct fb_var_screeninfo; struct fb_fix_screeninfo; -class QLinuxFbGraphicsSystem : public QPlatformIntegration +class QLinuxFbIntegration : public QPlatformIntegration { public: - QLinuxFbGraphicsSystem(); - ~QLinuxFbGraphicsSystem(); + QLinuxFbIntegration(); + ~QLinuxFbIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId WinId) const; @@ -83,9 +83,9 @@ public: QList screens() const { return mScreens; } private: - QLinuxFbGraphicsSystemScreen *mPrimaryScreen; + QLinuxFbScreen *mPrimaryScreen; QList mScreens; - QLinuxFbGraphicsSystemPrivate *d_ptr; + QLinuxFbIntegrationPrivate *d_ptr; enum PixelType { NormalPixel, BGRPixel }; diff --git a/src/plugins/platforms/vnc/main.cpp b/src/plugins/platforms/vnc/main.cpp index 9de33eb..23d78c1 100644 --- a/src/plugins/platforms/vnc/main.cpp +++ b/src/plugins/platforms/vnc/main.cpp @@ -45,28 +45,28 @@ QT_BEGIN_NAMESPACE -class QVNCGraphicsSystemPlugin : public QPlatformIntegrationPlugin +class QVNCIntegrationPlugin : public QPlatformIntegrationPlugin { public: QStringList keys() const; QPlatformIntegration *create(const QString&); }; -QStringList QVNCGraphicsSystemPlugin::keys() const +QStringList QVNCIntegrationPlugin::keys() const { QStringList list; list << "VNC"; return list; } -QPlatformIntegration* QVNCGraphicsSystemPlugin::create(const QString& system) +QPlatformIntegration* QVNCIntegrationPlugin::create(const QString& system) { if (system.toLower() == "vnc") - return new QVNCGraphicsSystem; + return new QVNCIntegration; return 0; } -Q_EXPORT_PLUGIN2(vnc, QVNCGraphicsSystemPlugin) +Q_EXPORT_PLUGIN2(vnc, QVNCIntegrationPlugin) QT_END_NAMESPACE diff --git a/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp b/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp index ef50230..cbc8bbd 100644 --- a/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp +++ b/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp @@ -51,8 +51,8 @@ #include -QVNCGraphicsSystemScreen::QVNCGraphicsSystemScreen() - : QGraphicsSystemFbScreen::QGraphicsSystemFbScreen() +QVNCScreen::QVNCScreen() + : QFbScreen::QFbScreen() { int w = 800; int h = 600; @@ -69,21 +69,21 @@ QVNCGraphicsSystemScreen::QVNCGraphicsSystemScreen() setPhysicalSize((geometry().size()*254)/720); - d_ptr = new QVNCGraphicsSystemScreenPrivate(this); + d_ptr = new QVNCScreenPrivate(this); cursor = new QVNCCursor(d_ptr->vncServer, this); d_ptr->vncServer->setCursor(static_cast(cursor)); } -QVNCDirtyMap *QVNCGraphicsSystemScreen::dirtyMap() +QVNCDirtyMap *QVNCScreen::dirtyMap() { return d_ptr->dirty; } -QRegion QVNCGraphicsSystemScreen::doRedraw() +QRegion QVNCScreen::doRedraw() { QRegion touched; - touched = QGraphicsSystemFbScreen::doRedraw(); + touched = QFbScreen::doRedraw(); QVector rects = touched.rects(); for (int i = 0; i < rects.size(); i++) @@ -92,39 +92,39 @@ QRegion QVNCGraphicsSystemScreen::doRedraw() } -QVNCGraphicsSystem::QVNCGraphicsSystem() +QVNCIntegration::QVNCIntegration() { - mPrimaryScreen = new QVNCGraphicsSystemScreen(); + mPrimaryScreen = new QVNCScreen(); mScreens.append(mPrimaryScreen); } -QPixmapData *QVNCGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const +QPixmapData *QVNCIntegration::createPixmapData(QPixmapData::PixelType type) const { return new QRasterPixmapData(type); } -// QWindowSurface *QVNCGraphicsSystem::createWindowSurface(QWidget *widget) const +// QWindowSurface *QVNCIntegration::createWindowSurface(QWidget *widget) const // { // if (widget->windowType() == Qt::Desktop) // return 0; // Don't create an explicit window surface for the destkop. -// QGraphicsSystemFbWindowSurface * surface; -// surface = new QGraphicsSystemFbWindowSurface(mPrimaryScreen, widget); +// QFbWindowSurface * surface; +// surface = new QFbWindowSurface(mPrimaryScreen, widget); // mPrimaryScreen->addWindowSurface(surface); // return surface; // } -QWindowSurface *QVNCGraphicsSystem::createWindowSurfaceForWindow(QWidget *widget, WId) const +QWindowSurface *QVNCIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const { if (widget->windowType() == Qt::Desktop) return 0; // Don't create an explicit window surface for the destkop. - QGraphicsSystemFbWindowSurface * surface; - surface = new QGraphicsSystemFbWindowSurface(mPrimaryScreen, widget); + QFbWindowSurface * surface; + surface = new QFbWindowSurface(mPrimaryScreen, widget); return surface; } -QPlatformWindow *QVNCGraphicsSystem::createPlatformWindow(QWidget *widget, WId /*winId*/) const +QPlatformWindow *QVNCIntegration::createPlatformWindow(QWidget *widget, WId /*winId*/) const { QFbWindow *w = new QFbWindow(mPrimaryScreen, widget); mPrimaryScreen->addWindow(w); diff --git a/src/plugins/platforms/vnc/qgraphicssystem_vnc.h b/src/plugins/platforms/vnc/qgraphicssystem_vnc.h index 3205872..887ccc3 100644 --- a/src/plugins/platforms/vnc/qgraphicssystem_vnc.h +++ b/src/plugins/platforms/vnc/qgraphicssystem_vnc.h @@ -51,32 +51,32 @@ QT_BEGIN_NAMESPACE class QVNCServer; class QVNCDirtyMap; -class QVNCGraphicsSystemScreenPrivate; +class QVNCScreenPrivate; -class QVNCGraphicsSystemScreen : public QGraphicsSystemFbScreen +class QVNCScreen : public QFbScreen { public: - QVNCGraphicsSystemScreen(); + QVNCScreen(); int linestep() const { return image() ? image()->bytesPerLine() : 0; } uchar *base() const { return image() ? image()->bits() : 0; } QVNCDirtyMap *dirtyMap(); public: - QVNCGraphicsSystemScreenPrivate *d_ptr; + QVNCScreenPrivate *d_ptr; private: QVNCServer *server; QRegion doRedraw(); }; -class QVNCGraphicsSystemPrivate; +class QVNCIntegrationPrivate; -class QVNCGraphicsSystem : public QPlatformIntegration +class QVNCIntegration : public QPlatformIntegration { public: - QVNCGraphicsSystem(); + QVNCIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; @@ -86,7 +86,7 @@ public: private: - QVNCGraphicsSystemScreen *mPrimaryScreen; + QVNCScreen *mPrimaryScreen; QList mScreens; }; diff --git a/src/plugins/platforms/vnc/qvnccursor.cpp b/src/plugins/platforms/vnc/qvnccursor.cpp index fb214d8..78da53b 100644 --- a/src/plugins/platforms/vnc/qvnccursor.cpp +++ b/src/plugins/platforms/vnc/qvnccursor.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE -QVNCCursor::QVNCCursor(QVNCServer * srvr, QVNCGraphicsSystemScreen *scr ) +QVNCCursor::QVNCCursor(QVNCServer * srvr, QVNCScreen *scr ) :QGraphicsSystemSoftwareCursor(scr), useVncCursor(false), server(srvr) { } diff --git a/src/plugins/platforms/vnc/qvnccursor.h b/src/plugins/platforms/vnc/qvnccursor.h index 8ea0f45..2c6ff5b 100644 --- a/src/plugins/platforms/vnc/qvnccursor.h +++ b/src/plugins/platforms/vnc/qvnccursor.h @@ -48,12 +48,12 @@ QT_BEGIN_NAMESPACE -class QVNCGraphicsSystemScreen; +class QVNCScreen; class QVNCServer; class QVNCCursor : public QGraphicsSystemSoftwareCursor { public: - QVNCCursor(QVNCServer *, QVNCGraphicsSystemScreen *); + QVNCCursor(QVNCServer *, QVNCScreen *); // input methods void setCursorMode(bool vnc); diff --git a/src/plugins/platforms/vnc/qvncserver.cpp b/src/plugins/platforms/vnc/qvncserver.cpp index ea576d4..ab0a2f3 100644 --- a/src/plugins/platforms/vnc/qvncserver.cpp +++ b/src/plugins/platforms/vnc/qvncserver.cpp @@ -358,13 +358,13 @@ bool QRfbClientCutText::read(QTcpSocket *s) //=========================================================================== -QVNCServer::QVNCServer(QVNCGraphicsSystemScreen *screen) +QVNCServer::QVNCServer(QVNCScreen *screen) : qvnc_screen(screen), cursor(0) { init(5900); } -QVNCServer::QVNCServer(QVNCGraphicsSystemScreen *screen, int id) +QVNCServer::QVNCServer(QVNCScreen *screen, int id) : qvnc_screen(screen), cursor(0) { init(5900 + id); @@ -620,7 +620,7 @@ void QVNCServer::readClient() } #if 0//Q_BYTE_ORDER == Q_BIG_ENDIAN -bool QVNCGraphicsSystemScreen::swapBytes() const +bool QVNCScreen::swapBytes() const { if (depth() != 16) return false; @@ -1499,7 +1499,7 @@ static void blendCursor(QImage &image, const QRect &imageRect) } #endif // QT_NO_QWS_CURSOR -QVNCDirtyMap::QVNCDirtyMap(QVNCGraphicsSystemScreen *s) +QVNCDirtyMap::QVNCDirtyMap(QVNCScreen *s) : bytesPerPixel(0), numDirty(0), screen(s) { bytesPerPixel = (screen->depth() + 7) / 8; @@ -1885,7 +1885,7 @@ void QVNCServer::discardClient() -QVNCGraphicsSystemScreenPrivate::QVNCGraphicsSystemScreenPrivate(QVNCGraphicsSystemScreen *parent) +QVNCScreenPrivate::QVNCScreenPrivate(QVNCScreen *parent) : dpiX(72), dpiY(72), doOnScreenSurface(false), refreshRate(25), vncServer(0), q_ptr(parent) { @@ -1902,12 +1902,12 @@ QVNCGraphicsSystemScreenPrivate::QVNCGraphicsSystemScreenPrivate(QVNCGraphicsSys dirty = new QVNCDirtyMapOptimized(q_ptr); } -QVNCGraphicsSystemScreenPrivate::~QVNCGraphicsSystemScreenPrivate() +QVNCScreenPrivate::~QVNCScreenPrivate() { } -void QVNCGraphicsSystemScreenPrivate::setDirty(const QRect& rect, bool force) +void QVNCScreenPrivate::setDirty(const QRect& rect, bool force) { if (rect.isEmpty()) return; @@ -1916,7 +1916,7 @@ void QVNCGraphicsSystemScreenPrivate::setDirty(const QRect& rect, bool force) // q_ptr->screen()->setDirty(rect); if (!vncServer || !vncServer->isConnected()) { -// qDebug() << "QVNCGraphicsSystemScreenPrivate::setDirty() - Not connected"; +// qDebug() << "QVNCScreenPrivate::setDirty() - Not connected"; return; } const QRect r = rect; // .translated(-q_ptr->offset()); diff --git a/src/plugins/platforms/vnc/qvncserver.h b/src/plugins/platforms/vnc/qvncserver.h index 4fcdbae..41cadab 100644 --- a/src/plugins/platforms/vnc/qvncserver.h +++ b/src/plugins/platforms/vnc/qvncserver.h @@ -72,7 +72,7 @@ class QVNCServer; class QVNCCursor : public QProxyScreenCursor { public: - QVNCCursor(QVNCGraphicsSystemScreen *s); + QVNCCursor(QVNCScreen *s); ~QVNCCursor(); void hide(); @@ -82,7 +82,7 @@ public: private: void setDirty(const QRect &r) const; - QVNCGraphicsSystemScreen *screen; + QVNCScreen *screen; }; class QVNCClientCursor : public QProxyScreenCursor @@ -106,7 +106,7 @@ private: class QVNCDirtyMap { public: - QVNCDirtyMap(QVNCGraphicsSystemScreen *screen); + QVNCDirtyMap(QVNCScreen *screen); virtual ~QVNCDirtyMap(); void reset(); @@ -122,7 +122,7 @@ public: protected: uchar *map; - QVNCGraphicsSystemScreen *screen; + QVNCScreen *screen; uchar *buffer; int bufferWidth; int bufferHeight; @@ -134,7 +134,7 @@ template class QVNCDirtyMapOptimized : public QVNCDirtyMap { public: - QVNCDirtyMapOptimized(QVNCGraphicsSystemScreen *screen) : QVNCDirtyMap(screen) {} + QVNCDirtyMapOptimized(QVNCScreen *screen) : QVNCDirtyMap(screen) {} ~QVNCDirtyMapOptimized() {} void setDirty(int x, int y, bool force = false); @@ -246,11 +246,11 @@ public: quint32 length; }; -class QVNCGraphicsSystemScreenPrivate : public QObject +class QVNCScreenPrivate : public QObject { public: - QVNCGraphicsSystemScreenPrivate(QVNCGraphicsSystemScreen *parent); - ~QVNCGraphicsSystemScreenPrivate(); + QVNCScreenPrivate(QVNCScreen *parent); + ~QVNCScreenPrivate(); void setDirty(const QRect &rect, bool force = false); void configure(); @@ -266,7 +266,7 @@ public: QSharedMemory shm; #endif - QVNCGraphicsSystemScreen *q_ptr; + QVNCScreen *q_ptr; }; class QRfbEncoder @@ -438,8 +438,8 @@ class QVNCServer : public QObject { Q_OBJECT public: - QVNCServer(QVNCGraphicsSystemScreen *screen); - QVNCServer(QVNCGraphicsSystemScreen *screen, int id); + QVNCServer(QVNCScreen *screen); + QVNCServer(QVNCScreen *screen, int id); ~QVNCServer(); void setDirty(); @@ -464,7 +464,7 @@ public: return pixelFormat.bitsPerPixel / 8; } - inline QVNCGraphicsSystemScreen* screen() const { return qvnc_screen; } + inline QVNCScreen* screen() const { return qvnc_screen; } inline QVNCDirtyMap* dirtyMap() const { return qvnc_screen->dirtyMap(); } inline QTcpSocket* clientSocket() const { return client; } QImage *screenImage() const; @@ -519,7 +519,7 @@ private: #endif bool dirtyCursor; int refreshRate; - QVNCGraphicsSystemScreen *qvnc_screen; + QVNCScreen *qvnc_screen; #ifndef QT_NO_QWS_CURSOR QVNCClientCursor *qvnc_cursor; #endif -- cgit v0.12 From e8af272c0c95ab531a060d3e8e8e75b7b03619f4 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 13 Apr 2010 11:38:49 +0200 Subject: Port the QVFb backend to the new API --- src/plugins/platforms/qvfb/main.cpp | 16 +- .../platforms/qvfb/qgraphicssystem_qvfb.cpp | 434 -------------------- src/plugins/platforms/qvfb/qgraphicssystem_qvfb.h | 95 ----- src/plugins/platforms/qvfb/qvfb.pro | 11 +- src/plugins/platforms/qvfb/qvfbintegration.cpp | 439 +++++++++++++++++++++ src/plugins/platforms/qvfb/qvfbintegration.h | 97 +++++ src/plugins/platforms/qvfb/qwindowsurface_qvfb.cpp | 38 +- src/plugins/platforms/qvfb/qwindowsurface_qvfb.h | 26 +- 8 files changed, 586 insertions(+), 570 deletions(-) delete mode 100644 src/plugins/platforms/qvfb/qgraphicssystem_qvfb.cpp delete mode 100644 src/plugins/platforms/qvfb/qgraphicssystem_qvfb.h create mode 100644 src/plugins/platforms/qvfb/qvfbintegration.cpp create mode 100644 src/plugins/platforms/qvfb/qvfbintegration.h diff --git a/src/plugins/platforms/qvfb/main.cpp b/src/plugins/platforms/qvfb/main.cpp index b28dde8..409f11c 100644 --- a/src/plugins/platforms/qvfb/main.cpp +++ b/src/plugins/platforms/qvfb/main.cpp @@ -39,34 +39,34 @@ ** ****************************************************************************/ -#include -#include "qgraphicssystem_qvfb.h" +#include +#include "qvfbintegration.h" #include QT_BEGIN_NAMESPACE -class QVFbGraphicsSystemPlugin : public QGraphicsSystemPlugin +class QVFbIntegrationPlugin : public QPlatformIntegrationPlugin { public: QStringList keys() const; - QGraphicsSystem *create(const QString&); + QPlatformIntegration *create(const QString&); }; -QStringList QVFbGraphicsSystemPlugin::keys() const +QStringList QVFbIntegrationPlugin::keys() const { QStringList list; list << "QVFb"; return list; } -QGraphicsSystem* QVFbGraphicsSystemPlugin::create(const QString& system) +QPlatformIntegration* QVFbIntegrationPlugin::create(const QString& system) { if (system.toLower() == "qvfb") - return new QVFbGraphicsSystem; + return new QVFbIntegration; return 0; } -Q_EXPORT_PLUGIN2(qvfb, QVFbGraphicsSystemPlugin) +Q_EXPORT_PLUGIN2(qvfb, QVFbIntegrationPlugin) QT_END_NAMESPACE diff --git a/src/plugins/platforms/qvfb/qgraphicssystem_qvfb.cpp b/src/plugins/platforms/qvfb/qgraphicssystem_qvfb.cpp deleted file mode 100644 index 19058a6..0000000 --- a/src/plugins/platforms/qvfb/qgraphicssystem_qvfb.cpp +++ /dev/null @@ -1,434 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include // overrides QT_OPEN - -#include -#include - -#include "qgraphicssystem_qvfb.h" -#include "qwindowsurface_qvfb.h" -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - - -class QVFbGraphicsSystemScreenKeyboardHandler : public QObject -{ - Q_OBJECT -public: - QVFbGraphicsSystemScreenKeyboardHandler(); - ~QVFbGraphicsSystemScreenKeyboardHandler(); - -private slots: - void readKeyboardData(); - -private: - int kbdFD; - int kbdIdx; - int kbdBufferLen; - unsigned char *kbdBuffer; - QSocketNotifier *keyNotifier; -}; - -QVFbGraphicsSystemScreenKeyboardHandler::QVFbGraphicsSystemScreenKeyboardHandler() -{ - int displayId = 0; //TODO displayId - const QString keyboardDev = QT_VFB_KEYBOARD_PIPE(displayId); - - - kbdFD = -1; - kbdIdx = 0; - kbdBufferLen = sizeof(QVFbKeyData) * 5; - kbdBuffer = new unsigned char [kbdBufferLen]; - - kbdFD = QT_OPEN(keyboardDev.toLatin1().constData(), O_RDWR | O_NDELAY); - - if (kbdFD == -1) { - perror("QVFbGraphicsSystemScreenKeyboardHandler"); - qWarning("QVFbGraphicsSystemScreenKeyboardHandler: Unable to open device %s", - qPrintable(keyboardDev)); - return; - } - - // Clear pending input - char buf[2]; - while (QT_READ(kbdFD, buf, 1) > 0) { } - - keyNotifier = new QSocketNotifier(kbdFD, QSocketNotifier::Read, this); - connect(keyNotifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData())); - -} - -QVFbGraphicsSystemScreenKeyboardHandler::~QVFbGraphicsSystemScreenKeyboardHandler() -{ - if (kbdFD >= 0) - QT_CLOSE(kbdFD); - delete [] kbdBuffer; -} - - -void QVFbGraphicsSystemScreenKeyboardHandler::readKeyboardData() -{ - int n; - do { - n = QT_READ(kbdFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx); - if (n > 0) - kbdIdx += n; - } while (n > 0); - - int idx = 0; - while (kbdIdx - idx >= (int)sizeof(QVFbKeyData)) { - QVFbKeyData *kd = (QVFbKeyData *)(kbdBuffer + idx); - if (kd->unicode == 0 && kd->keycode == 0 && kd->modifiers == 0 && kd->press) { - // magic exit key - qWarning("Instructed to quit by Virtual Keyboard"); - qApp->quit(); - } - - //QWSServer::processKeyEvent(kd->unicode ? kd->unicode : 0xffff, kd->keycode, kd->modifiers, kd->press, kd->repeat); - - QEvent::Type type = kd->press ? QEvent::KeyPress : QEvent::KeyRelease; - - QString text; - if (kd->unicode && kd->unicode != 0xffff) - text += QChar(kd->unicode); - -// qDebug() << "readKeyboardData" << type << hex << kd->keycode << kd->modifiers << text; - - QWindowSystemInterface::handleKeyEvent(0, type, kd->keycode, kd->modifiers, text, kd->repeat, int(text.length())); - idx += sizeof(QVFbKeyData); - } - - int surplus = kbdIdx - idx; - for (int i = 0; i < surplus; i++) - kbdBuffer[i] = kbdBuffer[idx+i]; - kbdIdx = surplus; -} - - - - -class QVFbGraphicsSystemScreenMouseHandler : public QObject -{ - Q_OBJECT -public: - QVFbGraphicsSystemScreenMouseHandler(); - ~QVFbGraphicsSystemScreenMouseHandler(); - -private slots: - void readMouseData(); - -private: - int mouseFD; - int mouseIdx; - enum {mouseBufSize = 128}; - uchar mouseBuf[mouseBufSize]; - QSocketNotifier *mouseNotifier; - - int oldButtonState; -}; - -QVFbGraphicsSystemScreenMouseHandler::QVFbGraphicsSystemScreenMouseHandler() -{ - int displayId = 0; //TODO: displayId - QString mouseDev = QT_VFB_MOUSE_PIPE(displayId); - - mouseFD = QT_OPEN(mouseDev.toLatin1().constData(), O_RDWR | O_NDELAY); - - if (mouseFD == -1) { - perror("QVFbMouseHandler::QVFbMouseHandler"); - qWarning("QVFbMouseHander: Unable to open device %s", - qPrintable(mouseDev)); - return; - } - - // Clear pending input - char buf[2]; - while (QT_READ(mouseFD, buf, 1) > 0) { } - - mouseIdx = 0; - oldButtonState = 0; - mouseNotifier = new QSocketNotifier(mouseFD, QSocketNotifier::Read, this); - connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData())); -} - - -QVFbGraphicsSystemScreenMouseHandler::~QVFbGraphicsSystemScreenMouseHandler() -{ - if (mouseFD >= 0) - QT_CLOSE(mouseFD); -} - -void QVFbGraphicsSystemScreenMouseHandler::readMouseData() -{ - int n; - do { - n = QT_READ(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx); - if (n > 0) - mouseIdx += n; - } while (n > 0); - - int idx = 0; - static const int packetsize = sizeof(QPoint) + 2*sizeof(int); - while (mouseIdx-idx >= packetsize) { - uchar *mb = mouseBuf+idx; - QPoint mousePos = *reinterpret_cast(mb); - mb += sizeof(QPoint); - int bstate = *reinterpret_cast(mb); - mb += sizeof(int); - int wheel = *reinterpret_cast(mb); - - int button = bstate ^ oldButtonState; - QEvent::Type type = QEvent::MouseMove; - - if (button) { - type = (button & bstate) ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease; - } - QWindowSystemInterface::handleMouseEvent(0, mousePos, mousePos, Qt::MouseButtons(bstate)); - -// qDebug() << "readMouseData" << mousePos << button << bstate << oldButtonState << type; - - oldButtonState = bstate; - - idx += packetsize; - } - - int surplus = mouseIdx - idx; - for (int i = 0; i < surplus; i++) - mouseBuf[i] = mouseBuf[idx+i]; - mouseIdx = surplus; - -} - - -class QVFbGraphicsSystemScreenPrivate -{ -public: - QVFbGraphicsSystemScreenPrivate(QVFbGraphicsSystemScreen *) - : shmrgn(0), hdr(0), data(0), mouseHandler(0), keyboardHandler(0) - { - connect(0); //for now we only handle one screen - } - - ~QVFbGraphicsSystemScreenPrivate() { disconnect(); } - void setDirty(const QRect &r); - - bool connect(int displayId); - void disconnect(); - - QImage *screenImage() { return &img; } - QSize screenSize() { return img.size(); } - - int depth() const { return img.depth(); } - QImage::Format format() const { return img.format(); } - -private: - unsigned char *shmrgn; - QVFbHeader *hdr; - uchar *data; - QVFbGraphicsSystemScreenMouseHandler *mouseHandler; - QVFbGraphicsSystemScreenKeyboardHandler *keyboardHandler; - - - QImage img; -}; - - -void QVFbGraphicsSystemScreenPrivate::setDirty(const QRect &r) -{ - hdr->dirty = true; - hdr->update = hdr->update.united(r); -} - - -bool QVFbGraphicsSystemScreenPrivate::connect(int displayId) -{ - - key_t key = ftok(QT_VFB_MOUSE_PIPE(displayId).toLatin1(), 'b'); - - if (key == -1) - return false; - - - int shmId = shmget(key, 0, 0); - if (shmId != -1) - shmrgn = (unsigned char *)shmat(shmId, 0, 0); - else - return false; - - if ((long)shmrgn == -1 || shmrgn == 0) { - qDebug("No shmrgn %ld", (long)shmrgn); - return false; - } - - hdr = (QVFbHeader *)shmrgn; - data = shmrgn + hdr->dataoffset; - - int w = hdr->width; - int h = hdr->height; - int d = hdr->depth; - int lstep = hdr->linestep; - - QImage::Format format = QImage::Format_Invalid; - if (d == 32) - format = QImage::Format_ARGB32_Premultiplied; - else if (d == 16) - format = QImage::Format_RGB16; - - - if (format == QImage::Format_Invalid) { - img = QImage(); - return false; - } - - img = QImage(data, w, h, lstep, format); - - qDebug("connected %dx%d %d bpp", w, h, d); - - - mouseHandler = new QVFbGraphicsSystemScreenMouseHandler; - keyboardHandler = new QVFbGraphicsSystemScreenKeyboardHandler; - return true; -} - -void QVFbGraphicsSystemScreenPrivate::disconnect() -{ - if ((long)shmrgn != -1 && shmrgn) { - shmdt((char*)shmrgn); - shmrgn = 0; - } - delete mouseHandler; - mouseHandler = 0; - delete keyboardHandler; - keyboardHandler = 0; -} - - -QVFbGraphicsSystemScreen::QVFbGraphicsSystemScreen() -{ - d_ptr = new QVFbGraphicsSystemScreenPrivate(this); -} - - -QVFbGraphicsSystemScreen::~QVFbGraphicsSystemScreen() -{ - delete d_ptr; -} - -void QVFbGraphicsSystemScreen::setDirty(const QRect &rect) -{ - d_ptr->setDirty(rect); -} - - - -QRect QVFbGraphicsSystemScreen::geometry() const { - return QRect(QPoint(), d_ptr->screenSize()); -} - - -int QVFbGraphicsSystemScreen::depth() const -{ - return d_ptr->depth(); -} - -QImage::Format QVFbGraphicsSystemScreen::format() const -{ - return d_ptr->format(); -} - -QSize QVFbGraphicsSystemScreen::physicalSize() const { - return (d_ptr->screenSize()*254)/720; -} - -#if 0 -int QVFbGraphicsSystemScreen::linestep() const { - return d_ptr->screenImage() ? d_ptr->screenImage()->bytesPerLine() : 0; -} - -uchar *QVFbGraphicsSystemScreen::base() const { - return d_ptr->screenImage() ? d_ptr->screenImage()->bits() : 0; -} -#endif - -QImage *QVFbGraphicsSystemScreen::screenImage() -{ - return d_ptr->screenImage(); -} - -QVFbGraphicsSystem::QVFbGraphicsSystem() -{ - mPrimaryScreen = new QVFbGraphicsSystemScreen(); - - mScreens.append(mPrimaryScreen); -} - -QPixmapData *QVFbGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const -{ - return new QRasterPixmapData(type); -} - -QWindowSurface *QVFbGraphicsSystem::createWindowSurface(QWidget *widget) const -{ - if (widget->windowType() == Qt::Desktop) - return 0; // Don't create an explicit window surface for the destkop. - return new QVFbWindowSurface - (const_cast(this), mPrimaryScreen, widget); -} - -QT_END_NAMESPACE - -#include "qgraphicssystem_qvfb.moc" diff --git a/src/plugins/platforms/qvfb/qgraphicssystem_qvfb.h b/src/plugins/platforms/qvfb/qgraphicssystem_qvfb.h deleted file mode 100644 index b31869c..0000000 --- a/src/plugins/platforms/qvfb/qgraphicssystem_qvfb.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGRAPHICSSYSTEM_QVFB_H -#define QGRAPHICSSYSTEM_QVFB_H - -#include - -QT_BEGIN_NAMESPACE - - -class QVFbGraphicsSystemScreenPrivate; - -class QVFbGraphicsSystemScreen : public QGraphicsSystemScreen -{ -public: - QVFbGraphicsSystemScreen(); - ~QVFbGraphicsSystemScreen(); - - QRect geometry() const; - int depth() const; - QImage::Format format() const; - QSize physicalSize() const; - - QImage *screenImage(); - - void setDirty(const QRect &rect); - -public: - - QVFbGraphicsSystemScreenPrivate *d_ptr; -}; - -class QVFbGraphicsSystemPrivate; - - -class QVFbGraphicsSystem : public QGraphicsSystem -{ -public: - QVFbGraphicsSystem(); - - QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; - - QList screens() const { return mScreens; } - -private: - QVFbGraphicsSystemScreen *mPrimaryScreen; - QList mScreens; -}; - - - -QT_END_NAMESPACE - - -#endif diff --git a/src/plugins/platforms/qvfb/qvfb.pro b/src/plugins/platforms/qvfb/qvfb.pro index b321725..4dec274 100644 --- a/src/plugins/platforms/qvfb/qvfb.pro +++ b/src/plugins/platforms/qvfb/qvfb.pro @@ -1,12 +1,11 @@ -TARGET = qvfbgraphicssystem +TARGET = qvfbintegration include(../../qpluginbase.pri) -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/graphicssystems +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms +SOURCES = main.cpp qvfbintegration.cpp qwindowsurface_qvfb.cpp +HEADERS = qvfbintegration.h qwindowsurface_qvfb.h -SOURCES = main.cpp qgraphicssystem_qvfb.cpp qwindowsurface_qvfb.cpp -HEADERS = qgraphicssystem_qvfb.h qwindowsurface_qvfb.h - -target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems +target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target diff --git a/src/plugins/platforms/qvfb/qvfbintegration.cpp b/src/plugins/platforms/qvfb/qvfbintegration.cpp new file mode 100644 index 0000000..2a877e0 --- /dev/null +++ b/src/plugins/platforms/qvfb/qvfbintegration.cpp @@ -0,0 +1,439 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include // overrides QT_OPEN + +#include +#include + +#include "qvfbintegration.h" +#include "qwindowsurface_qvfb.h" +#include +#include +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + + +class QVFbScreenKeyboardHandler : public QObject +{ + Q_OBJECT +public: + QVFbScreenKeyboardHandler(); + ~QVFbScreenKeyboardHandler(); + +private slots: + void readKeyboardData(); + +private: + int kbdFD; + int kbdIdx; + int kbdBufferLen; + unsigned char *kbdBuffer; + QSocketNotifier *keyNotifier; +}; + +QVFbScreenKeyboardHandler::QVFbScreenKeyboardHandler() +{ + int displayId = 0; //TODO displayId + const QString keyboardDev = QT_VFB_KEYBOARD_PIPE(displayId); + + + kbdFD = -1; + kbdIdx = 0; + kbdBufferLen = sizeof(QVFbKeyData) * 5; + kbdBuffer = new unsigned char [kbdBufferLen]; + + kbdFD = QT_OPEN(keyboardDev.toLatin1().constData(), O_RDWR | O_NDELAY); + + if (kbdFD == -1) { + perror("QVFbScreenKeyboardHandler"); + qWarning("QVFbScreenKeyboardHandler: Unable to open device %s", + qPrintable(keyboardDev)); + return; + } + + // Clear pending input + char buf[2]; + while (QT_READ(kbdFD, buf, 1) > 0) { } + + keyNotifier = new QSocketNotifier(kbdFD, QSocketNotifier::Read, this); + connect(keyNotifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData())); + +} + +QVFbScreenKeyboardHandler::~QVFbScreenKeyboardHandler() +{ + if (kbdFD >= 0) + QT_CLOSE(kbdFD); + delete [] kbdBuffer; +} + + +void QVFbScreenKeyboardHandler::readKeyboardData() +{ + int n; + do { + n = QT_READ(kbdFD, kbdBuffer+kbdIdx, kbdBufferLen - kbdIdx); + if (n > 0) + kbdIdx += n; + } while (n > 0); + + int idx = 0; + while (kbdIdx - idx >= (int)sizeof(QVFbKeyData)) { + QVFbKeyData *kd = (QVFbKeyData *)(kbdBuffer + idx); + if (kd->unicode == 0 && kd->keycode == 0 && kd->modifiers == 0 && kd->press) { + // magic exit key + qWarning("Instructed to quit by Virtual Keyboard"); + qApp->quit(); + } + + //QWSServer::processKeyEvent(kd->unicode ? kd->unicode : 0xffff, kd->keycode, kd->modifiers, kd->press, kd->repeat); + + QEvent::Type type = kd->press ? QEvent::KeyPress : QEvent::KeyRelease; + + QString text; + if (kd->unicode && kd->unicode != 0xffff) + text += QChar(kd->unicode); + +// qDebug() << "readKeyboardData" << type << hex << kd->keycode << kd->modifiers << text; + + QWindowSystemInterface::handleKeyEvent(0, type, kd->keycode, kd->modifiers, text, kd->repeat, int(text.length())); + idx += sizeof(QVFbKeyData); + } + + int surplus = kbdIdx - idx; + for (int i = 0; i < surplus; i++) + kbdBuffer[i] = kbdBuffer[idx+i]; + kbdIdx = surplus; +} + + + + +class QVFbScreenMouseHandler : public QObject +{ + Q_OBJECT +public: + QVFbScreenMouseHandler(); + ~QVFbScreenMouseHandler(); + +private slots: + void readMouseData(); + +private: + int mouseFD; + int mouseIdx; + enum {mouseBufSize = 128}; + uchar mouseBuf[mouseBufSize]; + QSocketNotifier *mouseNotifier; + + int oldButtonState; +}; + +QVFbScreenMouseHandler::QVFbScreenMouseHandler() +{ + int displayId = 0; //TODO: displayId + QString mouseDev = QT_VFB_MOUSE_PIPE(displayId); + + mouseFD = QT_OPEN(mouseDev.toLatin1().constData(), O_RDWR | O_NDELAY); + + if (mouseFD == -1) { + perror("QVFbMouseHandler::QVFbMouseHandler"); + qWarning("QVFbMouseHander: Unable to open device %s", + qPrintable(mouseDev)); + return; + } + + // Clear pending input + char buf[2]; + while (QT_READ(mouseFD, buf, 1) > 0) { } + + mouseIdx = 0; + oldButtonState = 0; + mouseNotifier = new QSocketNotifier(mouseFD, QSocketNotifier::Read, this); + connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData())); +} + + +QVFbScreenMouseHandler::~QVFbScreenMouseHandler() +{ + if (mouseFD >= 0) + QT_CLOSE(mouseFD); +} + +void QVFbScreenMouseHandler::readMouseData() +{ + int n; + do { + n = QT_READ(mouseFD, mouseBuf+mouseIdx, mouseBufSize-mouseIdx); + if (n > 0) + mouseIdx += n; + } while (n > 0); + + int idx = 0; + static const int packetsize = sizeof(QPoint) + 2*sizeof(int); + while (mouseIdx-idx >= packetsize) { + uchar *mb = mouseBuf+idx; + QPoint mousePos = *reinterpret_cast(mb); + mb += sizeof(QPoint); + int bstate = *reinterpret_cast(mb); + mb += sizeof(int); + //int wheel = *reinterpret_cast(mb); + + int button = bstate ^ oldButtonState; + QEvent::Type type = QEvent::MouseMove; + + if (button) { + type = (button & bstate) ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease; + } + QWindowSystemInterface::handleMouseEvent(0, mousePos, mousePos, Qt::MouseButtons(bstate)); + +// qDebug() << "readMouseData" << mousePos << button << bstate << oldButtonState << type; + + oldButtonState = bstate; + + idx += packetsize; + } + + int surplus = mouseIdx - idx; + for (int i = 0; i < surplus; i++) + mouseBuf[i] = mouseBuf[idx+i]; + mouseIdx = surplus; + +} + + +class QVFbScreenPrivate +{ +public: + QVFbScreenPrivate(QVFbScreen *) + : shmrgn(0), hdr(0), data(0), mouseHandler(0), keyboardHandler(0) + { + connect(0); //for now we only handle one screen + } + + ~QVFbScreenPrivate() { disconnect(); } + void setDirty(const QRect &r); + + bool connect(int displayId); + void disconnect(); + + QImage *screenImage() { return &img; } + QSize screenSize() { return img.size(); } + + int depth() const { return img.depth(); } + QImage::Format format() const { return img.format(); } + +private: + unsigned char *shmrgn; + QVFbHeader *hdr; + uchar *data; + QVFbScreenMouseHandler *mouseHandler; + QVFbScreenKeyboardHandler *keyboardHandler; + + + QImage img; +}; + + +void QVFbScreenPrivate::setDirty(const QRect &r) +{ + hdr->dirty = true; + hdr->update = hdr->update.united(r); +} + + +bool QVFbScreenPrivate::connect(int displayId) +{ + + key_t key = ftok(QT_VFB_MOUSE_PIPE(displayId).toLatin1(), 'b'); + + if (key == -1) + return false; + + + int shmId = shmget(key, 0, 0); + if (shmId != -1) + shmrgn = (unsigned char *)shmat(shmId, 0, 0); + else + return false; + + if ((long)shmrgn == -1 || shmrgn == 0) { + qDebug("No shmrgn %ld", (long)shmrgn); + return false; + } + + hdr = (QVFbHeader *)shmrgn; + data = shmrgn + hdr->dataoffset; + + int w = hdr->width; + int h = hdr->height; + int d = hdr->depth; + int lstep = hdr->linestep; + + QImage::Format format = QImage::Format_Invalid; + if (d == 32) + format = QImage::Format_ARGB32_Premultiplied; + else if (d == 16) + format = QImage::Format_RGB16; + + + if (format == QImage::Format_Invalid) { + img = QImage(); + return false; + } + + img = QImage(data, w, h, lstep, format); + + qDebug("connected %dx%d %d bpp", w, h, d); + + + mouseHandler = new QVFbScreenMouseHandler; + keyboardHandler = new QVFbScreenKeyboardHandler; + return true; +} + +void QVFbScreenPrivate::disconnect() +{ + if ((long)shmrgn != -1 && shmrgn) { + shmdt((char*)shmrgn); + shmrgn = 0; + } + delete mouseHandler; + mouseHandler = 0; + delete keyboardHandler; + keyboardHandler = 0; +} + + +QVFbScreen::QVFbScreen() +{ + d_ptr = new QVFbScreenPrivate(this); +} + + +QVFbScreen::~QVFbScreen() +{ + delete d_ptr; +} + +void QVFbScreen::setDirty(const QRect &rect) +{ + d_ptr->setDirty(rect); +} + + + +QRect QVFbScreen::geometry() const { + return QRect(QPoint(), d_ptr->screenSize()); +} + + +int QVFbScreen::depth() const +{ + return d_ptr->depth(); +} + +QImage::Format QVFbScreen::format() const +{ + return d_ptr->format(); +} + +QSize QVFbScreen::physicalSize() const { + return (d_ptr->screenSize()*254)/720; +} + +#if 0 +int QVFbScreen::linestep() const { + return d_ptr->screenImage() ? d_ptr->screenImage()->bytesPerLine() : 0; +} + +uchar *QVFbScreen::base() const { + return d_ptr->screenImage() ? d_ptr->screenImage()->bits() : 0; +} +#endif + +QImage *QVFbScreen::screenImage() +{ + return d_ptr->screenImage(); +} + +QVFbIntegration::QVFbIntegration() +{ + mPrimaryScreen = new QVFbScreen(); + + mScreens.append(mPrimaryScreen); +} + +QPixmapData *QVFbIntegration::createPixmapData(QPixmapData::PixelType type) const +{ + return new QRasterPixmapData(type); +} + +QWindowSurface *QVFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const +{ + if (widget->windowType() == Qt::Desktop) + return 0; // Don't create an explicit window surface for the destkop. + return new QVFbWindowSurface(mPrimaryScreen, widget); +} + + +QPlatformWindow *QVFbIntegration::createPlatformWindow(QWidget *widget, WId) const +{ + return new QVFbWindow(mPrimaryScreen, widget); +} + +QT_END_NAMESPACE + +#include "qgraphicssystem_qvfb.moc" diff --git a/src/plugins/platforms/qvfb/qvfbintegration.h b/src/plugins/platforms/qvfb/qvfbintegration.h new file mode 100644 index 0000000..1207678 --- /dev/null +++ b/src/plugins/platforms/qvfb/qvfbintegration.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGRAPHICSSYSTEM_QVFB_H +#define QGRAPHICSSYSTEM_QVFB_H + +#include +#include + +QT_BEGIN_NAMESPACE + + +class QVFbScreenPrivate; + +class QVFbScreen : public QPlatformScreen +{ +public: + QVFbScreen(); + ~QVFbScreen(); + + QRect geometry() const; + int depth() const; + QImage::Format format() const; + QSize physicalSize() const; + + QImage *screenImage(); + + void setDirty(const QRect &rect); + +public: + + QVFbScreenPrivate *d_ptr; +}; + +class QVFbIntegrationPrivate; + + +class QVFbIntegration : public QPlatformIntegration +{ +public: + QVFbIntegration(); + + QPixmapData *createPixmapData(QPixmapData::PixelType type) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; + + QList screens() const { return mScreens; } + +private: + QVFbScreen *mPrimaryScreen; + QList mScreens; +}; + + + +QT_END_NAMESPACE + + +#endif diff --git a/src/plugins/platforms/qvfb/qwindowsurface_qvfb.cpp b/src/plugins/platforms/qvfb/qwindowsurface_qvfb.cpp index 0aafe28..b46d9c0 100644 --- a/src/plugins/platforms/qvfb/qwindowsurface_qvfb.cpp +++ b/src/plugins/platforms/qvfb/qwindowsurface_qvfb.cpp @@ -41,15 +41,15 @@ #include "qwindowsurface_qvfb.h" -#include "qgraphicssystem_qvfb.h" +#include "qvfbintegration.h" #include #include #include QT_BEGIN_NAMESPACE -QVFbWindowSurface::QVFbWindowSurface(QVFbGraphicsSystem *graphicsSystem, - QVFbGraphicsSystemScreen *screen, QWidget *window) +QVFbWindowSurface::QVFbWindowSurface(//QVFbIntegration *graphicsSystem, + QVFbScreen *screen, QWidget *window) : QWindowSurface(window), mScreen(screen) { @@ -69,36 +69,40 @@ void QVFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoi Q_UNUSED(widget); Q_UNUSED(offset); - QRect rect = geometry(); - QPoint topLeft = rect.topLeft(); +// QRect rect = geometry(); +// QPoint topLeft = rect.topLeft(); mScreen->setDirty(region.boundingRect()); } -void QVFbWindowSurface::setGeometry(const QRect &) +void QVFbWindowSurface::resize(const QSize&) { // any size you like as long as it's full-screen... QRect rect(mScreen->availableGeometry()); - QWindowSystemInterface::handleGeometryChange(this->window(), rect); - - QWindowSurface::setGeometry(rect); + QWindowSurface::resize(rect.size()); } -bool QVFbWindowSurface::scroll(const QRegion &area, int dx, int dy) -{ - return QWindowSurface::scroll(area, dx, dy); -} -void QVFbWindowSurface::beginPaint(const QRegion ®ion) +QVFbWindow::QVFbWindow(QVFbScreen *screen, QWidget *window) + : QPlatformWindow(window), + mScreen(screen) { - Q_UNUSED(region); } -void QVFbWindowSurface::endPaint(const QRegion ®ion) + +void QVFbWindow::setGeometry(const QRect &) { - Q_UNUSED(region); + +// any size you like as long as it's full-screen... + + QRect rect(mScreen->availableGeometry()); + QWindowSystemInterface::handleGeometryChange(this->widget(), rect); + + QPlatformWindow::setGeometry(rect); } + + QT_END_NAMESPACE diff --git a/src/plugins/platforms/qvfb/qwindowsurface_qvfb.h b/src/plugins/platforms/qvfb/qwindowsurface_qvfb.h index 1971caa..9228189 100644 --- a/src/plugins/platforms/qvfb/qwindowsurface_qvfb.h +++ b/src/plugins/platforms/qvfb/qwindowsurface_qvfb.h @@ -43,32 +43,38 @@ #define QWINDOWSURFACE_QVFB_H #include +#include QT_BEGIN_NAMESPACE -class QVFbGraphicsSystem; -class QVFbGraphicsSystemScreen; +class QVFbIntegration; +class QVFbScreen; class QVFbWindowSurface : public QWindowSurface { public: - QVFbWindowSurface(QVFbGraphicsSystem *graphicsSystem, - QVFbGraphicsSystemScreen *screen, QWidget *window); + QVFbWindowSurface(QVFbScreen *screen, QWidget *window); ~QVFbWindowSurface(); QPaintDevice *paintDevice(); void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void setGeometry(const QRect &rect); - bool scroll(const QRegion &area, int dx, int dy); + void resize(const QSize &size); + +private: + QVFbScreen *mScreen; +}; - void beginPaint(const QRegion ®ion); - void endPaint(const QRegion ®ion); +class QVFbWindow : public QPlatformWindow +{ +public: + QVFbWindow(QVFbScreen *screen, QWidget *window); + void setGeometry(const QRect &rect); private: - QVFbGraphicsSystem *mGraphicsSystem; - QVFbGraphicsSystemScreen *mScreen; + QVFbScreen *mScreen; }; + QT_END_NAMESPACE #endif -- cgit v0.12 From f507dca0b179b85455662c69029435310320f4c0 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 13 Apr 2010 16:11:27 +0200 Subject: Oops, don't crash in raise()/lower() --- src/plugins/platforms/testlite/qplatformintegration_testlite.cpp | 2 +- src/plugins/platforms/testlite/qtestlitewindow.cpp | 6 +++--- src/plugins/platforms/testlite/qtestlitewindow.h | 3 +-- src/plugins/platforms/testlite/qwindowsurface_testlite.cpp | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp index f9b3135..f13951d 100644 --- a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp +++ b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp @@ -113,7 +113,7 @@ QWindowSurface *QTestLiteIntegration::createWindowSurfaceForWindow(QWidget *widg QPlatformWindow *QTestLiteIntegration::createPlatformWindow(QWidget *widget, WId /*winId*/) const { - return new QTestLiteWindow(const_cast(this), mPrimaryScreen, widget); + return new QTestLiteWindow(this, mPrimaryScreen, widget); } diff --git a/src/plugins/platforms/testlite/qtestlitewindow.cpp b/src/plugins/platforms/testlite/qtestlitewindow.cpp index 0b215e3..108f732 100644 --- a/src/plugins/platforms/testlite/qtestlitewindow.cpp +++ b/src/plugins/platforms/testlite/qtestlitewindow.cpp @@ -143,7 +143,7 @@ private: -QTestLiteWindow::QTestLiteWindow(QTestLiteIntegration *platformIntegration, +QTestLiteWindow::QTestLiteWindow(const QTestLiteIntegration *platformIntegration, QTestLiteScreen */*screen*/, QWidget *window) :QPlatformWindow(window) { @@ -638,12 +638,12 @@ WId QTestLiteWindow::winId() const void QTestLiteWindow::raise() { - XRaiseWindow(mPlatformIntegration->xd->display, x_window); + XRaiseWindow(xd->display, x_window); } void QTestLiteWindow::lower() { - XLowerWindow(mPlatformIntegration->xd->display, x_window); + XLowerWindow(xd->display, x_window); } void QTestLiteWindow::setWindowTitle(const QString &title) diff --git a/src/plugins/platforms/testlite/qtestlitewindow.h b/src/plugins/platforms/testlite/qtestlitewindow.h index 6fb7ed2..3624854 100644 --- a/src/plugins/platforms/testlite/qtestlitewindow.h +++ b/src/plugins/platforms/testlite/qtestlitewindow.h @@ -99,7 +99,7 @@ class QWindowSurface; class QTestLiteWindow : public QPlatformWindow { public: - QTestLiteWindow(QTestLiteIntegration *platformIntegration, + QTestLiteWindow(const QTestLiteIntegration *platformIntegration, QTestLiteScreen *screen, QWidget *window); ~QTestLiteWindow(); @@ -143,7 +143,6 @@ private: QWindowSurface *windowSurface; MyDisplay *xd; - QTestLiteIntegration *mPlatformIntegration; QTestLiteScreen *mScreen; Qt::WindowFlags window_flags; diff --git a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp index b5a0f74..af10368 100644 --- a/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp +++ b/src/plugins/platforms/testlite/qwindowsurface_testlite.cpp @@ -137,7 +137,6 @@ QTestLiteWindowSurface::QTestLiteWindowSurface (QTestLiteScreen */*screen*/, QWi QTestLiteWindowSurface::~QTestLiteWindowSurface() { - qDebug() << "~QTestLiteWindowSurface"; delete image_info; } -- cgit v0.12 From b2315a45cb1d64b86a4974ae0dac97c877a69d91 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Wed, 14 Apr 2010 11:07:02 +0200 Subject: Implement createWindowSurface, so that reparenting works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Jørgen --- src/gui/painting/qgraphicssystem_lite.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/painting/qgraphicssystem_lite.cpp b/src/gui/painting/qgraphicssystem_lite.cpp index a62abbb..68d880b 100644 --- a/src/gui/painting/qgraphicssystem_lite.cpp +++ b/src/gui/painting/qgraphicssystem_lite.cpp @@ -51,8 +51,7 @@ QPixmapData *QLiteGraphicsSystem::createPixmapData(QPixmapData::PixelType type) QWindowSurface *QLiteGraphicsSystem::createWindowSurface(QWidget *widget) const { - qFatal("should not use QLiteGraphicsSystem::createWindowSurface"); - return 0; + return QApplicationPrivate::platformIntegration()->createWindowSurfaceForWindow(widget, widget->winId()); } QBlittable *QLiteGraphicsSystem::createBlittable(const QSize &size) const -- cgit v0.12 From 4e42cea17031ff90481a674686afdd5548fba4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 14 Apr 2010 12:38:01 +0200 Subject: Refactored directfb plugin --- src/plugins/platforms/directfb/directfb.pro | 12 +- src/plugins/platforms/directfb/main.cpp | 2 +- .../platforms/directfb/qblitter_directfb.cpp | 114 ----------------- src/plugins/platforms/directfb/qblitter_directfb.h | 29 ----- .../platforms/directfb/qdirectfbblitter.cpp | 114 +++++++++++++++++ src/plugins/platforms/directfb/qdirectfbblitter.h | 29 +++++ .../platforms/directfb/qdirectfbconvenience.cpp | 2 +- src/plugins/platforms/directfb/qdirectfbcursor.cpp | 3 - .../platforms/directfb/qdirectfbintegration.cpp | 125 ++++++++++++++++++ .../platforms/directfb/qdirectfbintegration.h | 100 +++++++++++++++ .../platforms/directfb/qdirectfbwindowsurface.cpp | 141 +++++++++++++++++++++ .../platforms/directfb/qdirectfbwindowsurface.h | 77 +++++++++++ .../directfb/qplatformintegration_directfb.cpp | 125 ------------------ .../directfb/qplatformintegration_directfb.h | 99 --------------- .../platforms/directfb/qwindowsurface_directfb.cpp | 141 --------------------- .../platforms/directfb/qwindowsurface_directfb.h | 77 ----------- 16 files changed, 594 insertions(+), 596 deletions(-) delete mode 100644 src/plugins/platforms/directfb/qblitter_directfb.cpp delete mode 100644 src/plugins/platforms/directfb/qblitter_directfb.h create mode 100644 src/plugins/platforms/directfb/qdirectfbblitter.cpp create mode 100644 src/plugins/platforms/directfb/qdirectfbblitter.h create mode 100644 src/plugins/platforms/directfb/qdirectfbintegration.cpp create mode 100644 src/plugins/platforms/directfb/qdirectfbintegration.h create mode 100644 src/plugins/platforms/directfb/qdirectfbwindowsurface.cpp create mode 100644 src/plugins/platforms/directfb/qdirectfbwindowsurface.h delete mode 100644 src/plugins/platforms/directfb/qplatformintegration_directfb.cpp delete mode 100644 src/plugins/platforms/directfb/qplatformintegration_directfb.h delete mode 100644 src/plugins/platforms/directfb/qwindowsurface_directfb.cpp delete mode 100644 src/plugins/platforms/directfb/qwindowsurface_directfb.h diff --git a/src/plugins/platforms/directfb/directfb.pro b/src/plugins/platforms/directfb/directfb.pro index ec5f0f1..f81ec31 100644 --- a/src/plugins/platforms/directfb/directfb.pro +++ b/src/plugins/platforms/directfb/directfb.pro @@ -13,16 +13,16 @@ INCLUDEPATH += $$DIRECTFB_INCLUDEPATH LIBS += $$DIRECTFB_LIBS SOURCES = main.cpp \ - qplatformintegration_directfb.cpp \ - qwindowsurface_directfb.cpp \ - qblitter_directfb.cpp \ + qdirectfbintegration.cpp \ + qdirectfbwindowsurface.cpp \ + qdirectfbblitter.cpp \ qdirectfbconvenience.cpp \ qdirectfbinput.cpp \ qdirectfbcursor.cpp \ qdirectfbwindow.cpp -HEADERS = qplatformintegration_directfb.h \ - qwindowsurface_directfb.h \ - qblitter_directfb.h \ +HEADERS = qdirectfbintegration.h \ + qdirectfbwindowsurface.h \ + qdirectfbblitter.h \ qdirectfbconvenience.h \ qdirectfbinput.h \ qdirectfbcursor.h \ diff --git a/src/plugins/platforms/directfb/main.cpp b/src/plugins/platforms/directfb/main.cpp index 1f0f081..9c7bcf6 100644 --- a/src/plugins/platforms/directfb/main.cpp +++ b/src/plugins/platforms/directfb/main.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include -#include "qplatformintegration_directfb.h" +#include "qdirectfbintegration.h" QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/directfb/qblitter_directfb.cpp b/src/plugins/platforms/directfb/qblitter_directfb.cpp deleted file mode 100644 index 20f8741..0000000 --- a/src/plugins/platforms/directfb/qblitter_directfb.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "qblitter_directfb.h" -#include "qdirectfbconvenience.h" - -#include - -#include - -#include - -QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, IDirectFBSurface *surface) - : QBlittable(rect, QBlittable::Capabilities(QBlittable::SolidRectCapability - |QBlittable::SourcePixmapCapability - |QBlittable::SourceOverPixmapCapability - |QBlittable::SourceOverScaledPixmapCapability)) -{ - if (surface) { - m_surface = surface; - } else { - DFBSurfaceDescription surfaceDesc; - memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription)); - surfaceDesc.width = rect.width(); - surfaceDesc.height = rect.height(); - surfaceDesc.caps = DSCAPS_PREMULTIPLIED; - surfaceDesc.pixelformat = DSPF_ARGB; - surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT); - - IDirectFB *dfb = QDirectFbConvenience::dfbInterface(); - dfb->CreateSurface(dfb,&surfaceDesc, &m_surface); - m_surface->Clear(m_surface,0,0,0,0); - } - -} - -QDirectFbBlitter::~QDirectFbBlitter() -{ - unlock(); - m_surface->Release(m_surface); -} - -void QDirectFbBlitter::fillRect(const QRectF &rect, const QColor &color) -{ - m_surface->SetColor(m_surface, color.red(), color.green(), color.blue(), color.alpha()); -// When the blitter api supports non opaque blits, also remember to change -// qpixmap_blitter.cpp::fill -// DFBSurfaceDrawingFlags drawingFlags = color.alpha() ? DSDRAW_BLEND : DSDRAW_NOFX; -// m_surface->SetDrawingFlags(m_surface, drawingFlags); - m_surface->SetDrawingFlags(m_surface, DSDRAW_NOFX); - m_surface->FillRectangle(m_surface, rect.x(), rect.y(), - rect.width(), rect.height()); -} - -void QDirectFbBlitter::drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &srcRect) -{ - QPixmapData *data = pixmap.pixmapData(); - Q_ASSERT(data->width() && data->height()); - Q_ASSERT(data->classId() == QPixmapData::BlitterClass); - QBlittablePixmapData *blitPm = static_cast(data); - QDirectFbBlitter *dfbBlitter = static_cast(blitPm->blittable()); - dfbBlitter->unlock(); - - IDirectFBSurface *s = dfbBlitter->m_surface; - - DFBSurfaceBlittingFlags blittingFlags = DSBLIT_NOFX; - DFBSurfacePorterDuffRule porterDuff = DSPD_SRC; - if (pixmap.hasAlpha()) { - blittingFlags = DSBLIT_BLEND_ALPHACHANNEL; - porterDuff = DSPD_SRC_OVER; - } - - m_surface->SetBlittingFlags(m_surface, DFBSurfaceBlittingFlags(blittingFlags)); - m_surface->SetPorterDuff(m_surface,porterDuff); - m_surface->SetDstBlendFunction(m_surface,DSBF_INVSRCALPHA); - - const DFBRectangle sRect = { srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height() }; - - DFBResult result; - if (rect.width() == srcRect.width() && rect.height() == srcRect.height()) - result = m_surface->Blit(m_surface, s, &sRect, rect.x(), rect.y()); - else { - const DFBRectangle dRect = { rect.x(), rect.y(), rect.width(), rect.height() }; - result = m_surface->StretchBlit(m_surface, s, &sRect, &dRect); - } - if (result != DFB_OK) - DirectFBError("QDirectFBBlitter::drawPixmap()", result); -} - -QImage *QDirectFbBlitter::doLock() -{ - Q_ASSERT(m_surface); - Q_ASSERT(size().isValid()); - - void *mem; - int bpl; - const DFBResult result = m_surface->Lock(m_surface, DFBSurfaceLockFlags(DSLF_WRITE|DSLF_READ), static_cast(&mem), &bpl); - if (result == DFB_OK) { - DFBSurfacePixelFormat dfbFormat; - DFBSurfaceCapabilities dfbCaps; - m_surface->GetPixelFormat(m_surface,&dfbFormat); - m_surface->GetCapabilities(m_surface,&dfbCaps); - QImage::Format format = QDirectFbConvenience::imageFormatFromSurfaceFormat(dfbFormat, dfbCaps); - int w, h; - m_surface->GetSize(m_surface,&w,&h); - m_image = QImage(static_cast(mem),w,h,bpl,format); - } else { - DirectFBError("Failed to lock image", result); - } - - return &m_image; -} - -void QDirectFbBlitter::doUnlock() -{ - m_surface->Unlock(m_surface); -} diff --git a/src/plugins/platforms/directfb/qblitter_directfb.h b/src/plugins/platforms/directfb/qblitter_directfb.h deleted file mode 100644 index 85a303a..0000000 --- a/src/plugins/platforms/directfb/qblitter_directfb.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef QDIRECTFBBLITTER_H -#define QDIRECTFBBLITTER_H - -#include "qdirectfbconvenience.h" - -#include - -#include - -class QDirectFbBlitter : public QBlittable -{ -public: - QDirectFbBlitter(const QSize &size, IDirectFBSurface *surface = 0); - virtual ~QDirectFbBlitter(); - - virtual void fillRect(const QRectF &rect, const QColor &color); - virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect); - -protected: - virtual QImage *doLock(); - virtual void doUnlock(); - - IDirectFBSurface *m_surface; - QImage m_image; - - friend class QDirectFbConvenience; -}; - -#endif // QDIRECTFBBLITTER_H diff --git a/src/plugins/platforms/directfb/qdirectfbblitter.cpp b/src/plugins/platforms/directfb/qdirectfbblitter.cpp new file mode 100644 index 0000000..15bb18b --- /dev/null +++ b/src/plugins/platforms/directfb/qdirectfbblitter.cpp @@ -0,0 +1,114 @@ +#include "qdirectfbblitter.h" +#include "qdirectfbconvenience.h" + +#include + +#include + +#include + +QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, IDirectFBSurface *surface) + : QBlittable(rect, QBlittable::Capabilities(QBlittable::SolidRectCapability + |QBlittable::SourcePixmapCapability + |QBlittable::SourceOverPixmapCapability + |QBlittable::SourceOverScaledPixmapCapability)) +{ + if (surface) { + m_surface = surface; + } else { + DFBSurfaceDescription surfaceDesc; + memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription)); + surfaceDesc.width = rect.width(); + surfaceDesc.height = rect.height(); + surfaceDesc.caps = DSCAPS_PREMULTIPLIED; + surfaceDesc.pixelformat = DSPF_ARGB; + surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT); + + IDirectFB *dfb = QDirectFbConvenience::dfbInterface(); + dfb->CreateSurface(dfb,&surfaceDesc, &m_surface); + m_surface->Clear(m_surface,0,0,0,0); + } + +} + +QDirectFbBlitter::~QDirectFbBlitter() +{ + unlock(); + m_surface->Release(m_surface); +} + +void QDirectFbBlitter::fillRect(const QRectF &rect, const QColor &color) +{ + m_surface->SetColor(m_surface, color.red(), color.green(), color.blue(), color.alpha()); +// When the blitter api supports non opaque blits, also remember to change +// qpixmap_blitter.cpp::fill +// DFBSurfaceDrawingFlags drawingFlags = color.alpha() ? DSDRAW_BLEND : DSDRAW_NOFX; +// m_surface->SetDrawingFlags(m_surface, drawingFlags); + m_surface->SetDrawingFlags(m_surface, DSDRAW_NOFX); + m_surface->FillRectangle(m_surface, rect.x(), rect.y(), + rect.width(), rect.height()); +} + +void QDirectFbBlitter::drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &srcRect) +{ + QPixmapData *data = pixmap.pixmapData(); + Q_ASSERT(data->width() && data->height()); + Q_ASSERT(data->classId() == QPixmapData::BlitterClass); + QBlittablePixmapData *blitPm = static_cast(data); + QDirectFbBlitter *dfbBlitter = static_cast(blitPm->blittable()); + dfbBlitter->unlock(); + + IDirectFBSurface *s = dfbBlitter->m_surface; + + DFBSurfaceBlittingFlags blittingFlags = DSBLIT_NOFX; + DFBSurfacePorterDuffRule porterDuff = DSPD_SRC; + if (pixmap.hasAlpha()) { + blittingFlags = DSBLIT_BLEND_ALPHACHANNEL; + porterDuff = DSPD_SRC_OVER; + } + + m_surface->SetBlittingFlags(m_surface, DFBSurfaceBlittingFlags(blittingFlags)); + m_surface->SetPorterDuff(m_surface,porterDuff); + m_surface->SetDstBlendFunction(m_surface,DSBF_INVSRCALPHA); + + const DFBRectangle sRect = { srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height() }; + + DFBResult result; + if (rect.width() == srcRect.width() && rect.height() == srcRect.height()) + result = m_surface->Blit(m_surface, s, &sRect, rect.x(), rect.y()); + else { + const DFBRectangle dRect = { rect.x(), rect.y(), rect.width(), rect.height() }; + result = m_surface->StretchBlit(m_surface, s, &sRect, &dRect); + } + if (result != DFB_OK) + DirectFBError("QDirectFBBlitter::drawPixmap()", result); +} + +QImage *QDirectFbBlitter::doLock() +{ + Q_ASSERT(m_surface); + Q_ASSERT(size().isValid()); + + void *mem; + int bpl; + const DFBResult result = m_surface->Lock(m_surface, DFBSurfaceLockFlags(DSLF_WRITE|DSLF_READ), static_cast(&mem), &bpl); + if (result == DFB_OK) { + DFBSurfacePixelFormat dfbFormat; + DFBSurfaceCapabilities dfbCaps; + m_surface->GetPixelFormat(m_surface,&dfbFormat); + m_surface->GetCapabilities(m_surface,&dfbCaps); + QImage::Format format = QDirectFbConvenience::imageFormatFromSurfaceFormat(dfbFormat, dfbCaps); + int w, h; + m_surface->GetSize(m_surface,&w,&h); + m_image = QImage(static_cast(mem),w,h,bpl,format); + } else { + DirectFBError("Failed to lock image", result); + } + + return &m_image; +} + +void QDirectFbBlitter::doUnlock() +{ + m_surface->Unlock(m_surface); +} diff --git a/src/plugins/platforms/directfb/qdirectfbblitter.h b/src/plugins/platforms/directfb/qdirectfbblitter.h new file mode 100644 index 0000000..85a303a --- /dev/null +++ b/src/plugins/platforms/directfb/qdirectfbblitter.h @@ -0,0 +1,29 @@ +#ifndef QDIRECTFBBLITTER_H +#define QDIRECTFBBLITTER_H + +#include "qdirectfbconvenience.h" + +#include + +#include + +class QDirectFbBlitter : public QBlittable +{ +public: + QDirectFbBlitter(const QSize &size, IDirectFBSurface *surface = 0); + virtual ~QDirectFbBlitter(); + + virtual void fillRect(const QRectF &rect, const QColor &color); + virtual void drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &subrect); + +protected: + virtual QImage *doLock(); + virtual void doUnlock(); + + IDirectFBSurface *m_surface; + QImage m_image; + + friend class QDirectFbConvenience; +}; + +#endif // QDIRECTFBBLITTER_H diff --git a/src/plugins/platforms/directfb/qdirectfbconvenience.cpp b/src/plugins/platforms/directfb/qdirectfbconvenience.cpp index 8594c09..adf9687 100644 --- a/src/plugins/platforms/directfb/qdirectfbconvenience.cpp +++ b/src/plugins/platforms/directfb/qdirectfbconvenience.cpp @@ -1,5 +1,5 @@ #include "qdirectfbconvenience.h" -#include "qblitter_directfb.h" +#include "qdirectfbblitter.h" #include diff --git a/src/plugins/platforms/directfb/qdirectfbcursor.cpp b/src/plugins/platforms/directfb/qdirectfbcursor.cpp index bb7088f..2edae45 100644 --- a/src/plugins/platforms/directfb/qdirectfbcursor.cpp +++ b/src/plugins/platforms/directfb/qdirectfbcursor.cpp @@ -1,9 +1,6 @@ #include "qdirectfbcursor.h" -#include "qblitter_directfb.h" -#include "qplatformintegration_directfb.h" #include "qdirectfbconvenience.h" -#include QDirectFBCursor::QDirectFBCursor(QPlatformScreen* screen) : QGraphicsSystemCursor(screen), surface(0) diff --git a/src/plugins/platforms/directfb/qdirectfbintegration.cpp b/src/plugins/platforms/directfb/qdirectfbintegration.cpp new file mode 100644 index 0000000..b096081 --- /dev/null +++ b/src/plugins/platforms/directfb/qdirectfbintegration.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdirectfbintegration.h" +#include "qdirectfbwindowsurface.h" +#include "qdirectfbblitter.h" +#include "qdirectfbconvenience.h" +#include "qdirectfbcursor.h" +#include "qdirectfbwindow.h" + +#include +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QDirectFbScreen::QDirectFbScreen(int display) + :QPlatformScreen() +{ + m_layer = QDirectFbConvenience::dfbDisplayLayer(display); + m_layer->SetCooperativeLevel(m_layer,DLSCL_SHARED); + + DFBDisplayLayerConfig config; + m_layer->GetConfiguration(m_layer, &config); + + m_format = QDirectFbConvenience::imageFormatFromSurfaceFormat(config.pixelformat, config.surface_caps); + m_geometry = QRect(0,0,config.width,config.height); + const int dpi = 72; + const qreal inch = 25.4; + m_depth = 32; + m_physicalSize = QSize(qRound(config.width * inch / dpi), qRound(config.height *inch / dpi)); + + cursor = new QDirectFBCursor(this); +} + +QDirectFbScreen::~QDirectFbScreen() +{ +} + +QDirectFbIntegration::QDirectFbIntegration() +{ + const QStringList args = QCoreApplication::arguments(); + int argc = args.size(); + char **argv = new char*[argc]; + + for (int i = 0; i < argc; ++i) + argv[i] = qstrdup(args.at(i).toLocal8Bit().constData()); + + DFBResult result = DirectFBInit(&argc, &argv); + if (result != DFB_OK) { + DirectFBError("QDirectFBScreen: error initializing DirectFB", + result); + } + delete[] argv; + + QDirectFbScreen *primaryScreen = new QDirectFbScreen(0); + mScreens.append(primaryScreen); +} + +QPixmapData *QDirectFbIntegration::createPixmapData(QPixmapData::PixelType type) const +{ + if (type == QPixmapData::BitmapType) + return new QRasterPixmapData(type); + else + return new QBlittablePixmapData(type); +} + +QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWidget *widget, WId winId) const +{ + Q_UNUSED(winId); + return new QDirectFbWindow(widget); +} + +QWindowSurface *QDirectFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId winId) const +{ + return new QDirectFbWindowSurface(widget,winId); +} + +QBlittable *QDirectFbIntegration::createBlittable(const QSize &size) const +{ + return new QDirectFbBlitter(size); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/directfb/qdirectfbintegration.h b/src/plugins/platforms/directfb/qdirectfbintegration.h new file mode 100644 index 0000000..808bc9d --- /dev/null +++ b/src/plugins/platforms/directfb/qdirectfbintegration.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLATFORMINTEGRATION_DIRECTFB_H +#define QPLATFORMINTEGRATION_DIRECTFB_H + +#include "qdirectfbinput.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QDirectFBCursor; + +class QDirectFbScreen : public QPlatformScreen +{ +Q_OBJECT +public: + QDirectFbScreen(int display); + ~QDirectFbScreen(); + + QRect geometry() const { return m_geometry; } + int depth() const { return m_depth; } + QImage::Format format() const { return m_format; } + QSize physicalSize() const { return m_physicalSize; } + +public: + QRect m_geometry; + int m_depth; + QImage::Format m_format; + QSize m_physicalSize; + + IDirectFBDisplayLayer *m_layer; + +private: + QDirectFBCursor * cursor; + +}; + +class QDirectFbIntegration : public QPlatformIntegration +{ +public: + QDirectFbIntegration(); + + QPixmapData *createPixmapData(QPixmapData::PixelType type) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const; + QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; + QBlittable *createBlittable(const QSize &size) const; + + QList screens() const { return mScreens; } + + + +private: + QList mScreens; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/directfb/qdirectfbwindowsurface.cpp b/src/plugins/platforms/directfb/qdirectfbwindowsurface.cpp new file mode 100644 index 0000000..4ca9a72 --- /dev/null +++ b/src/plugins/platforms/directfb/qdirectfbwindowsurface.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdirectfbwindowsurface.h" +#include "qdirectfbintegration.h" +#include "qdirectfbblitter.h" +#include "qdirectfbconvenience.h" +#include + +#include + +QT_BEGIN_NAMESPACE + +QDirectFbWindowSurface::QDirectFbWindowSurface(QWidget *window, WId wId) + : QWindowSurface(window), m_pixmap(0), m_pmdata(0), m_dfbSurface(0) +{ + + IDirectFBDisplayLayer *layer = QDirectFbConvenience::dfbDisplayLayer(); + + DFBWindowID id(wId); + IDirectFBWindow *dfbWindow; + + layer->GetWindow(layer,id,&dfbWindow); + + dfbWindow->GetSurface(dfbWindow,&m_dfbSurface); +//WRONGSIZE + QDirectFbBlitter *blitter = new QDirectFbBlitter(window->rect().size(), m_dfbSurface); + m_pmdata = new QBlittablePixmapData(QPixmapData::PixmapType); + m_pmdata->setBlittable(blitter); + m_pixmap = new QPixmap(m_pmdata); +} + +QDirectFbWindowSurface::~QDirectFbWindowSurface() +{ + +} + +QPaintDevice *QDirectFbWindowSurface::paintDevice() +{ + return m_pixmap; +} + +void QDirectFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(widget); + m_pmdata->blittable()->unlock(); + + QVector rects = region.rects(); + for (int i = 0 ; i < rects.size(); i++) { + const QRect rect = rects.at(i); + DFBRegion dfbReg = { rect.x() + offset.x(),rect.y() + offset.y(),rect.right() + offset.x(),rect.bottom() + offset.y()}; + m_dfbSurface->Flip(m_dfbSurface, &dfbReg, DFBSurfaceFlipFlags(DSFLIP_BLIT|DSFLIP_ONSYNC)); + } +} + +void QDirectFbWindowSurface::resize(const QSize &size) +{ + QWindowSurface::resize(size); + + //Have to add 1 ref ass it will be removed by deleting the old blitter in setBlittable + m_dfbSurface->AddRef(m_dfbSurface); + QDirectFbBlitter *blitter = new QDirectFbBlitter(size,m_dfbSurface); + m_pmdata->setBlittable(blitter); +} + +static inline void scrollSurface(IDirectFBSurface *surface, const QRect &r, int dx, int dy) +{ + const DFBRectangle rect = { r.x(), r.y(), r.width(), r.height() }; + surface->Blit(surface, surface, &rect, r.x() + dx, r.y() + dy); + const DFBRegion region = { rect.x + dx, rect.y + dy, r.right() + dx, r.bottom() + dy }; + surface->Flip(surface, ®ion, DFBSurfaceFlipFlags(DSFLIP_BLIT)); +} + +bool QDirectFbWindowSurface::scroll(const QRegion &area, int dx, int dy) +{ + m_pmdata->blittable()->unlock(); + + if (!m_dfbSurface || area.isEmpty()) + return false; + m_dfbSurface->SetBlittingFlags(m_dfbSurface, DSBLIT_NOFX); + if (area.rectCount() == 1) { + scrollSurface(m_dfbSurface, area.boundingRect(), dx, dy); + } else { + const QVector rects = area.rects(); + const int n = rects.size(); + for (int i=0; i +#include + +#include + +QT_BEGIN_NAMESPACE + +class QDirectFbWindowSurface : public QWindowSurface +{ +public: + QDirectFbWindowSurface(QWidget *window, WId wid); + ~QDirectFbWindowSurface(); + + QPaintDevice *paintDevice(); + void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); + void resize (const QSize &size); + bool scroll(const QRegion &area, int dx, int dy); + + void beginPaint(const QRegion ®ion); + void endPaint(const QRegion ®ion); + +private: + void lockSurfaceToImage(); + + QPixmap *m_pixmap; + QBlittablePixmapData *m_pmdata; + + IDirectFBSurface *m_dfbSurface; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/directfb/qplatformintegration_directfb.cpp b/src/plugins/platforms/directfb/qplatformintegration_directfb.cpp deleted file mode 100644 index 5f428ef..0000000 --- a/src/plugins/platforms/directfb/qplatformintegration_directfb.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformintegration_directfb.h" -#include "qwindowsurface_directfb.h" -#include "qblitter_directfb.h" -#include "qdirectfbconvenience.h" -#include "qdirectfbcursor.h" -#include "qdirectfbwindow.h" - -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QDirectFbScreen::QDirectFbScreen(int display) - :QPlatformScreen() -{ - m_layer = QDirectFbConvenience::dfbDisplayLayer(display); - m_layer->SetCooperativeLevel(m_layer,DLSCL_SHARED); - - DFBDisplayLayerConfig config; - m_layer->GetConfiguration(m_layer, &config); - - m_format = QDirectFbConvenience::imageFormatFromSurfaceFormat(config.pixelformat, config.surface_caps); - m_geometry = QRect(0,0,config.width,config.height); - const int dpi = 72; - const qreal inch = 25.4; - m_depth = 32; - m_physicalSize = QSize(qRound(config.width * inch / dpi), qRound(config.height *inch / dpi)); - - cursor = new QDirectFBCursor(this); -} - -QDirectFbScreen::~QDirectFbScreen() -{ -} - -QDirectFbIntegration::QDirectFbIntegration() -{ - const QStringList args = QCoreApplication::arguments(); - int argc = args.size(); - char **argv = new char*[argc]; - - for (int i = 0; i < argc; ++i) - argv[i] = qstrdup(args.at(i).toLocal8Bit().constData()); - - DFBResult result = DirectFBInit(&argc, &argv); - if (result != DFB_OK) { - DirectFBError("QDirectFBScreen: error initializing DirectFB", - result); - } - delete[] argv; - - QDirectFbScreen *primaryScreen = new QDirectFbScreen(0); - mScreens.append(primaryScreen); -} - -QPixmapData *QDirectFbIntegration::createPixmapData(QPixmapData::PixelType type) const -{ - if (type == QPixmapData::BitmapType) - return new QRasterPixmapData(type); - else - return new QBlittablePixmapData(type); -} - -QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWidget *widget, WId winId) const -{ - Q_UNUSED(winId); - return new QDirectFbWindow(widget); -} - -QWindowSurface *QDirectFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId winId) const -{ - return new QDirectFbWindowSurface(widget,winId); -} - -QBlittable *QDirectFbIntegration::createBlittable(const QSize &size) const -{ - return new QDirectFbBlitter(size); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/directfb/qplatformintegration_directfb.h b/src/plugins/platforms/directfb/qplatformintegration_directfb.h deleted file mode 100644 index a8489c0..0000000 --- a/src/plugins/platforms/directfb/qplatformintegration_directfb.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPLATFORMINTEGRATION_DIRECTFB_H -#define QPLATFORMINTEGRATION_DIRECTFB_H - -#include "qdirectfbinput.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QDirectFBCursor; - -class QDirectFbScreen : public QPlatformScreen -{ -public: - QDirectFbScreen(int display); - ~QDirectFbScreen(); - - QRect geometry() const { return m_geometry; } - int depth() const { return m_depth; } - QImage::Format format() const { return m_format; } - QSize physicalSize() const { return m_physicalSize; } - -public: - QRect m_geometry; - int m_depth; - QImage::Format m_format; - QSize m_physicalSize; - - IDirectFBDisplayLayer *m_layer; - -private: - QDirectFBCursor * cursor; - -}; - -class QDirectFbIntegration : public QPlatformIntegration -{ -public: - QDirectFbIntegration(); - - QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const; - QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; - QBlittable *createBlittable(const QSize &size) const; - - QList screens() const { return mScreens; } - - - -private: - QList mScreens; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/platforms/directfb/qwindowsurface_directfb.cpp b/src/plugins/platforms/directfb/qwindowsurface_directfb.cpp deleted file mode 100644 index e978cae..0000000 --- a/src/plugins/platforms/directfb/qwindowsurface_directfb.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtOpenVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwindowsurface_directfb.h" -#include "qplatformintegration_directfb.h" -#include "qblitter_directfb.h" -#include "qdirectfbconvenience.h" -#include - -#include - -QT_BEGIN_NAMESPACE - -QDirectFbWindowSurface::QDirectFbWindowSurface(QWidget *window, WId wId) - : QWindowSurface(window), m_pixmap(0), m_pmdata(0), m_dfbSurface(0) -{ - - IDirectFBDisplayLayer *layer = QDirectFbConvenience::dfbDisplayLayer(); - - DFBWindowID id(wId); - IDirectFBWindow *dfbWindow; - - layer->GetWindow(layer,id,&dfbWindow); - - dfbWindow->GetSurface(dfbWindow,&m_dfbSurface); -//WRONGSIZE - QDirectFbBlitter *blitter = new QDirectFbBlitter(window->rect().size(), m_dfbSurface); - m_pmdata = new QBlittablePixmapData(QPixmapData::PixmapType); - m_pmdata->setBlittable(blitter); - m_pixmap = new QPixmap(m_pmdata); -} - -QDirectFbWindowSurface::~QDirectFbWindowSurface() -{ - -} - -QPaintDevice *QDirectFbWindowSurface::paintDevice() -{ - return m_pixmap; -} - -void QDirectFbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) -{ - Q_UNUSED(widget); - m_pmdata->blittable()->unlock(); - - QVector rects = region.rects(); - for (int i = 0 ; i < rects.size(); i++) { - const QRect rect = rects.at(i); - DFBRegion dfbReg = { rect.x() + offset.x(),rect.y() + offset.y(),rect.right() + offset.x(),rect.bottom() + offset.y()}; - m_dfbSurface->Flip(m_dfbSurface, &dfbReg, DFBSurfaceFlipFlags(DSFLIP_BLIT|DSFLIP_ONSYNC)); - } -} - -void QDirectFbWindowSurface::resize(const QSize &size) -{ - QWindowSurface::resize(size); - - //Have to add 1 ref ass it will be removed by deleting the old blitter in setBlittable - m_dfbSurface->AddRef(m_dfbSurface); - QDirectFbBlitter *blitter = new QDirectFbBlitter(size,m_dfbSurface); - m_pmdata->setBlittable(blitter); -} - -static inline void scrollSurface(IDirectFBSurface *surface, const QRect &r, int dx, int dy) -{ - const DFBRectangle rect = { r.x(), r.y(), r.width(), r.height() }; - surface->Blit(surface, surface, &rect, r.x() + dx, r.y() + dy); - const DFBRegion region = { rect.x + dx, rect.y + dy, r.right() + dx, r.bottom() + dy }; - surface->Flip(surface, ®ion, DFBSurfaceFlipFlags(DSFLIP_BLIT)); -} - -bool QDirectFbWindowSurface::scroll(const QRegion &area, int dx, int dy) -{ - m_pmdata->blittable()->unlock(); - - if (!m_dfbSurface || area.isEmpty()) - return false; - m_dfbSurface->SetBlittingFlags(m_dfbSurface, DSBLIT_NOFX); - if (area.rectCount() == 1) { - scrollSurface(m_dfbSurface, area.boundingRect(), dx, dy); - } else { - const QVector rects = area.rects(); - const int n = rects.size(); - for (int i=0; i -#include - -#include - -QT_BEGIN_NAMESPACE - -class QDirectFbWindowSurface : public QWindowSurface -{ -public: - QDirectFbWindowSurface(QWidget *window, WId wid); - ~QDirectFbWindowSurface(); - - QPaintDevice *paintDevice(); - void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void resize (const QSize &size); - bool scroll(const QRegion &area, int dx, int dy); - - void beginPaint(const QRegion ®ion); - void endPaint(const QRegion ®ion); - -private: - void lockSurfaceToImage(); - - QPixmap *m_pixmap; - QBlittablePixmapData *m_pmdata; - - IDirectFBSurface *m_dfbSurface; -}; - -QT_END_NAMESPACE - -#endif -- cgit v0.12 From a43355f7d10a72f60719f7e5a617bcd0031f8fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 19 Apr 2010 12:54:09 +0200 Subject: QPlatformScreen now has default implementation for physicalSize assuming dpi = 100. This also simplifies minimal slightly. Also use propper apis in qfont for default dpi by using QPlatformScreen --- src/gui/kernel/qplatformscreen_lite.cpp | 8 ++++++++ src/gui/kernel/qplatformscreen_lite.h | 2 +- src/gui/text/qfont.cpp | 14 ++++++++++++-- .../platforms/minimal/qplatformintegration_minimal.cpp | 1 - .../platforms/minimal/qplatformintegration_minimal.h | 1 - 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qplatformscreen_lite.cpp b/src/gui/kernel/qplatformscreen_lite.cpp index 4492463..4c0a02b 100644 --- a/src/gui/kernel/qplatformscreen_lite.cpp +++ b/src/gui/kernel/qplatformscreen_lite.cpp @@ -56,3 +56,11 @@ QWidget *QPlatformScreen::topLevelAt(const QPoint & pos) const return 0; } +QSize QPlatformScreen::physicalSize() const +{ + static const int dpi = 100; + int width = geometry().width() / dpi * qreal(25.4) ; + int height = geometry().height() / dpi * qreal(25.4) ; + return QSize(width,height); +} + diff --git a/src/gui/kernel/qplatformscreen_lite.h b/src/gui/kernel/qplatformscreen_lite.h index cae5f42..7d0e28d 100644 --- a/src/gui/kernel/qplatformscreen_lite.h +++ b/src/gui/kernel/qplatformscreen_lite.h @@ -62,7 +62,7 @@ public: virtual QRect availableGeometry() const {return geometry();}; virtual int depth() const = 0; virtual QImage::Format format() const = 0; - virtual QSize physicalSize() const = 0; + virtual QSize physicalSize() const; virtual void setDirty(const QRect &) {} virtual QWidget *topLevelAt(const QPoint &point) const; }; diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 01e4ef6..81d431c 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -75,6 +75,10 @@ #ifdef Q_OS_SYMBIAN #include "qt_s60_p.h" #endif +#ifdef Q_WS_LITE +#include +#include +#endif #include @@ -173,7 +177,10 @@ Q_GUI_EXPORT int qt_defaultDpiX() screen = subScreens.at(0); dpi = qRound(screen->width() / (screen->physicalWidth() / qreal(25.4))); #elif defined(Q_WS_LITE) - dpi = 72; + QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0); + const QSize screenSize = screen->geometry().size(); + const QSize physicalSize = screen->physicalSize(); + dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4))); #elif defined(Q_OS_SYMBIAN) dpi = S60->defaultDpiX; #endif // Q_WS_X11 @@ -203,7 +210,10 @@ Q_GUI_EXPORT int qt_defaultDpiY() screen = subScreens.at(0); dpi = qRound(screen->height() / (screen->physicalHeight() / qreal(25.4))); #elif defined(Q_WS_LITE) - dpi = 72; + QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0); + const QSize screenSize = screen->geometry().size(); + const QSize physicalSize = screen->physicalSize(); + dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4))); #elif defined(Q_OS_SYMBIAN) dpi = S60->defaultDpiY; #endif // Q_WS_X11 diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp index 404ffbc..94aa4f3 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp @@ -11,7 +11,6 @@ QMinimalIntegration::QMinimalIntegration() mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320); mPrimaryScreen->mDepth = 16; mPrimaryScreen->mFormat = QImage::Format_RGB16; - mPrimaryScreen->mPhysicalSize = QSize(40, 54); mScreens.append(mPrimaryScreen); } diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.h b/src/plugins/platforms/minimal/qplatformintegration_minimal.h index 2e8a8cf..fefe6c3 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.h +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.h @@ -57,7 +57,6 @@ public: QRect geometry() const { return mGeometry; } int depth() const { return mDepth; } QImage::Format format() const { return mFormat; } - QSize physicalSize() const { return mPhysicalSize; } public: QRect mGeometry; -- cgit v0.12 From 66e4d48129d6baa405ed9a4a22b12913227a8c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 21 Apr 2010 08:28:30 +0200 Subject: Renamed createWindowSurfaceForWindow to createWindowSurface. Gave also a default dpi when there is no platform integration, ie. it has not been initialised yet or is being initialised. --- src/gui/kernel/qplatformintegration_lite.h | 2 +- src/gui/kernel/qwidget_lite.cpp | 2 +- src/gui/painting/qgraphicssystem_lite.cpp | 2 +- src/gui/text/qfont.cpp | 28 +++++++++++++++------- .../platforms/directfb/qdirectfbintegration.cpp | 2 +- .../platforms/directfb/qdirectfbintegration.h | 2 +- .../platforms/linuxfb/qgraphicssystem_linuxfb.cpp | 4 +--- .../platforms/linuxfb/qgraphicssystem_linuxfb.h | 2 +- .../minimal/qplatformintegration_minimal.cpp | 2 +- .../minimal/qplatformintegration_minimal.h | 2 +- src/plugins/platforms/qvfb/qvfbintegration.cpp | 6 ++--- src/plugins/platforms/qvfb/qvfbintegration.h | 2 +- .../testlite/qplatformintegration_testlite.cpp | 4 +--- .../testlite/qplatformintegration_testlite.h | 2 +- src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp | 4 +--- src/plugins/platforms/vnc/qgraphicssystem_vnc.h | 2 +- 16 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/gui/kernel/qplatformintegration_lite.h b/src/gui/kernel/qplatformintegration_lite.h index b13260e..ee6f833 100644 --- a/src/gui/kernel/qplatformintegration_lite.h +++ b/src/gui/kernel/qplatformintegration_lite.h @@ -63,7 +63,7 @@ public: // GraphicsSystem functions virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0; virtual QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const = 0; - virtual QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const = 0; + virtual QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const = 0; virtual QBlittable *createBlittable(const QSize &size) const; // Window System functions diff --git a/src/gui/kernel/qwidget_lite.cpp b/src/gui/kernel/qwidget_lite.cpp index 465dbee..ee1a582 100644 --- a/src/gui/kernel/qwidget_lite.cpp +++ b/src/gui/kernel/qwidget_lite.cpp @@ -77,7 +77,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO Q_ASSERT(platformWindow); if (!surface) { - surface = QApplicationPrivate::platformIntegration()->createWindowSurfaceForWindow(q,platformWindow->winId()); + surface = QApplicationPrivate::platformIntegration()->createWindowSurface(q,platformWindow->winId()); } Q_ASSERT(surface); diff --git a/src/gui/painting/qgraphicssystem_lite.cpp b/src/gui/painting/qgraphicssystem_lite.cpp index 68d880b..1d24129 100644 --- a/src/gui/painting/qgraphicssystem_lite.cpp +++ b/src/gui/painting/qgraphicssystem_lite.cpp @@ -51,7 +51,7 @@ QPixmapData *QLiteGraphicsSystem::createPixmapData(QPixmapData::PixelType type) QWindowSurface *QLiteGraphicsSystem::createWindowSurface(QWidget *widget) const { - return QApplicationPrivate::platformIntegration()->createWindowSurfaceForWindow(widget, widget->winId()); + return QApplicationPrivate::platformIntegration()->createWindowSurface(widget, widget->winId()); } QBlittable *QLiteGraphicsSystem::createBlittable(const QSize &size) const diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 81d431c..2c2ceb1 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -177,10 +177,16 @@ Q_GUI_EXPORT int qt_defaultDpiX() screen = subScreens.at(0); dpi = qRound(screen->width() / (screen->physicalWidth() / qreal(25.4))); #elif defined(Q_WS_LITE) - QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0); - const QSize screenSize = screen->geometry().size(); - const QSize physicalSize = screen->physicalSize(); - dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4))); + QPlatformIntegration *pi = QApplicationPrivate::platformIntegration(); + if (pi) { + QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0); + const QSize screenSize = screen->geometry().size(); + const QSize physicalSize = screen->physicalSize(); + dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4))); + } else { + //PI has not been initialised, or it is being initialised. Give a default dpi + dpi = 100; + } #elif defined(Q_OS_SYMBIAN) dpi = S60->defaultDpiX; #endif // Q_WS_X11 @@ -210,10 +216,16 @@ Q_GUI_EXPORT int qt_defaultDpiY() screen = subScreens.at(0); dpi = qRound(screen->height() / (screen->physicalHeight() / qreal(25.4))); #elif defined(Q_WS_LITE) - QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0); - const QSize screenSize = screen->geometry().size(); - const QSize physicalSize = screen->physicalSize(); - dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4))); + QPlatformIntegration *pi = QApplicationPrivate::platformIntegration(); + if (pi) { + QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0); + const QSize screenSize = screen->geometry().size(); + const QSize physicalSize = screen->physicalSize(); + dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4))); + } else { + //PI has not been initialised, or it is being initialised. Give a default dpi + dpi = 100; + } #elif defined(Q_OS_SYMBIAN) dpi = S60->defaultDpiY; #endif // Q_WS_X11 diff --git a/src/plugins/platforms/directfb/qdirectfbintegration.cpp b/src/plugins/platforms/directfb/qdirectfbintegration.cpp index b096081..60fce7e 100644 --- a/src/plugins/platforms/directfb/qdirectfbintegration.cpp +++ b/src/plugins/platforms/directfb/qdirectfbintegration.cpp @@ -112,7 +112,7 @@ QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWidget *widget, WId return new QDirectFbWindow(widget); } -QWindowSurface *QDirectFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId winId) const +QWindowSurface *QDirectFbIntegration::createWindowSurface(QWidget *widget, WId winId) const { return new QDirectFbWindowSurface(widget,winId); } diff --git a/src/plugins/platforms/directfb/qdirectfbintegration.h b/src/plugins/platforms/directfb/qdirectfbintegration.h index 808bc9d..c0e770f 100644 --- a/src/plugins/platforms/directfb/qdirectfbintegration.h +++ b/src/plugins/platforms/directfb/qdirectfbintegration.h @@ -84,7 +84,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const; - QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; QBlittable *createBlittable(const QSize &size) const; QList screens() const { return mScreens; } diff --git a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp index 25cdc7b..acc254a 100644 --- a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp +++ b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.cpp @@ -786,10 +786,8 @@ QPixmapData *QLinuxFbIntegration::createPixmapData(QPixmapData::PixelType type) return new QRasterPixmapData(type); } -QWindowSurface *QLinuxFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const +QWindowSurface *QLinuxFbIntegration::createWindowSurface(QWidget *widget, WId) const { - if (widget->windowType() == Qt::Desktop) - return 0; // Don't create an explicit window surface for the destkop. QFbWindowSurface * surface = new QFbWindowSurface(mPrimaryScreen, widget); return surface; diff --git a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h index 7d4c031..dc61df5 100644 --- a/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h +++ b/src/plugins/platforms/linuxfb/qgraphicssystem_linuxfb.h @@ -78,7 +78,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId WinId) const; - QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId WinId) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId WinId) const; QList screens() const { return mScreens; } diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp index 94aa4f3..73e025c 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.cpp @@ -26,7 +26,7 @@ QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWidget *widget, WId return new QPlatformWindow(widget); } -QWindowSurface *QMinimalIntegration::createWindowSurfaceForWindow(QWidget *widget, WId winId) const +QWindowSurface *QMinimalIntegration::createWindowSurface(QWidget *widget, WId winId) const { Q_UNUSED(winId); return new QMinimalWindowSurface(widget); diff --git a/src/plugins/platforms/minimal/qplatformintegration_minimal.h b/src/plugins/platforms/minimal/qplatformintegration_minimal.h index fefe6c3..a2f7449 100644 --- a/src/plugins/platforms/minimal/qplatformintegration_minimal.h +++ b/src/plugins/platforms/minimal/qplatformintegration_minimal.h @@ -72,7 +72,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; - QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; QList screens() const { return mScreens; } diff --git a/src/plugins/platforms/qvfb/qvfbintegration.cpp b/src/plugins/platforms/qvfb/qvfbintegration.cpp index 2a877e0..e22c724 100644 --- a/src/plugins/platforms/qvfb/qvfbintegration.cpp +++ b/src/plugins/platforms/qvfb/qvfbintegration.cpp @@ -421,10 +421,8 @@ QPixmapData *QVFbIntegration::createPixmapData(QPixmapData::PixelType type) cons return new QRasterPixmapData(type); } -QWindowSurface *QVFbIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const +QWindowSurface *QVFbIntegration::createWindowSurface(QWidget *widget, WId) const { - if (widget->windowType() == Qt::Desktop) - return 0; // Don't create an explicit window surface for the destkop. return new QVFbWindowSurface(mPrimaryScreen, widget); } @@ -436,4 +434,4 @@ QPlatformWindow *QVFbIntegration::createPlatformWindow(QWidget *widget, WId) con QT_END_NAMESPACE -#include "qgraphicssystem_qvfb.moc" +#include "qvfbintegration.moc" diff --git a/src/plugins/platforms/qvfb/qvfbintegration.h b/src/plugins/platforms/qvfb/qvfbintegration.h index 1207678..ab44d46 100644 --- a/src/plugins/platforms/qvfb/qvfbintegration.h +++ b/src/plugins/platforms/qvfb/qvfbintegration.h @@ -80,7 +80,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; - QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; QList screens() const { return mScreens; } diff --git a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp index f13951d..f657617 100644 --- a/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp +++ b/src/plugins/platforms/testlite/qplatformintegration_testlite.cpp @@ -103,10 +103,8 @@ QPixmapData *QTestLiteIntegration::createPixmapData(QPixmapData::PixelType type) return new QRasterPixmapData(type); } -QWindowSurface *QTestLiteIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const +QWindowSurface *QTestLiteIntegration::createWindowSurface(QWidget *widget, WId) const { - if (widget->windowType() == Qt::Desktop) - return 0; // Don't create an explicit window surface for the destkop. return new QTestLiteWindowSurface(mPrimaryScreen, widget); } diff --git a/src/plugins/platforms/testlite/qplatformintegration_testlite.h b/src/plugins/platforms/testlite/qplatformintegration_testlite.h index bd27d89..729e74f 100644 --- a/src/plugins/platforms/testlite/qplatformintegration_testlite.h +++ b/src/plugins/platforms/testlite/qplatformintegration_testlite.h @@ -75,7 +75,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; - QWindowSurface *createWindowSurfaceForWindow(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; diff --git a/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp b/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp index cbc8bbd..a872991 100644 --- a/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp +++ b/src/plugins/platforms/vnc/qgraphicssystem_vnc.cpp @@ -114,10 +114,8 @@ QPixmapData *QVNCIntegration::createPixmapData(QPixmapData::PixelType type) cons // return surface; // } -QWindowSurface *QVNCIntegration::createWindowSurfaceForWindow(QWidget *widget, WId) const +QWindowSurface *QVNCIntegration::createWindowSurface(QWidget *widget, WId) 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); return surface; diff --git a/src/plugins/platforms/vnc/qgraphicssystem_vnc.h b/src/plugins/platforms/vnc/qgraphicssystem_vnc.h index 887ccc3..524b888 100644 --- a/src/plugins/platforms/vnc/qgraphicssystem_vnc.h +++ b/src/plugins/platforms/vnc/qgraphicssystem_vnc.h @@ -80,7 +80,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; - QWindowSurface *createWindowSurfaceForWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; QList screens() const { return mScreens; } -- cgit v0.12