summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2010-12-08 12:11:30 (GMT)
committerJørgen Lind <jorgen.lind@nokia.com>2011-01-04 14:18:21 (GMT)
commit337f75854883fb93e1b4f41e10c79dc7c352f4a6 (patch)
tree44ad66aa2059a8a29b66f32bce93ec17a8ae7403
parentf6c5b16768d45f196bab0a2766d4be6027991e08 (diff)
downloadQt-337f75854883fb93e1b4f41e10c79dc7c352f4a6.zip
Qt-337f75854883fb93e1b4f41e10c79dc7c352f4a6.tar.gz
Qt-337f75854883fb93e1b4f41e10c79dc7c352f4a6.tar.bz2
Refactoring of testlite to conform with Lighthouse structure
-rw-r--r--src/plugins/platforms/testlite/qglxintegration.cpp75
-rw-r--r--src/plugins/platforms/testlite/qglxintegration.h18
-rw-r--r--src/plugins/platforms/testlite/qtestlitecursor.cpp200
-rw-r--r--src/plugins/platforms/testlite/qtestlitecursor.h69
-rw-r--r--src/plugins/platforms/testlite/qtestliteintegration.cpp65
-rw-r--r--src/plugins/platforms/testlite/qtestliteintegration.h29
-rw-r--r--src/plugins/platforms/testlite/qtestlitescreen.cpp430
-rw-r--r--src/plugins/platforms/testlite/qtestlitescreen.h103
-rw-r--r--src/plugins/platforms/testlite/qtestlitewindow.cpp871
-rw-r--r--src/plugins/platforms/testlite/qtestlitewindow.h96
-rw-r--r--src/plugins/platforms/testlite/qtestlitewindowsurface.cpp34
-rw-r--r--src/plugins/platforms/testlite/qtestlitewindowsurface.h2
-rw-r--r--src/plugins/platforms/testlite/testlite.pro9
13 files changed, 1005 insertions, 996 deletions
diff --git a/src/plugins/platforms/testlite/qglxintegration.cpp b/src/plugins/platforms/testlite/qglxintegration.cpp
index a4b7b69..1dffb3e 100644
--- a/src/plugins/platforms/testlite/qglxintegration.cpp
+++ b/src/plugins/platforms/testlite/qglxintegration.cpp
@@ -44,6 +44,7 @@
#include <QGLFormat>
#include "qtestlitewindow.h"
+#include "qtestlitescreen.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -57,9 +58,9 @@
QT_BEGIN_NAMESPACE
-QMutex QGLXGLContext::m_defaultSharedContextMutex(QMutex::Recursive);
+QMutex QGLXContext::m_defaultSharedContextMutex(QMutex::Recursive);
-QVector<int> QGLXGLContext::buildSpec(const QPlatformWindowFormat &format)
+QVector<int> QGLXContext::buildSpec(const QPlatformWindowFormat &format)
{
QVector<int> spec(48);
int i = 0;
@@ -111,7 +112,7 @@ QVector<int> QGLXGLContext::buildSpec(const QPlatformWindowFormat &format)
return spec;
}
-GLXFBConfig QGLXGLContext::findConfig(const MyDisplay *xd, const QPlatformWindowFormat &format)
+GLXFBConfig QGLXContext::findConfig(const QTestLiteScreen *screen, const QPlatformWindowFormat &format)
{
bool reduced = true;
GLXFBConfig chosenConfig = 0;
@@ -120,7 +121,7 @@ GLXFBConfig QGLXGLContext::findConfig(const MyDisplay *xd, const QPlatformWindow
QVector<int> spec = buildSpec(reducedFormat);
int confcount = 0;
GLXFBConfig *configs;
- configs = glXChooseFBConfig(xd->display,xd->screen,spec.constData(),&confcount);
+ configs = glXChooseFBConfig(screen->display(),screen->xScreenNumber(),spec.constData(),&confcount);
if (confcount)
{
for (int i = 0; i < confcount; i++) {
@@ -128,7 +129,7 @@ GLXFBConfig QGLXGLContext::findConfig(const MyDisplay *xd, const QPlatformWindow
// Make sure we try to get an ARGB visual if the format asked for an alpha:
if (reducedFormat.alpha()) {
int alphaSize;
- glXGetFBConfigAttrib(xd->display,configs[i],GLX_ALPHA_SIZE,&alphaSize);
+ glXGetFBConfigAttrib(screen->display(),configs[i],GLX_ALPHA_SIZE,&alphaSize);
if (alphaSize > 0)
break;
} else {
@@ -147,14 +148,14 @@ GLXFBConfig QGLXGLContext::findConfig(const MyDisplay *xd, const QPlatformWindow
return chosenConfig;
}
-XVisualInfo *QGLXGLContext::findVisualInfo(const MyDisplay *xd, const QPlatformWindowFormat &format)
+XVisualInfo *QGLXContext::findVisualInfo(const QTestLiteScreen *screen, const QPlatformWindowFormat &format)
{
- GLXFBConfig config = QGLXGLContext::findConfig(xd,format);
- XVisualInfo *visualInfo = glXGetVisualFromFBConfig(xd->display,config);
+ GLXFBConfig config = QGLXContext::findConfig(screen,format);
+ XVisualInfo *visualInfo = glXGetVisualFromFBConfig(screen->display(),config);
return visualInfo;
}
-QPlatformWindowFormat QGLXGLContext::platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext ctx)
+QPlatformWindowFormat QGLXContext::platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext ctx)
{
QPlatformWindowFormat format;
int redSize = 0;
@@ -210,7 +211,7 @@ QPlatformWindowFormat QGLXGLContext::platformWindowFromGLXFBConfig(Display *disp
return format;
}
-QPlatformWindowFormat QGLXGLContext::reducePlatformWindowFormat(const QPlatformWindowFormat &format, bool *reduced)
+QPlatformWindowFormat QGLXContext::reducePlatformWindowFormat(const QPlatformWindowFormat &format, bool *reduced)
{
QPlatformWindowFormat retFormat = format;
*reduced = true;
@@ -235,9 +236,9 @@ QPlatformWindowFormat QGLXGLContext::reducePlatformWindowFormat(const QPlatformW
return retFormat;
}
-QGLXGLContext::QGLXGLContext(Window window, MyDisplay *xd, const QPlatformWindowFormat &format)
+QGLXContext::QGLXContext(Window window, QTestLiteScreen *screen, const QPlatformWindowFormat &format)
: QPlatformGLContext()
- , m_xd(xd)
+ , m_screen(screen)
, m_drawable((Drawable)window)
, m_context(0)
{
@@ -246,7 +247,7 @@ QGLXGLContext::QGLXGLContext(Window window, MyDisplay *xd, const QPlatformWindow
if (format.useDefaultSharedContext()) {
if (!QPlatformGLContext::defaultSharedContext()) {
if (m_defaultSharedContextMutex.tryLock()){
- createDefaultSharedContex(xd);
+ createDefaultSharedContex(screen);
m_defaultSharedContextMutex.unlock();
} else {
m_defaultSharedContextMutex.lock(); //wait to the the shared context is created
@@ -259,32 +260,32 @@ QGLXGLContext::QGLXGLContext(Window window, MyDisplay *xd, const QPlatformWindow
}
GLXContext shareGlxContext = 0;
if (sharePlatformContext)
- shareGlxContext = static_cast<const QGLXGLContext*>(sharePlatformContext)->glxContext();
+ shareGlxContext = static_cast<const QGLXContext*>(sharePlatformContext)->glxContext();
- GLXFBConfig config = findConfig(xd,format);
- m_context = glXCreateNewContext(xd->display,config,GLX_RGBA_TYPE,shareGlxContext,TRUE);
- m_windowFormat = QGLXGLContext::platformWindowFromGLXFBConfig(xd->display,config,m_context);
+ GLXFBConfig config = findConfig(screen,format);
+ m_context = glXCreateNewContext(screen->display(),config,GLX_RGBA_TYPE,shareGlxContext,TRUE);
+ m_windowFormat = QGLXContext::platformWindowFromGLXFBConfig(screen->display(),config,m_context);
#ifdef MYX11_DEBUG
qDebug() << "QGLXGLContext::create context" << m_context;
#endif
}
-QGLXGLContext::QGLXGLContext(MyDisplay *display, Drawable drawable, GLXContext context)
- : QPlatformGLContext(), m_xd(display), m_drawable(drawable), m_context(context)
+QGLXContext::QGLXContext(QTestLiteScreen *screen, Drawable drawable, GLXContext context)
+ : QPlatformGLContext(), m_screen(screen), m_drawable(drawable), m_context(context)
{
}
-QGLXGLContext::~QGLXGLContext()
+QGLXContext::~QGLXContext()
{
if (m_context) {
qDebug("Destroying GLX context 0x%p", m_context);
- glXDestroyContext(m_xd->display, m_context);
+ glXDestroyContext(m_screen->display(), m_context);
}
}
-void QGLXGLContext::createDefaultSharedContex(MyDisplay *xd)
+void QGLXContext::createDefaultSharedContex(QTestLiteScreen *screen)
{
int x = 0;
int y = 0;
@@ -293,45 +294,45 @@ void QGLXGLContext::createDefaultSharedContex(MyDisplay *xd)
QPlatformWindowFormat format = QPlatformWindowFormat::defaultFormat();
GLXContext context;
- GLXFBConfig config = findConfig(xd,format);
+ GLXFBConfig config = findConfig(screen,format);
if (config) {
- XVisualInfo *visualInfo = glXGetVisualFromFBConfig(xd->display,config);
- Colormap cmap = XCreateColormap(xd->display,xd->rootWindow(),visualInfo->visual,AllocNone);
+ XVisualInfo *visualInfo = glXGetVisualFromFBConfig(screen->display(),config);
+ Colormap cmap = XCreateColormap(screen->display(),screen->rootWindow(),visualInfo->visual,AllocNone);
XSetWindowAttributes a;
a.colormap = cmap;
- Window sharedWindow = XCreateWindow(xd->display, xd->rootWindow(),x, y, w, h,
+ Window sharedWindow = XCreateWindow(screen->display(), screen->rootWindow(),x, y, w, h,
0, visualInfo->depth, InputOutput, visualInfo->visual,
CWColormap, &a);
- context = glXCreateNewContext(xd->display,config,GLX_RGBA_TYPE,0,TRUE);
- QPlatformGLContext *sharedContext = new QGLXGLContext(xd,sharedWindow,context);
+ context = glXCreateNewContext(screen->display(),config,GLX_RGBA_TYPE,0,TRUE);
+ QPlatformGLContext *sharedContext = new QGLXContext(screen,sharedWindow,context);
QPlatformGLContext::setDefaultSharedContext(sharedContext);
} else {
qWarning("Warning no shared context created");
}
}
-void QGLXGLContext::makeCurrent()
+void QGLXContext::makeCurrent()
{
QPlatformGLContext::makeCurrent();
#ifdef MYX11_DEBUG
qDebug("QGLXGLContext::makeCurrent(window=0x%x, ctx=0x%x)", m_drawable, m_context);
#endif
- glXMakeCurrent(m_xd->display, m_drawable, m_context);
+ glXMakeCurrent(m_screen->display(), m_drawable, m_context);
}
-void QGLXGLContext::doneCurrent()
+void QGLXContext::doneCurrent()
{
QPlatformGLContext::doneCurrent();
- glXMakeCurrent(m_xd->display, 0, 0);
+ glXMakeCurrent(m_screen->display(), 0, 0);
}
-void QGLXGLContext::swapBuffers()
+void QGLXContext::swapBuffers()
{
- glXSwapBuffers(m_xd->display, m_drawable);
+ glXSwapBuffers(m_screen->display(), m_drawable);
}
-void* QGLXGLContext::getProcAddress(const QString& procName)
+void* QGLXContext::getProcAddress(const QString& procName)
{
typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *);
static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
@@ -340,7 +341,7 @@ void* QGLXGLContext::getProcAddress(const QString& procName)
if (resolved && !glXGetProcAddressARB)
return 0;
if (!glXGetProcAddressARB) {
- QList<QByteArray> glxExt = QByteArray(glXGetClientString(m_xd->display, GLX_EXTENSIONS)).split(' ');
+ QList<QByteArray> glxExt = QByteArray(glXGetClientString(m_screen->display(), GLX_EXTENSIONS)).split(' ');
if (glxExt.contains("GLX_ARB_get_proc_address")) {
#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
void *handle = dlopen(NULL, RTLD_LAZY);
@@ -364,7 +365,7 @@ void* QGLXGLContext::getProcAddress(const QString& procName)
return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.toLatin1().data()));
}
-QPlatformWindowFormat QGLXGLContext::platformWindowFormat() const
+QPlatformWindowFormat QGLXContext::platformWindowFormat() const
{
return m_windowFormat;
}
diff --git a/src/plugins/platforms/testlite/qglxintegration.h b/src/plugins/platforms/testlite/qglxintegration.h
index e17790e..5ae0b2a 100644
--- a/src/plugins/platforms/testlite/qglxintegration.h
+++ b/src/plugins/platforms/testlite/qglxintegration.h
@@ -53,13 +53,11 @@
QT_BEGIN_NAMESPACE
-class MyDisplay;
-
-class QGLXGLContext : public QPlatformGLContext
+class QGLXContext : public QPlatformGLContext
{
public:
- QGLXGLContext(Window window, MyDisplay *xd, const QPlatformWindowFormat &format);
- ~QGLXGLContext();
+ QGLXContext(Window window, QTestLiteScreen *xd, const QPlatformWindowFormat &format);
+ ~QGLXContext();
virtual void makeCurrent();
virtual void doneCurrent();
@@ -70,22 +68,22 @@ public:
QPlatformWindowFormat platformWindowFormat() const;
- static XVisualInfo *findVisualInfo(const MyDisplay *xd, const QPlatformWindowFormat &format);
+ static XVisualInfo *findVisualInfo(const QTestLiteScreen *xd, const QPlatformWindowFormat &format);
private:
- static GLXFBConfig findConfig(const MyDisplay *xd,const QPlatformWindowFormat &format);
+ static GLXFBConfig findConfig(const QTestLiteScreen *xd,const QPlatformWindowFormat &format);
static QVector<int> buildSpec(const QPlatformWindowFormat &format);
static QPlatformWindowFormat platformWindowFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext context);
static QPlatformWindowFormat reducePlatformWindowFormat(const QPlatformWindowFormat &format, bool *reduced);
- MyDisplay *m_xd;
+ QTestLiteScreen *m_screen;
Drawable m_drawable;
GLXContext m_context;
QPlatformWindowFormat m_windowFormat;
- QGLXGLContext (MyDisplay *display, Drawable drawable, GLXContext context);
+ QGLXContext (QTestLiteScreen *screen, Drawable drawable, GLXContext context);
static QMutex m_defaultSharedContextMutex;
- static void createDefaultSharedContex(MyDisplay *xd);
+ static void createDefaultSharedContex(QTestLiteScreen *xd);
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/testlite/qtestlitecursor.cpp b/src/plugins/platforms/testlite/qtestlitecursor.cpp
new file mode 100644
index 0000000..4f3f0cb
--- /dev/null
+++ b/src/plugins/platforms/testlite/qtestlitecursor.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** 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 "qtestlitecursor.h"
+
+#include "qtestliteintegration.h"
+#include "qtestlitescreen.h"
+#include "qtestlitewindow.h"
+
+#include <QtGui/QBitmap>
+
+#include <X11/cursorfont.h>
+
+QT_BEGIN_NAMESPACE
+
+QTestLiteCursor::QTestLiteCursor(QTestLiteScreen *screen)
+ : QPlatformCursor(screen)
+{
+}
+
+void QTestLiteCursor::changeCursor(QCursor *cursor, QWidget *widget)
+{
+ QTestLiteWindow *w = 0;
+ if (widget) {
+ QWidget *window = widget->window();
+ w = static_cast<QTestLiteWindow*>(window->platformWindow());
+ } else {
+ // No X11 cursor control when there is no widget under the cursor
+ return;
+ }
+
+ if (!w)
+ return;
+
+ int id = cursor->handle();
+ if (id == currentCursor)
+ return;
+ Cursor c;
+ if (!cursorMap.contains(id)) {
+ if (cursor->shape() == Qt::BitmapCursor)
+ c = createCursorBitmap(cursor);
+ else
+ c = createCursorShape(cursor->shape());
+ if (!c) {
+ return;
+ }
+ cursorMap.insert(id, c);
+ } else {
+ c = cursorMap.value(id);
+ }
+
+ w->setCursor(c);
+}
+
+Cursor QTestLiteCursor::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 = testLiteScreen()->rootWindow();
+
+ 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(testLiteScreen()->display(), rootwin, mapBits, width, height);
+ Pixmap mp = XCreateBitmapFromData(testLiteScreen()->display(), rootwin, maskBits, width, height);
+ Cursor c = XCreatePixmapCursor(testLiteScreen()->display(), cp, mp, &fg, &bg, spot.x(), spot.y());
+ XFreePixmap(testLiteScreen()->display(), cp);
+ XFreePixmap(testLiteScreen()->display(), mp);
+ delete[] mapBits;
+ delete[] maskBits;
+
+ return c;
+}
+
+Cursor QTestLiteCursor::createCursorShape(int cshape)
+{
+ Cursor cursor = 0;
+
+ if (cshape < 0 || cshape > Qt::LastCursor)
+ return 0;
+
+ switch (cshape) {
+ case Qt::ArrowCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_left_ptr);
+ break;
+ case Qt::UpArrowCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_center_ptr);
+ break;
+ case Qt::CrossCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_crosshair);
+ break;
+ case Qt::WaitCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_watch);
+ break;
+ case Qt::IBeamCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_xterm);
+ break;
+ case Qt::SizeAllCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_fleur);
+ break;
+ case Qt::PointingHandCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_hand2);
+ break;
+ case Qt::SizeBDiagCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_top_right_corner);
+ break;
+ case Qt::SizeFDiagCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_bottom_right_corner);
+ break;
+ case Qt::SizeVerCursor:
+ case Qt::SplitVCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_sb_v_double_arrow);
+ break;
+ case Qt::SizeHorCursor:
+ case Qt::SplitHCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_sb_h_double_arrow);
+ break;
+ case Qt::WhatsThisCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_question_arrow);
+ break;
+ case Qt::ForbiddenCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_circle);
+ break;
+ case Qt::BusyCursor:
+ cursor = XCreateFontCursor(testLiteScreen()->display(), XC_watch);
+ break;
+
+ default: //default cursor for all the rest
+ break;
+ }
+ return cursor;
+}
+
+QTestLiteScreen * QTestLiteCursor::testLiteScreen() const
+{
+ return static_cast<QTestLiteScreen *>(screen);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/testlite/qtestlitecursor.h b/src/plugins/platforms/testlite/qtestlitecursor.h
new file mode 100644
index 0000000..15a5b2a
--- /dev/null
+++ b/src/plugins/platforms/testlite/qtestlitecursor.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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 QTESTLITECURSOR_H
+#define QTESTLITECURSOR_H
+
+#include <QtGui/QPlatformCursor>
+
+#include "qtestliteintegration.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTestLiteCursor : QPlatformCursor
+{
+public:
+ QTestLiteCursor(QTestLiteScreen *screen);
+
+ void changeCursor(QCursor * cursor, QWidget * widget);
+private:
+
+ Cursor createCursorBitmap(QCursor * cursor);
+ Cursor createCursorShape(int cshape);
+
+ QTestLiteScreen *testLiteScreen() const;
+ int currentCursor;
+ QMap<int, Cursor> cursorMap;
+};
+
+QT_END_NAMESPACE
+
+#endif // QTESTLITECURSOR_H
diff --git a/src/plugins/platforms/testlite/qtestliteintegration.cpp b/src/plugins/platforms/testlite/qtestliteintegration.cpp
index 68e9051..fc2a89c 100644
--- a/src/plugins/platforms/testlite/qtestliteintegration.cpp
+++ b/src/plugins/platforms/testlite/qtestliteintegration.cpp
@@ -39,17 +39,14 @@
**
****************************************************************************/
-
-
#include "qtestliteintegration.h"
#include "qtestlitewindowsurface.h"
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtCore/qdebug.h>
-#include <QPlatformCursor>
-
#include "qtestlitewindow.h"
#include "qgenericunixfontdatabase.h"
+#include "qtestlitescreen.h"
#ifndef QT_NO_OPENGL
#include <GL/glx.h>
@@ -59,50 +56,13 @@
QT_BEGIN_NAMESPACE
-class MyCursor : QPlatformCursor
-{
-public:
- MyCursor(QPlatformScreen *screen) : QPlatformCursor(screen) {}
-
- void changeCursor(QCursor * cursor, QWidget * widget) {
- QTestLiteWindow *w = 0;
- if (widget) {
- QWidget *window = widget->window();
- w = static_cast<QTestLiteWindow*>(window->platformWindow());
- } else {
- // No X11 cursor control when there is no widget under the cursor
- return;
- }
-
- //qDebug() << "changeCursor" << widget << ws;
- if (!w)
- return;
-
- w->setCursor(cursor);
- }
-};
-
QTestLiteIntegration::QTestLiteIntegration(bool useOpenGL)
: mUseOpenGL(useOpenGL)
, mFontDb(new QGenericUnixFontDatabase())
{
- xd = new MyDisplay;
-
mPrimaryScreen = new QTestLiteScreen();
-
- mPrimaryScreen->mGeometry = QRect
- (0, 0, xd->width, xd->height);
- mPrimaryScreen->mDepth = 32;
- mPrimaryScreen->mFormat = QImage::Format_RGB32;
- mPrimaryScreen->mPhysicalSize =
- QSize(xd->physicalWidth, xd->physicalHeight);
-
mScreens.append(mPrimaryScreen);
-
-
- (void)new MyCursor(mPrimaryScreen);
-
}
QPixmapData *QTestLiteIntegration::createPixmapData(QPixmapData::PixelType type) const
@@ -120,21 +80,33 @@ QWindowSurface *QTestLiteIntegration::createWindowSurface(QWidget *widget, WId)
if (mUseOpenGL)
return new QGLWindowSurface(widget);
#endif
- return new QTestLiteWindowSurface(mPrimaryScreen, widget);
+ return new QTestLiteWindowSurface(widget);
}
QPlatformWindow *QTestLiteIntegration::createPlatformWindow(QWidget *widget, WId /*winId*/) const
{
- return new QTestLiteWindow(this, mPrimaryScreen, widget);
+ return new QTestLiteWindow(widget);
}
QPixmap QTestLiteIntegration::grabWindow(WId window, int x, int y, int width, int height) const
{
- QImage img = xd->grabWindow(window, x, y, width, height);
- return QPixmap::fromImage(img);
+ QImage image;
+ QWidget *widget = QWidget::find(window);
+ if (widget) {
+ QTestLiteScreen *screen = QTestLiteScreen::testLiteScreenForWidget(widget);
+ image = screen->grabWindow(window,x,y,width,height);
+ } else {
+ for (int i = 0; i < mScreens.size(); i++) {
+ QTestLiteScreen *screen = static_cast<QTestLiteScreen *>(mScreens[i]);
+ if (screen->rootWindow() == window) {
+ image = screen->grabWindow(window,x,y,width,height);
+ }
+ }
+ }
+ return QPixmap::fromImage(image);
}
QPlatformFontDatabase *QTestLiteIntegration::fontDatabase() const
@@ -145,7 +117,8 @@ QPlatformFontDatabase *QTestLiteIntegration::fontDatabase() const
bool QTestLiteIntegration::hasOpenGL() const
{
#ifndef QT_NO_OPENGL
- return glXQueryExtension(xd->display, 0, 0) != 0;
+ QTestLiteScreen *screen = static_cast<const QTestLiteScreen *>(mScreens.at(0));
+ return glXQueryExtension(screen->display(), 0, 0) != 0;
#endif
return false;
}
diff --git a/src/plugins/platforms/testlite/qtestliteintegration.h b/src/plugins/platforms/testlite/qtestliteintegration.h
index 8286ef0..37d09f5 100644
--- a/src/plugins/platforms/testlite/qtestliteintegration.h
+++ b/src/plugins/platforms/testlite/qtestliteintegration.h
@@ -42,34 +42,17 @@
#ifndef QGRAPHICSSYSTEM_TESTLITE_H
#define QGRAPHICSSYSTEM_TESTLITE_H
-#include <QtGui/QPlatformIntegration>
-#include <QtGui/QPlatformScreen>
-
//make sure textstream is included before any X11 headers
#include <QtCore/QTextStream>
-QT_BEGIN_NAMESPACE
+#include <QtGui/QPlatformIntegration>
+#include <QtGui/QPlatformScreen>
-class MyDisplay;
+#include <QtGui/private/qt_x11_p.h>
-class QTestLiteScreen : public QPlatformScreen
-{
-public:
- QTestLiteScreen()
- : mDepth(16), mFormat(QImage::Format_RGB16) {}
- ~QTestLiteScreen() {}
-
- QRect geometry() const { return mGeometry; }
- int depth() const { return mDepth; }
- QImage::Format format() const { return mFormat; }
- QSize physicalSize() const { return mPhysicalSize; }
+QT_BEGIN_NAMESPACE
-public:
- QRect mGeometry;
- int mDepth;
- QImage::Format mFormat;
- QSize mPhysicalSize;
-};
+class QTestLiteScreen;
class QTestLiteIntegration : public QPlatformIntegration
{
@@ -88,8 +71,6 @@ public:
bool hasOpenGL() const;
- MyDisplay *xd;
-
private:
bool mUseOpenGL;
QTestLiteScreen *mPrimaryScreen;
diff --git a/src/plugins/platforms/testlite/qtestlitescreen.cpp b/src/plugins/platforms/testlite/qtestlitescreen.cpp
new file mode 100644
index 0000000..919506e
--- /dev/null
+++ b/src/plugins/platforms/testlite/qtestlitescreen.cpp
@@ -0,0 +1,430 @@
+/****************************************************************************
+**
+** 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 "qtestlitescreen.h"
+
+#include "qtestlitecursor.h"
+#include "qtestlitewindow.h"
+
+#include <QtCore/QDebug>
+#include <QtCore/QSocketNotifier>
+
+QT_BEGIN_NAMESPACE
+
+static int (*original_x_errhandler)(Display *dpy, XErrorEvent *);
+static bool seen_badwindow;
+
+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;
+}
+
+QTestLiteScreen::QTestLiteScreen()
+ : mFormat(QImage::Format_RGB32)
+ , mWmProtocolsAtom(0)
+ , mWmDeleteWindowAtom(0)
+{
+ char *display_name = getenv("DISPLAY");
+ mDisplay = XOpenDisplay(display_name);
+ if (!mDisplay) {
+ fprintf(stderr, "Cannot connect to X server: %s\n",
+ display_name);
+ exit(1);
+ }
+
+#ifndef DONT_USE_MIT_SHM
+ Status MIT_SHM_extension_supported = XShmQueryExtension (mDisplay);
+ Q_ASSERT(MIT_SHM_extension_supported == True);
+#endif
+ original_x_errhandler = XSetErrorHandler(qt_x_errhandler);
+
+ if (qgetenv("DO_X_SYNCHRONIZE").toInt())
+ XSynchronize(mDisplay, true);
+
+ mScreen = DefaultScreen(mDisplay);
+ int width = DisplayWidth(mDisplay, mScreen);
+ int height = DisplayHeight(mDisplay, mScreen);
+ mGeometry = QRect(0,0,width,height);
+
+ int physicalWidth = DisplayWidthMM(mDisplay, mScreen);
+ int physicalHeight = DisplayHeightMM(mDisplay, mScreen);
+ mPhysicalSize = QSize(physicalWidth,physicalHeight);
+
+ int xSocketNumber = XConnectionNumber(mDisplay);
+
+ mDepth = DefaultDepth(mDisplay,mScreen);
+#ifdef MYX11_DEBUG
+ qDebug() << "X socket:"<< xSocketNumber;
+#endif
+ QSocketNotifier *sock = new QSocketNotifier(xSocketNumber, QSocketNotifier::Read, this);
+ connect(sock, SIGNAL(activated(int)), this, SLOT(eventDispatcher()));
+
+ mWmProtocolsAtom = XInternAtom (mDisplay, "WM_PROTOCOLS", False);
+ mWmDeleteWindowAtom = XInternAtom (mDisplay, "WM_DELETE_WINDOW", False);
+
+ mWmMotifHintAtom = XInternAtom(mDisplay, "_MOTIF_WM_HINTS\0", False);
+
+ mCursor = new QTestLiteCursor(this);
+}
+
+QTestLiteScreen::~QTestLiteScreen()
+{
+ delete mCursor;
+ XCloseDisplay(mDisplay);
+}
+
+#ifdef KeyPress
+#undef KeyPress
+#endif
+#ifdef KeyRelease
+#undef KeyRelease
+#endif
+
+//Q_GUI_EXPORT extern Atom wmProtocolsAtom;
+//Q_GUI_EXPORT extern Atom wmDeleteWindowAtom;
+
+bool QTestLiteScreen::handleEvent(XEvent *xe)
+{
+ int quit = false;
+ QTestLiteWindow *xw = 0;
+ QWidget *widget = QWidget::find(xe->xany.window);
+ if (widget) {
+ xw = static_cast<QTestLiteWindow *>(widget->platformWindow());
+ }
+ 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;
+
+ case XFocusIn:
+ xw->handleFocusInEvent();
+ break;
+
+ case XFocusOut:
+ xw->handleFocusOutEvent();
+ break;
+
+ default:
+#ifdef MYX11_DEBUG
+ qDebug() << hex << xe->xany.window << "Other X event" << xe->type;
+#endif
+ break;
+ }
+ return quit;
+}
+
+void QTestLiteScreen::eventDispatcher()
+{
+ ulong marker = XNextRequest(mDisplay);
+ // int i = 0;
+ while (XPending(mDisplay)) {
+ XEvent event;
+ XNextEvent(mDisplay, &event);
+ /* done = */
+ handleEvent(&event);
+
+ if (event.xany.serial >= marker) {
+ #ifdef MYX11_DEBUG
+ qDebug() << "potential livelock averted";
+ #endif
+ #if 0
+ if (XEventsQueued(mDisplay, QueuedAfterFlush)) {
+ qDebug() << " with events queued";
+ QTimer::singleShot(0, this, SLOT(eventDispatcher()));
+ }
+ #endif
+ break;
+ }
+ }
+}
+
+QImage QTestLiteScreen::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(mDisplay, 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(mDisplay, 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;
+}
+
+QTestLiteScreen * QTestLiteScreen::testLiteScreenForWidget(QWidget *widget)
+{
+ QPlatformScreen *platformScreen = platformScreenForWidget(widget);
+ return static_cast<QTestLiteScreen *>(platformScreen);
+}
+
+Display * QTestLiteScreen::display() const
+{
+ return mDisplay;
+}
+
+int QTestLiteScreen::xScreenNumber() const
+{
+ return mScreen;
+}
+
+Atom QTestLiteScreen::wmProtocolsAtom() const
+{
+ return mWmProtocolsAtom;
+}
+
+Atom QTestLiteScreen::wmDeleteWindowAtom() const
+{
+ return mWmDeleteWindowAtom;
+}
+
+void QTestLiteScreen::setWmDeleteWindowAtom(Atom newDeleteWindowAtom)
+{
+ mWmDeleteWindowAtom = newDeleteWindowAtom;
+}
+
+Atom QTestLiteScreen::atomForMotifWmHints() const
+{
+ return mWmMotifHintAtom;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/testlite/qtestlitescreen.h b/src/plugins/platforms/testlite/qtestlitescreen.h
new file mode 100644
index 0000000..f8d9468
--- /dev/null
+++ b/src/plugins/platforms/testlite/qtestlitescreen.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** 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 QTESTLITESCREEN_H
+#define QTESTLITESCREEN_H
+
+#include <QtGui/QPlatformScreen>
+#include "qtestliteintegration.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTestLiteCursor;
+
+class QTestLiteScreen : public QPlatformScreen
+{
+ Q_OBJECT
+public:
+ QTestLiteScreen();
+
+ ~QTestLiteScreen();
+
+ QRect geometry() const { return mGeometry; }
+ int depth() const { return mDepth; }
+ QImage::Format format() const { return mFormat; }
+ QSize physicalSize() const { return mPhysicalSize; }
+
+ Window rootWindow() { return RootWindow(mDisplay, mScreen); }
+ unsigned long blackPixel() { return BlackPixel(mDisplay, mScreen); }
+ unsigned long whitePixel() { return WhitePixel(mDisplay, mScreen); }
+
+ bool handleEvent(XEvent *xe);
+ QImage grabWindow(Window window, int x, int y, int w, int h);
+
+ static QTestLiteScreen *testLiteScreenForWidget(QWidget *widget);
+
+ Display *display() const;
+ int xScreenNumber() const;
+
+ Atom wmProtocolsAtom() const;
+ Atom wmDeleteWindowAtom() const;
+ void setWmDeleteWindowAtom(Atom newDeleteWindowAtom);
+
+ Atom atomForMotifWmHints() const;
+
+
+public slots:
+ void eventDispatcher();
+
+private:
+ QRect mGeometry;
+ QSize mPhysicalSize;
+ int mDepth;
+ QImage::Format mFormat;
+ QTestLiteCursor *mCursor;
+
+ Display * mDisplay;
+ int mScreen;
+ Atom mWmProtocolsAtom;
+ Atom mWmDeleteWindowAtom;
+ Atom mWmMotifHintAtom;
+};
+
+QT_END_NAMESPACE
+
+#endif // QTESTLITESCREEN_H
diff --git a/src/plugins/platforms/testlite/qtestlitewindow.cpp b/src/plugins/platforms/testlite/qtestlitewindow.cpp
index 5f9d387..f8f4a5f 100644
--- a/src/plugins/platforms/testlite/qtestlitewindow.cpp
+++ b/src/plugins/platforms/testlite/qtestlitewindow.cpp
@@ -39,169 +39,81 @@
**
****************************************************************************/
-#include "qtestliteintegration.h"
-#include <QWindowSystemInterface>
-#include <private/qwindowsurface_p.h>
-#include <QtGui/private/qapplication_p.h>
-
#include "qtestlitewindow.h"
-#include <QBitmap>
-#include <QCursor>
-#include <QDateTime>
-#include <QPixmap>
-#include <QImage>
-#include <QSocketNotifier>
+#include "qtestliteintegration.h"
+#include "qtestlitescreen.h"
-#include <qdebug.h>
-#include <QTimer>
+#include <QtGui/QWindowSystemInterface>
+#include <QSocketNotifier>
#include <QApplication>
+#include <QDebug>
+
+#include <QtGui/private/qwindowsurface_p.h>
+#include <QtGui/private/qapplication_p.h>
#ifndef QT_NO_OPENGL
#include "qglxintegration.h"
#endif
-#include <stdio.h>
-#include <stdlib.h>
-
-
-#include <X11/Xatom.h>
-
-#include <X11/cursorfont.h>
-
-
-
-//### remove stuff we don't want from qt_x11_p.h
-#undef ATOM
-#undef X11
-
//#define MYX11_DEBUG
QT_BEGIN_NAMESPACE
-static int (*original_x_errhandler)(Display *dpy, XErrorEvent *);
-static bool seen_badwindow;
-
-
-static Atom wmProtocolsAtom;
-static Atom wmDeleteWindowAtom;
-
-class MyX11CursorNode
+QTestLiteWindow::QTestLiteWindow(QWidget *window)
+ : QPlatformWindow(window)
+ , mGLContext(0)
+ , mScreen(QTestLiteScreen::testLiteScreenForWidget(window))
{
-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<int, MyX11CursorNode *> lookupMap;
- QTimer timer;
-
- Display *display;
-
- int removalDelay;
-};
-
-
-
-
-
-QTestLiteWindow::QTestLiteWindow(const QTestLiteIntegration *platformIntegration,
- QTestLiteScreen */*screen*/, QWidget *window)
- :QPlatformWindow(window), mGLContext(0)
-{
- xd = platformIntegration->xd;
- xd->windowList.append(this);
- {
- int x = window->x();
- int y = window->y();
- int w = window->width();
- int h = window->height();
+ int x = window->x();
+ int y = window->y();
+ int w = window->width();
+ int h = window->height();
if(window->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL
- && QApplicationPrivate::platformIntegration()->hasOpenGL() ) {
+ && QApplicationPrivate
+ ::platformIntegration()->hasOpenGL() ) {
#ifndef QT_NO_OPENGL
- XVisualInfo *visualInfo = QGLXGLContext::findVisualInfo(xd,window->platformWindowFormat());
- Colormap cmap = XCreateColormap(xd->display,xd->rootWindow(),visualInfo->visual,AllocNone);
+ XVisualInfo *visualInfo = QGLXContext::findVisualInfo(mScreen,window->platformWindowFormat());
+ Colormap cmap = XCreateColormap(mScreen->display(),mScreen->rootWindow(),visualInfo->visual,AllocNone);
XSetWindowAttributes a;
a.colormap = cmap;
- x_window = XCreateWindow(xd->display, xd->rootWindow(),x, y, w, h,
+ x_window = XCreateWindow(mScreen->display(), mScreen->rootWindow(),x, y, w, h,
0, visualInfo->depth, InputOutput, visualInfo->visual,
CWColormap, &a);
#endif //QT_NO_OPENGL
} else {
- x_window = XCreateSimpleWindow(xd->display, xd->rootWindow(),
+ x_window = XCreateSimpleWindow(mScreen->display(), mScreen->rootWindow(),
x, y, w, h, 0 /*border_width*/,
- xd->blackPixel(), xd->whitePixel());
+ mScreen->blackPixel(), mScreen->whitePixel());
}
#ifdef MYX11_DEBUG
qDebug() << "QTestLiteWindow::QTestLiteWindow creating" << hex << x_window << window;
#endif
- }
+// }
- width = -1;
- height = -1;
- xpos = -1;
- ypos = -1;
+// width = -1;
+// height = -1;
+// xpos = -1;
+// ypos = -1;
- XSetWindowBackgroundPixmap(xd->display, x_window, XNone);
+ XSetWindowBackgroundPixmap(mScreen->display(), x_window, XNone);
- XSelectInput(xd->display, x_window, ExposureMask | KeyPressMask | KeyReleaseMask |
+ XSelectInput(mScreen->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);
- currentCursor = -1;
+ Atom wmDeleteWindowAtom = mScreen->wmDeleteWindowAtom();
+ XChangeProperty (mScreen->display(), x_window,
+ mScreen->wmProtocolsAtom(),
+ XA_ATOM, 32, PropModeAppend,
+ (unsigned char *) &wmDeleteWindowAtom, 1);
+ mScreen->setWmDeleteWindowAtom(wmDeleteWindowAtom);
}
@@ -211,19 +123,12 @@ QTestLiteWindow::~QTestLiteWindow()
qDebug() << "~QTestLiteWindow" << hex << x_window;
#endif
delete mGLContext;
- XFreeGC(xd->display, gc);
- XDestroyWindow(xd->display, x_window);
-
- xd->windowList.removeAll(this);
+ XFreeGC(mScreen->display(), gc);
+ XDestroyWindow(mScreen->display(), x_window);
}
-
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Mouse event stuff
-
-
-
-
static Qt::MouseButtons translateMouseButtons(int s)
{
Qt::MouseButtons ret = 0;
@@ -236,13 +141,11 @@ static Qt::MouseButtons translateMouseButtons(int s)
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;
@@ -328,7 +231,6 @@ void QTestLiteWindow::handleFocusOutEvent()
QWindowSystemInterface::handleWindowActivated(0);
}
-
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Key event stuff -- not pretty either
//
@@ -570,7 +472,6 @@ static const unsigned int keyTbl[] = {
0, 0
};
-
static int lookupCode(unsigned int xkeycode)
{
if (xkeycode >= XK_F1 && xkeycode <= XK_F35)
@@ -586,7 +487,6 @@ static int lookupCode(unsigned int xkeycode)
return 0;
}
-
static Qt::KeyboardModifiers modifierFromKeyCode(int qtcode)
{
switch (qtcode) {
@@ -640,7 +540,7 @@ void QTestLiteWindow::handleKeyEvent(QEvent::Type type, void *ev)
void QTestLiteWindow::setGeometry(const QRect &rect)
{
- XMoveResizeWindow(xd->display, x_window, rect.x(), rect.y(), rect.width(), rect.height());
+ XMoveResizeWindow(mScreen->display(), x_window, rect.x(), rect.y(), rect.width(), rect.height());
QPlatformWindow::setGeometry(rect);
}
@@ -658,17 +558,17 @@ WId QTestLiteWindow::winId() const
void QTestLiteWindow::setParent(const QPlatformWindow *window)
{
QPoint point = widget()->mapTo(widget()->nativeParentWidget(),QPoint());
- XReparentWindow(xd->display,x_window,window->winId(),point.x(),point.y());
+ XReparentWindow(mScreen->display(),x_window,window->winId(),point.x(),point.y());
}
void QTestLiteWindow::raise()
{
- XRaiseWindow(xd->display, x_window);
+ XRaiseWindow(mScreen->display(), x_window);
}
void QTestLiteWindow::lower()
{
- XLowerWindow(xd->display, x_window);
+ XLowerWindow(mScreen->display(), x_window);
}
void QTestLiteWindow::setWindowTitle(const QString &title)
@@ -680,14 +580,14 @@ void QTestLiteWindow::setWindowTitle(const QString &title)
windowName.format = 8;
windowName.nitems = ba.length();
- XSetWMName(xd->display, x_window, &windowName);
+ XSetWMName(mScreen->display(), x_window, &windowName);
}
GC QTestLiteWindow::createGC()
{
GC gc;
- gc = XCreateGC(xd->display, x_window, 0, 0);
+ gc = XCreateGC(mScreen->display(), x_window, 0, 0);
if (gc < 0) {
qWarning("QTestLiteWindow::createGC() could not create GC");
}
@@ -701,34 +601,32 @@ void QTestLiteWindow::paintEvent()
#endif
if (QWindowSurface *surface = widget()->windowSurface())
- surface->flush(widget(), QRect(xpos,ypos,width, height), QPoint());
+ surface->flush(widget(), widget()->geometry(), QPoint());
}
void QTestLiteWindow::requestActivateWindow()
{
- XSetInputFocus(xd->display, x_window, XRevertToParent, CurrentTime);
+ XSetInputFocus(mScreen->display(), x_window, XRevertToParent, CurrentTime);
}
void QTestLiteWindow::resizeEvent(XConfigureEvent *e)
{
- if ((e->width != width || e->height != height) && e->x == 0 && e->y == 0) {
+ int xpos = geometry().x();
+ int ypos = geometry().y();
+ if ((e->width != geometry().width() || e->height != geometry().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 << x_window << dec << "ConfigureNotify" << e->x << e->y << e->width << e->height << "geometry" << xpos << ypos << width << height;
#endif
- QWindowSystemInterface::handleGeometryChange(widget(), QRect(xpos, ypos, width, height));
+ QWindowSystemInterface::handleGeometryChange(widget(), QRect(xpos, ypos, e->width, e->height));
}
-
void QTestLiteWindow::mousePressEvent(XButtonEvent *e)
{
static long prevTime = 0;
@@ -752,51 +650,7 @@ void QTestLiteWindow::mousePressEvent(XButtonEvent *e)
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 QTestLiteWindow::getMWMHints() const
{
QtMWMHints mwmhints;
@@ -804,10 +658,10 @@ static QtMWMHints GetMWMHints(Display *display, Window window)
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,
+ if ((XGetWindowProperty(mScreen->display(), x_window, mScreen->atomForMotifWmHints(), 0, 5, false,
+ mScreen->atomForMotifWmHints(), &type, &format, &nitems, &bytesLeft,
&data) == Success)
- && (type == mwm_hint_atom
+ && (type == mScreen->atomForMotifWmHints()
&& format == 32
&& nitems >= 5)) {
mwmhints = *(reinterpret_cast<QtMWMHints *>(data));
@@ -824,15 +678,15 @@ static QtMWMHints GetMWMHints(Display *display, Window window)
return mwmhints;
}
-#endif
-static void SetMWMHints(Display *display, Window window, const QtMWMHints &mwmhints)
+void QTestLiteWindow::setMWMHints(const QtMWMHints &mwmhints)
{
if (mwmhints.flags != 0l) {
- XChangeProperty(display, window, mwm_hint_atom, mwm_hint_atom, 32,
+ XChangeProperty(mScreen->display(), x_window,
+ mScreen->atomForMotifWmHints(), mScreen->atomForMotifWmHints(), 32,
PropModeReplace, (unsigned char *) &mwmhints, 5);
} else {
- XDeleteProperty(display, window, mwm_hint_atom);
+ XDeleteProperty(mScreen->display(), x_window, mScreen->atomForMotifWmHints());
}
}
@@ -849,17 +703,11 @@ static inline bool isTransient(const QWidget *w)
&& !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 << x_window << "flags" << flags;
#endif
@@ -878,12 +726,10 @@ Qt::WindowFlags QTestLiteWindow::setWindowFlags(Qt::WindowFlags flags)
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;
@@ -964,7 +810,7 @@ Qt::WindowFlags QTestLiteWindow::setWindowFlags(Qt::WindowFlags flags)
mwmhints.decorations = 0;
}
- SetMWMHints(xd->display, x_window, mwmhints);
+ setMWMHints(mwmhints);
//##### only if initializeWindow???
@@ -977,7 +823,7 @@ Qt::WindowFlags QTestLiteWindow::setWindowFlags(Qt::WindowFlags flags)
wsa.override_redirect = True;
wsa.save_under = True;
- XChangeWindowAttributes(xd->display, x_window, CWOverrideRedirect | CWSaveUnder,
+ XChangeWindowAttributes(mScreen->display(), x_window, CWOverrideRedirect | CWSaveUnder,
&wsa);
} else {
#ifdef MYX11_DEBUG
@@ -994,38 +840,15 @@ void QTestLiteWindow::setVisible(bool visible)
qDebug() << "QTestLiteWindow::setVisible" << visible << hex << x_window;
#endif
if (visible)
- XMapWindow(xd->display, x_window);
+ XMapWindow(mScreen->display(), x_window);
else
- XUnmapWindow(xd->display, x_window);
+ XUnmapWindow(mScreen->display(), x_window);
}
-
-void QTestLiteWindow::setCursor(QCursor * cursor)
+void QTestLiteWindow::setCursor(const Cursor &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);
+ XDefineCursor(mScreen->display(), x_window, cursor);
+ XFlush(mScreen->display());
}
QPlatformGLContext *QTestLiteWindow::glContext() const
@@ -1035,574 +858,20 @@ QPlatformGLContext *QTestLiteWindow::glContext() const
if (!mGLContext) {
QTestLiteWindow *that = const_cast<QTestLiteWindow *>(this);
#ifndef QT_NO_OPENGL
- that->mGLContext = new QGLXGLContext(x_window, xd,widget()->platformWindowFormat());
+ that->mGLContext = new QGLXContext(x_window, mScreen,widget()->platformWindowFormat());
#endif
}
return mGLContext;
}
-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)
+Window QTestLiteWindow::xWindow() const
{
- 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();
- if (node)
- node->setAnte(0);
- 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;
-
- case XFocusIn:
- xw->handleFocusInEvent();
- break;
-
- case XFocusOut:
- xw->handleFocusOutEvent();
- 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;
- }
- }
+ return x_window;
}
-
-QImage MyDisplay::grabWindow(Window window, int x, int y, int w, int h)
+GC QTestLiteWindow::graphicsContext() const
{
- 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;
+ return gc;
}
-
-
-
-
-
-
QT_END_NAMESPACE
-#include "qtestlitewindow.moc"
diff --git a/src/plugins/platforms/testlite/qtestlitewindow.h b/src/plugins/platforms/testlite/qtestlitewindow.h
index 69442f1..8e9f6fd 100644
--- a/src/plugins/platforms/testlite/qtestlitewindow.h
+++ b/src/plugins/platforms/testlite/qtestlitewindow.h
@@ -42,63 +42,51 @@
#ifndef QTESTLITEWINDOW_H
#define QTESTLITEWINDOW_H
+#include "qtestliteintegration.h"
+
#include <QPlatformWindow>
-#include <qevent.h>
+#include <QEvent>
#include <QObject>
#include <QImage>
-#include <qtimer.h>
-#include <QDateTime>
-
-#include <private/qt_x11_p.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-
-
-
-class QTestLiteIntegration;
-class QTestLiteScreen;
-class QTestLiteWindowSurface;
-class MyX11Cursors;
-class QTestLiteWindow;
-class MyDisplay : public QObject
-{
- Q_OBJECT;
-public:
- MyDisplay();
- ~MyDisplay();
+struct QtMWMHints {
+ ulong flags, functions, decorations;
+ long input_mode;
+ ulong status;
+};
- Window rootWindow() { return RootWindow(display, screen); }
- unsigned long blackPixel() { return BlackPixel(display, screen); }
- unsigned long whitePixel() { return WhitePixel(display, screen); }
+enum {
+ MWM_HINTS_FUNCTIONS = (1L << 0),
- bool handleEvent(XEvent *xe);
- QImage grabWindow(Window window, int x, int y, int w, int h);
+ 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),
-public slots:
- void eventDispatcher();
+ MWM_HINTS_DECORATIONS = (1L << 1),
-public: //###
- Display * display;
- int screen;
- int width, height;
- int physicalWidth;
- int physicalHeight;
+ 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),
- QList<QTestLiteWindow*> windowList;
+ MWM_HINTS_INPUT_MODE = (1L << 2),
- MyX11Cursors * cursors;
+ MWM_INPUT_MODELESS = 0L,
+ MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L,
+ MWM_INPUT_FULL_APPLICATION_MODAL = 3L
};
-struct MyShmImageInfo;
-
class QTestLiteWindow : public QPlatformWindow
{
public:
- QTestLiteWindow(const QTestLiteIntegration *platformIntegration,
- QTestLiteScreen *screen, QWidget *window);
+ QTestLiteWindow(QWidget *window);
~QTestLiteWindow();
@@ -128,33 +116,29 @@ public:
void lower();
void setWindowTitle(const QString &title);
- void setCursor(QCursor * cursor);
+ void setCursor(const Cursor &cursor);
QPlatformGLContext *glContext() const;
+ Window xWindow() const;
+ GC graphicsContext() const;
+
+protected:
+ void setMWMHints(const QtMWMHints &mwmhints);
+ QtMWMHints getMWMHints() const;
+
private:
- int xpos, ypos;
- int width, height;
Window x_window;
GC gc;
GC createGC();
- Cursor createCursorShape(int cshape);
- Cursor createCursorBitmap(QCursor * cursor);
-
- int currentCursor;
-
- MyDisplay *xd;
+ QPlatformGLContext *mGLContext;
QTestLiteScreen *mScreen;
Qt::WindowFlags window_flags;
- QPlatformGLContext *mGLContext;
-
- friend class QTestLiteWindowSurface; // x_window, gc and windowSurface
-};
-
-
+ Atom m_mwm_hint_atom;
+};
#endif
diff --git a/src/plugins/platforms/testlite/qtestlitewindowsurface.cpp b/src/plugins/platforms/testlite/qtestlitewindowsurface.cpp
index b3232c8..ced964a 100644
--- a/src/plugins/platforms/testlite/qtestlitewindowsurface.cpp
+++ b/src/plugins/platforms/testlite/qtestlitewindowsurface.cpp
@@ -46,6 +46,7 @@
#include <QWindowSystemInterface>
#include "qtestlitewindow.h"
+#include "qtestlitescreen.h"
# include <sys/ipc.h>
# include <sys/shm.h>
@@ -65,8 +66,6 @@ struct MyShmImageInfo {
Display *display;
};
-//void QTestLiteWindowSurface::flush()
-
#ifndef DONT_USE_MIT_SHM
void MyShmImageInfo::destroy()
@@ -80,20 +79,21 @@ void MyShmImageInfo::destroy()
void QTestLiteWindowSurface::resizeShmImage(int width, int height)
{
- MyDisplay *xd = xw->xd;
#ifdef DONT_USE_MIT_SHM
shm_img = QImage(width, height, QImage::Format_RGB32);
#else
+
+ QTestLiteScreen *screen = QTestLiteScreen::testLiteScreenForWidget(window());
if (image_info)
image_info->destroy();
else
- image_info = new MyShmImageInfo(xd->display);
+ image_info = new MyShmImageInfo(screen->display());
- Visual *visual = DefaultVisual(xd->display, xd->screen);
+ Visual *visual = DefaultVisual(screen->display(), screen->xScreenNumber());
- XImage *image = XShmCreateImage (xd->display, visual, 24, ZPixmap, 0,
+ XImage *image = XShmCreateImage (screen->display(), visual, 24, ZPixmap, 0,
&image_info->shminfo, width, height);
@@ -105,7 +105,7 @@ void QTestLiteWindowSurface::resizeShmImage(int width, int height)
image_info->image = image;
- Status shm_attach_status = XShmAttach(xd->display, &image_info->shminfo);
+ Status shm_attach_status = XShmAttach(screen->display(), &image_info->shminfo);
Q_ASSERT(shm_attach_status == True);
@@ -126,7 +126,7 @@ QSize QTestLiteWindowSurface::bufferSize() const
return shm_img.size();
}
-QTestLiteWindowSurface::QTestLiteWindowSurface (QTestLiteScreen */*screen*/, QWidget *window)
+QTestLiteWindowSurface::QTestLiteWindowSurface (QWidget *window)
: QWindowSurface(window),
painted(false), image_info(0)
{
@@ -151,29 +151,27 @@ void QTestLiteWindowSurface::flush(QWidget *widget, const QRegion &region, const
Q_UNUSED(region);
Q_UNUSED(offset);
- // qDebug() << "QTestLiteWindowSurface::flush:" << (long)this;
-
if (!painted)
return;
- MyDisplay *xd = xw->xd;
- GC gc = xw->gc;
- Window window = xw->x_window;
+ QTestLiteScreen *screen = QTestLiteScreen::testLiteScreenForWidget(widget);
+ GC gc = xw->graphicsContext();
+ Window window = xw->xWindow();
#ifdef DONT_USE_MIT_SHM
// just convert the image every time...
if (!shm_img.isNull()) {
- Visual *visual = DefaultVisual(xd->display, xd->screen);
+ Visual *visual = DefaultVisual(screen->display(), screen->xScreenNumber());
QImage image = shm_img;
//img.convertToFormat(
- XImage *xi = XCreateImage(xd->display, visual, 24, ZPixmap,
+ XImage *xi = XCreateImage(screen->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());
+ /*int r =*/ XPutImage(screen->display(), window, gc, xi, 0, 0, x, y, image.width(), image.height());
xi->data = 0; // QImage owns these bits
XDestroyImage(xi);
@@ -187,11 +185,11 @@ void QTestLiteWindowSurface::flush(QWidget *widget, const QRegion &region, const
// 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,
+ XShmPutImage (screen->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);
+ XSync(screen->display(), False);
}
#endif
}
diff --git a/src/plugins/platforms/testlite/qtestlitewindowsurface.h b/src/plugins/platforms/testlite/qtestlitewindowsurface.h
index 915e7fe..ca900e5 100644
--- a/src/plugins/platforms/testlite/qtestlitewindowsurface.h
+++ b/src/plugins/platforms/testlite/qtestlitewindowsurface.h
@@ -55,7 +55,7 @@ class MyShmImageInfo;
class QTestLiteWindowSurface : public QWindowSurface
{
public:
- QTestLiteWindowSurface (QTestLiteScreen *screen, QWidget *window);
+ QTestLiteWindowSurface (QWidget *window);
~QTestLiteWindowSurface();
QPaintDevice *paintDevice();
diff --git a/src/plugins/platforms/testlite/testlite.pro b/src/plugins/platforms/testlite/testlite.pro
index 05bd384..ef977bf 100644
--- a/src/plugins/platforms/testlite/testlite.pro
+++ b/src/plugins/platforms/testlite/testlite.pro
@@ -7,13 +7,16 @@ SOURCES = \
main.cpp \
qtestliteintegration.cpp \
qtestlitewindowsurface.cpp \
- qtestlitewindow.cpp
+ qtestlitewindow.cpp \
+ qtestlitecursor.cpp \
+ qtestlitescreen.cpp
HEADERS = \
qtestliteintegration.h \
qtestlitewindowsurface.h \
- qtestlitewindow.h
-
+ qtestlitewindow.h \
+ qtestlitecursor.h \
+ qtestlitescreen.h
LIBS += -lX11 -lXext