summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/xcb
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /src/plugins/platforms/xcb
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r--src/plugins/platforms/xcb/README3
-rw-r--r--src/plugins/platforms/xcb/main.cpp72
-rw-r--r--src/plugins/platforms/xcb/qdri2context.cpp271
-rw-r--r--src/plugins/platforms/xcb/qdri2context.h77
-rw-r--r--src/plugins/platforms/xcb/qglxintegration.cpp154
-rw-r--r--src/plugins/platforms/xcb/qglxintegration.h78
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.cpp780
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.h331
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.cpp151
-rw-r--r--src/plugins/platforms/xcb/qxcbintegration.h83
-rw-r--r--src/plugins/platforms/xcb/qxcbkeyboard.cpp973
-rw-r--r--src/plugins/platforms/xcb/qxcbkeyboard.h82
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.cpp185
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.h75
-rw-r--r--src/plugins/platforms/xcb/qxcbobject.h62
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.cpp134
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.h80
-rw-r--r--src/plugins/platforms/xcb/qxcbwindow.cpp683
-rw-r--r--src/plugins/platforms/xcb/qxcbwindow.h108
-rw-r--r--src/plugins/platforms/xcb/qxcbwindowsurface.cpp258
-rw-r--r--src/plugins/platforms/xcb/qxcbwindowsurface.h72
-rw-r--r--src/plugins/platforms/xcb/xcb.pro70
22 files changed, 4782 insertions, 0 deletions
diff --git a/src/plugins/platforms/xcb/README b/src/plugins/platforms/xcb/README
new file mode 100644
index 0000000000..17a86e6d08
--- /dev/null
+++ b/src/plugins/platforms/xcb/README
@@ -0,0 +1,3 @@
+Required packages:
+libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm1 libxcb-icccm1-dev libxcb-sync0 libxcb-sync0-dev
+
diff --git a/src/plugins/platforms/xcb/main.cpp b/src/plugins/platforms/xcb/main.cpp
new file mode 100644
index 0000000000..89bc66e052
--- /dev/null
+++ b/src/plugins/platforms/xcb/main.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 <QtGui/QPlatformIntegrationPlugin>
+#include "qxcbintegration.h"
+
+QT_BEGIN_NAMESPACE
+
+class QXcbIntegrationPlugin : public QPlatformIntegrationPlugin
+{
+public:
+ QStringList keys() const;
+ QPlatformIntegration *create(const QString&, const QStringList&);
+};
+
+QStringList QXcbIntegrationPlugin::keys() const
+{
+ QStringList list;
+ list << "xcb";
+ return list;
+}
+
+QPlatformIntegration* QXcbIntegrationPlugin::create(const QString& system, const QStringList& paramList)
+{
+ Q_UNUSED(paramList);
+ if (system.toLower() == "xcb")
+ return new QXcbIntegration;
+
+ return 0;
+}
+
+Q_EXPORT_PLUGIN2(xcb, QXcbIntegrationPlugin)
+
+QT_END_NAMESPACE
diff --git a/src/plugins/platforms/xcb/qdri2context.cpp b/src/plugins/platforms/xcb/qdri2context.cpp
new file mode 100644
index 0000000000..dbbfa67d8f
--- /dev/null
+++ b/src/plugins/platforms/xcb/qdri2context.cpp
@@ -0,0 +1,271 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qdri2context.h"
+
+#include "qxcbwindow.h"
+#include "qxcbconnection.h"
+
+#include <QtCore/QDebug>
+#include <QtGui/QWidget>
+
+#include <xcb/dri2.h>
+#include <xcb/xfixes.h>
+
+#define MESA_EGL_NO_X11_HEADERS
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#define GL_GLEXT_PROTOTYPES
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+class QDri2ContextPrivate
+{
+public:
+ QDri2ContextPrivate(QXcbWindow *window)
+ : qXcbWindow(window)
+ , windowFormat(window->widget()->platformWindowFormat())
+ , image(0)
+ {
+ }
+
+ xcb_window_t xcbWindow() { return qXcbWindow->window(); }
+ xcb_connection_t *xcbConnection() { return qXcbWindow->xcb_connection(); }
+
+ QXcbWindow *qXcbWindow;
+ QPlatformWindowFormat windowFormat;
+
+ EGLContext eglContext;
+
+ EGLImageKHR image;
+
+ GLuint fbo;
+ GLuint rbo;
+ GLuint depth;
+
+ QSize size;
+};
+
+QDri2Context::QDri2Context(QXcbWindow *window)
+ : d_ptr(new QDri2ContextPrivate(window))
+{
+ Q_D(QDri2Context);
+
+ static const EGLint contextAttribs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ EGLContext shareContext = EGL_NO_CONTEXT;
+ if (window->widget()->platformWindowFormat().sharedGLContext()) {
+ QDri2Context *context = static_cast<QDri2Context *>(window->widget()->platformWindowFormat().sharedGLContext());
+ shareContext = context->d_func()->eglContext;
+ }
+ d->eglContext = eglCreateContext(EGL_DISPLAY_FROM_XCB(d->qXcbWindow), NULL,
+ shareContext, contextAttribs);
+
+ if (d->eglContext == EGL_NO_CONTEXT) {
+ qDebug() << "No eglContext!" << eglGetError();
+ }
+
+ EGLBoolean makeCurrentSuccess = eglMakeCurrent(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,d->eglContext);
+ if (!makeCurrentSuccess) {
+ qDebug() << "eglMakeCurrent failed!" << eglGetError();
+ }
+
+ xcb_dri2_create_drawable (d->xcbConnection(), d->xcbWindow());
+
+ glGenFramebuffers(1,&d->fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER,d->fbo);
+ glActiveTexture(GL_TEXTURE0);
+
+ glGenRenderbuffers(1, &d->rbo);
+ glBindRenderbuffer(GL_RENDERBUFFER, d->rbo);
+
+ glGenRenderbuffers(1,&d->depth);
+ glBindRenderbuffer(GL_RENDERBUFFER, d->depth);
+
+ resize(d->qXcbWindow->widget()->geometry().size());
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, d->rbo);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERER,d->depth);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERER,d->depth);
+
+ //restore the old current context
+ const QPlatformGLContext *currentContext = QPlatformGLContext::currentContext();
+ if (currentContext)
+ const_cast<QPlatformGLContext*>(currentContext)->makeCurrent();
+}
+
+QDri2Context::~QDri2Context()
+{
+ //cleanup
+}
+
+void QDri2Context::makeCurrent()
+{
+ QPlatformGLContext::makeCurrent();
+ Q_D(QDri2Context);
+
+ eglMakeCurrent(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,d->eglContext);
+ glBindFramebuffer(GL_FRAMEBUFFER,d->fbo);
+
+}
+
+void QDri2Context::doneCurrent()
+{
+ QPlatformGLContext::doneCurrent();
+ Q_D(QDri2Context);
+ eglMakeCurrent(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT);
+}
+
+void QDri2Context::swapBuffers()
+{
+ Q_D(QDri2Context);
+ xcb_rectangle_t rectangle;
+ rectangle.x = 0;
+ rectangle.y = 0;
+ rectangle.width = d->qXcbWindow->widget()->geometry().width();
+ rectangle.height = d->qXcbWindow->widget()->geometry().height();
+
+ xcb_xfixes_region_t xfixesRegion = xcb_generate_id(d->xcbConnection());
+ xcb_xfixes_create_region(d->xcbConnection(), xfixesRegion,
+ 1, &rectangle);
+
+ xcb_dri2_copy_region_cookie_t cookie = xcb_dri2_copy_region_unchecked(d->xcbConnection(),
+ d->qXcbWindow->window(),
+ xfixesRegion,
+ XCB_DRI2_ATTACHMENT_BUFFER_FRONT_LEFT,
+ XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT);
+
+ xcb_dri2_copy_region_reply_t *reply = xcb_dri2_copy_region_reply(d->xcbConnection(),cookie,NULL);
+
+ //cleanup
+ delete reply;
+ xcb_xfixes_destroy_region(d->xcbConnection(), xfixesRegion);
+
+}
+
+void * QDri2Context::getProcAddress(const QString &procName)
+{
+ return (void *)eglGetProcAddress(qPrintable(procName));
+}
+
+void QDri2Context::resize(const QSize &size)
+{
+ Q_D(QDri2Context);
+ d->size= size;
+
+ glBindFramebuffer(GL_FRAMEBUFFER,d->fbo);
+
+ xcb_dri2_dri2_buffer_t *backBfr = backBuffer();
+
+ if (d->image) {
+ qDebug() << "destroing image";
+ eglDestroyImageKHR(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),d->image);
+ }
+
+ EGLint imgAttribs[] = {
+ EGL_WIDTH, d->size.width(),
+ EGL_HEIGHT, d->size.height(),
+ EGL_DRM_BUFFER_STRIDE_MESA, backBfr->pitch /4,
+ EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
+ EGL_NONE
+ };
+
+ d->image = eglCreateImageKHR(EGL_DISPLAY_FROM_XCB(d->qXcbWindow),
+ EGL_NO_CONTEXT,
+ EGL_DRM_BUFFER_MESA,
+ (EGLClientBuffer) backBfr->name,
+ imgAttribs);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, d->rbo);
+ glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
+ d->image);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, d->depth);
+ glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8_OES,d->size.width(), d->size.height());
+
+}
+
+QPlatformWindowFormat QDri2Context::platformWindowFormat() const
+{
+ Q_D(const QDri2Context);
+ return d->windowFormat;
+}
+
+xcb_dri2_dri2_buffer_t * QDri2Context::backBuffer()
+{
+ Q_D(QDri2Context);
+
+ unsigned int backBufferAttachment = XCB_DRI2_ATTACHMENT_BUFFER_BACK_LEFT;
+ xcb_dri2_get_buffers_cookie_t cookie = xcb_dri2_get_buffers_unchecked (d->xcbConnection(),
+ d->xcbWindow(),
+ 1, 1, &backBufferAttachment);
+
+ xcb_dri2_get_buffers_reply_t *reply = xcb_dri2_get_buffers_reply (d->xcbConnection(), cookie, NULL);
+ if (!reply) {
+ qDebug() << "failed to get buffers reply";
+ return 0;
+ }
+
+ xcb_dri2_dri2_buffer_t *buffers = xcb_dri2_get_buffers_buffers (reply);
+ if (!buffers) {
+ qDebug() << "failed to get buffers";
+ return 0;
+ }
+
+ Q_ASSERT(reply->count == 1);
+
+ delete reply;
+
+ return buffers;
+}
+
+void * QDri2Context::eglContext() const
+{
+ Q_D(const QDri2Context);
+ return d->eglContext;
+}
diff --git a/src/plugins/platforms/xcb/qdri2context.h b/src/plugins/platforms/xcb/qdri2context.h
new file mode 100644
index 0000000000..42dd6bd590
--- /dev/null
+++ b/src/plugins/platforms/xcb/qdri2context.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QDRI2CONTEXT_H
+#define QDRI2CONTEXT_H
+
+#include <QtGui/QPlatformGLContext>
+
+class QXcbWindow;
+class QDri2ContextPrivate;
+
+struct xcb_dri2_dri2_buffer_t;
+
+class QDri2Context : public QPlatformGLContext
+{
+ Q_DECLARE_PRIVATE(QDri2Context);
+public:
+ QDri2Context(QXcbWindow *window);
+ ~QDri2Context();
+
+ void makeCurrent();
+ void doneCurrent();
+ void swapBuffers();
+ void* getProcAddress(const QString& procName);
+
+ void resize(const QSize &size);
+
+ QPlatformWindowFormat platformWindowFormat() const;
+
+ void *eglContext() const;
+
+protected:
+ xcb_dri2_dri2_buffer_t *backBuffer();
+ QScopedPointer<QDri2ContextPrivate> d_ptr;
+private:
+ Q_DISABLE_COPY(QDri2Context)
+};
+
+#endif // QDRI2CONTEXT_H
diff --git a/src/plugins/platforms/xcb/qglxintegration.cpp b/src/plugins/platforms/xcb/qglxintegration.cpp
new file mode 100644
index 0000000000..190221c5f4
--- /dev/null
+++ b/src/plugins/platforms/xcb/qglxintegration.cpp
@@ -0,0 +1,154 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 <QDebug>
+#include <QLibrary>
+#include <QGLFormat>
+
+#include "qxcbwindow.h"
+#include "qxcbscreen.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <GL/glx.h>
+
+#include "qglxintegration.h"
+#include "qglxconvenience.h"
+
+#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
+#include <dlfcn.h>
+#endif
+
+QGLXContext::QGLXContext(Window window, QXcbScreen *screen, const QPlatformWindowFormat &format)
+ : QPlatformGLContext()
+ , m_screen(screen)
+ , m_drawable((Drawable)window)
+ , m_context(0)
+{
+ Q_XCB_NOOP(m_screen->connection());
+ const QPlatformGLContext *sharePlatformContext;
+ sharePlatformContext = format.sharedGLContext();
+ GLXContext shareGlxContext = 0;
+ if (sharePlatformContext)
+ shareGlxContext = static_cast<const QGLXContext*>(sharePlatformContext)->glxContext();
+
+ GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),format);
+ m_context = glXCreateNewContext(DISPLAY_FROM_XCB(screen), config, GLX_RGBA_TYPE, shareGlxContext, TRUE);
+ m_windowFormat = qglx_platformWindowFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context);
+ Q_XCB_NOOP(m_screen->connection());
+}
+
+QGLXContext::QGLXContext(QXcbScreen *screen, Drawable drawable, GLXContext context)
+ : QPlatformGLContext(), m_screen(screen), m_drawable(drawable), m_context(context)
+{
+
+}
+
+QGLXContext::~QGLXContext()
+{
+ Q_XCB_NOOP(m_screen->connection());
+ if (m_context)
+ glXDestroyContext(DISPLAY_FROM_XCB(m_screen), m_context);
+ Q_XCB_NOOP(m_screen->connection());
+}
+
+void QGLXContext::makeCurrent()
+{
+ Q_XCB_NOOP(m_screen->connection());
+ QPlatformGLContext::makeCurrent();
+ glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), m_drawable, m_context);
+ Q_XCB_NOOP(m_screen->connection());
+}
+
+void QGLXContext::doneCurrent()
+{
+ Q_XCB_NOOP(m_screen->connection());
+ QPlatformGLContext::doneCurrent();
+ glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0);
+ Q_XCB_NOOP(m_screen->connection());
+}
+
+void QGLXContext::swapBuffers()
+{
+ Q_XCB_NOOP(m_screen->connection());
+ glXSwapBuffers(DISPLAY_FROM_XCB(m_screen), m_drawable);
+ doneCurrent();
+ Q_XCB_NOOP(m_screen->connection());
+}
+
+void* QGLXContext::getProcAddress(const QString& procName)
+{
+ Q_XCB_NOOP(m_screen->connection());
+ typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *);
+ static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
+ static bool resolved = false;
+
+ if (resolved && !glXGetProcAddressARB)
+ return 0;
+ if (!glXGetProcAddressARB) {
+ QList<QByteArray> glxExt = QByteArray(glXGetClientString(DISPLAY_FROM_XCB(m_screen), 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);
+ if (handle) {
+ glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB");
+ dlclose(handle);
+ }
+ if (!glXGetProcAddressARB)
+#endif
+ {
+ extern const QString qt_gl_library_name();
+// QLibrary lib(qt_gl_library_name());
+ QLibrary lib(QLatin1String("GL"));
+ glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
+ }
+ }
+ resolved = true;
+ }
+ if (!glXGetProcAddressARB)
+ return 0;
+ return glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.toLatin1().data()));
+}
+
+QPlatformWindowFormat QGLXContext::platformWindowFormat() const
+{
+ return m_windowFormat;
+}
diff --git a/src/plugins/platforms/xcb/qglxintegration.h b/src/plugins/platforms/xcb/qglxintegration.h
new file mode 100644
index 0000000000..99b72a04b5
--- /dev/null
+++ b/src/plugins/platforms/xcb/qglxintegration.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QGLXINTEGRATION_H
+#define QGLXINTEGRATION_H
+
+#include "qxcbwindow.h"
+
+#include <QtGui/QPlatformGLContext>
+#include <QtGui/QPlatformWindowFormat>
+
+#include <QtCore/QMutex>
+
+#include <GL/glx.h>
+
+class QGLXContext : public QPlatformGLContext
+{
+public:
+ QGLXContext(Window window, QXcbScreen *xd, const QPlatformWindowFormat &format);
+ ~QGLXContext();
+
+ virtual void makeCurrent();
+ virtual void doneCurrent();
+ virtual void swapBuffers();
+ virtual void* getProcAddress(const QString& procName);
+
+ GLXContext glxContext() const { return m_context; }
+
+ QPlatformWindowFormat platformWindowFormat() const;
+
+private:
+ QXcbScreen *m_screen;
+ Drawable m_drawable;
+ GLXContext m_context;
+ QPlatformWindowFormat m_windowFormat;
+
+ QGLXContext (QXcbScreen *screen, Drawable drawable, GLXContext context);
+};
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
new file mode 100644
index 0000000000..7ad12fe8b1
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -0,0 +1,780 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qxcbconnection.h"
+#include "qxcbkeyboard.h"
+#include "qxcbscreen.h"
+#include "qxcbwindow.h"
+
+#include <QtAlgorithms>
+#include <QSocketNotifier>
+#include <QtGui/private/qapplication_p.h>
+#include <QAbstractEventDispatcher>
+
+#include <QtCore/QDebug>
+
+#include <stdio.h>
+#include <errno.h>
+
+#ifdef XCB_USE_XLIB
+#include <X11/Xlib.h>
+#include <X11/Xlib-xcb.h>
+#endif
+
+#ifdef XCB_USE_EGL //dont pull in eglext prototypes
+#include <EGL/egl.h>
+#endif
+
+#ifdef XCB_USE_DRI2
+#include <xcb/dri2.h>
+#include <xcb/xfixes.h>
+extern "C" {
+#include <xf86drm.h>
+}
+#define MESA_EGL_NO_X11_HEADERS
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#endif
+
+QXcbConnection::QXcbConnection(const char *displayName)
+ : m_displayName(displayName ? QByteArray(displayName) : qgetenv("DISPLAY"))
+#ifdef XCB_USE_DRI2
+ , m_dri2_major(0)
+ , m_dri2_minor(0)
+ , m_dri2_support_probed(false)
+ , m_has_support_for_dri2(false)
+#endif
+{
+ int primaryScreen = 0;
+
+#ifdef XCB_USE_XLIB
+ Display *dpy = XOpenDisplay(m_displayName.constData());
+ primaryScreen = DefaultScreen(dpy);
+ m_connection = XGetXCBConnection(dpy);
+ XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
+ m_xlib_display = dpy;
+#ifdef XCB_USE_EGL
+ EGLDisplay eglDisplay = eglGetDisplay(dpy);
+ m_egl_display = eglDisplay;
+ EGLint major, minor;
+ eglBindAPI(EGL_OPENGL_ES_API);
+ m_has_egl = eglInitialize(eglDisplay,&major,&minor);
+#endif //XCB_USE_EGL
+#else
+ m_connection = xcb_connect(m_displayName.constData(), &primaryScreen);
+
+#endif //XCB_USE_XLIB
+ m_setup = xcb_get_setup(xcb_connection());
+
+ initializeAllAtoms();
+
+ xcb_screen_iterator_t it = xcb_setup_roots_iterator(m_setup);
+
+ int screenNumber = 0;
+ while (it.rem) {
+ m_screens << new QXcbScreen(this, it.data, screenNumber++);
+ xcb_screen_next(&it);
+ }
+
+ m_keyboard = new QXcbKeyboard(this);
+
+#ifdef XCB_USE_DRI2
+ initializeDri2();
+#endif
+
+ QSocketNotifier *notifier = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this);
+ connect(notifier, SIGNAL(activated(int)), this, SLOT(processXcbEvents()));
+
+ QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(qApp->thread());
+ connect(dispatcher, SIGNAL(aboutToBlock()), this, SLOT(processXcbEvents()));
+
+ sync();
+}
+
+QXcbConnection::~QXcbConnection()
+{
+ qDeleteAll(m_screens);
+
+#ifdef XCB_USE_XLIB
+ XCloseDisplay((Display *)m_xlib_display);
+#else
+ xcb_disconnect(xcb_connection());
+#endif
+
+ delete m_keyboard;
+}
+
+QXcbWindow *platformWindowFromId(xcb_window_t id)
+{
+ QWidget *widget = QWidget::find(id);
+ if (widget)
+ return static_cast<QXcbWindow *>(widget->platformWindow());
+ return 0;
+}
+
+#define HANDLE_PLATFORM_WINDOW_EVENT(event_t, window, handler) \
+{ \
+ event_t *e = (event_t *)event; \
+ if (QXcbWindow *platformWindow = platformWindowFromId(e->window)) { \
+ QObjectPrivate *d = QObjectPrivate::get(platformWindow->widget()); \
+ if (!d->wasDeleted) \
+ platformWindow->handler(e); \
+ } \
+} \
+break;
+
+#define HANDLE_KEYBOARD_EVENT(event_t, handler) \
+{ \
+ event_t *e = (event_t *)event; \
+ if (QXcbWindow *platformWindow = platformWindowFromId(e->event)) \
+ m_keyboard->handler(platformWindow->widget(), e); \
+} \
+break;
+
+//#define XCB_EVENT_DEBUG
+
+void printXcbEvent(const char *message, xcb_generic_event_t *event)
+{
+#ifdef XCB_EVENT_DEBUG
+#define PRINT_XCB_EVENT(ev) \
+ case ev: \
+ printf("%s: %d - %s - sequence: %d\n", message, int(ev), #ev, event->sequence); \
+ break;
+
+ switch (event->response_type & ~0x80) {
+ PRINT_XCB_EVENT(XCB_KEY_PRESS);
+ PRINT_XCB_EVENT(XCB_KEY_RELEASE);
+ PRINT_XCB_EVENT(XCB_BUTTON_PRESS);
+ PRINT_XCB_EVENT(XCB_BUTTON_RELEASE);
+ PRINT_XCB_EVENT(XCB_MOTION_NOTIFY);
+ PRINT_XCB_EVENT(XCB_ENTER_NOTIFY);
+ PRINT_XCB_EVENT(XCB_LEAVE_NOTIFY);
+ PRINT_XCB_EVENT(XCB_FOCUS_IN);
+ PRINT_XCB_EVENT(XCB_FOCUS_OUT);
+ PRINT_XCB_EVENT(XCB_KEYMAP_NOTIFY);
+ PRINT_XCB_EVENT(XCB_EXPOSE);
+ PRINT_XCB_EVENT(XCB_GRAPHICS_EXPOSURE);
+ PRINT_XCB_EVENT(XCB_VISIBILITY_NOTIFY);
+ PRINT_XCB_EVENT(XCB_CREATE_NOTIFY);
+ PRINT_XCB_EVENT(XCB_DESTROY_NOTIFY);
+ PRINT_XCB_EVENT(XCB_UNMAP_NOTIFY);
+ PRINT_XCB_EVENT(XCB_MAP_NOTIFY);
+ PRINT_XCB_EVENT(XCB_MAP_REQUEST);
+ PRINT_XCB_EVENT(XCB_REPARENT_NOTIFY);
+ PRINT_XCB_EVENT(XCB_CONFIGURE_NOTIFY);
+ PRINT_XCB_EVENT(XCB_CONFIGURE_REQUEST);
+ PRINT_XCB_EVENT(XCB_GRAVITY_NOTIFY);
+ PRINT_XCB_EVENT(XCB_RESIZE_REQUEST);
+ PRINT_XCB_EVENT(XCB_CIRCULATE_NOTIFY);
+ PRINT_XCB_EVENT(XCB_CIRCULATE_REQUEST);
+ PRINT_XCB_EVENT(XCB_PROPERTY_NOTIFY);
+ PRINT_XCB_EVENT(XCB_SELECTION_CLEAR);
+ PRINT_XCB_EVENT(XCB_SELECTION_REQUEST);
+ PRINT_XCB_EVENT(XCB_SELECTION_NOTIFY);
+ PRINT_XCB_EVENT(XCB_COLORMAP_NOTIFY);
+ PRINT_XCB_EVENT(XCB_CLIENT_MESSAGE);
+ PRINT_XCB_EVENT(XCB_MAPPING_NOTIFY);
+ default:
+ printf("%s: unknown event - response_type: %d - sequence: %d\n", message, int(event->response_type & ~0x80), int(event->sequence));
+ }
+#else
+ Q_UNUSED(message);
+ Q_UNUSED(event);
+#endif
+}
+
+const char *xcb_errors[] =
+{
+ "Success",
+ "BadRequest",
+ "BadValue",
+ "BadWindow",
+ "BadPixmap",
+ "BadAtom",
+ "BadCursor",
+ "BadFont",
+ "BadMatch",
+ "BadDrawable",
+ "BadAccess",
+ "BadAlloc",
+ "BadColor",
+ "BadGC",
+ "BadIDChoice",
+ "BadName",
+ "BadLength",
+ "BadImplementation",
+ "Unknown"
+};
+
+const char *xcb_protocol_request_codes[] =
+{
+ "Null",
+ "CreateWindow",
+ "ChangeWindowAttributes",
+ "GetWindowAttributes",
+ "DestroyWindow",
+ "DestroySubwindows",
+ "ChangeSaveSet",
+ "ReparentWindow",
+ "MapWindow",
+ "MapSubwindows",
+ "UnmapWindow",
+ "UnmapSubwindows",
+ "ConfigureWindow",
+ "CirculateWindow",
+ "GetGeometry",
+ "QueryTree",
+ "InternAtom",
+ "GetAtomName",
+ "ChangeProperty",
+ "DeleteProperty",
+ "GetProperty",
+ "ListProperties",
+ "SetSelectionOwner",
+ "GetSelectionOwner",
+ "ConvertSelection",
+ "SendEvent",
+ "GrabPointer",
+ "UngrabPointer",
+ "GrabButton",
+ "UngrabButton",
+ "ChangeActivePointerGrab",
+ "GrabKeyboard",
+ "UngrabKeyboard",
+ "GrabKey",
+ "UngrabKey",
+ "AllowEvents",
+ "GrabServer",
+ "UngrabServer",
+ "QueryPointer",
+ "GetMotionEvents",
+ "TranslateCoords",
+ "WarpPointer",
+ "SetInputFocus",
+ "GetInputFocus",
+ "QueryKeymap",
+ "OpenFont",
+ "CloseFont",
+ "QueryFont",
+ "QueryTextExtents",
+ "ListFonts",
+ "ListFontsWithInfo",
+ "SetFontPath",
+ "GetFontPath",
+ "CreatePixmap",
+ "FreePixmap",
+ "CreateGC",
+ "ChangeGC",
+ "CopyGC",
+ "SetDashes",
+ "SetClipRectangles",
+ "FreeGC",
+ "ClearArea",
+ "CopyArea",
+ "CopyPlane",
+ "PolyPoint",
+ "PolyLine",
+ "PolySegment",
+ "PolyRectangle",
+ "PolyArc",
+ "FillPoly",
+ "PolyFillRectangle",
+ "PolyFillArc",
+ "PutImage",
+ "GetImage",
+ "PolyText8",
+ "PolyText16",
+ "ImageText8",
+ "ImageText16",
+ "CreateColormap",
+ "FreeColormap",
+ "CopyColormapAndFree",
+ "InstallColormap",
+ "UninstallColormap",
+ "ListInstalledColormaps",
+ "AllocColor",
+ "AllocNamedColor",
+ "AllocColorCells",
+ "AllocColorPlanes",
+ "FreeColors",
+ "StoreColors",
+ "StoreNamedColor",
+ "QueryColors",
+ "LookupColor",
+ "CreateCursor",
+ "CreateGlyphCursor",
+ "FreeCursor",
+ "RecolorCursor",
+ "QueryBestSize",
+ "QueryExtension",
+ "ListExtensions",
+ "ChangeKeyboardMapping",
+ "GetKeyboardMapping",
+ "ChangeKeyboardControl",
+ "GetKeyboardControl",
+ "Bell",
+ "ChangePointerControl",
+ "GetPointerControl",
+ "SetScreenSaver",
+ "GetScreenSaver",
+ "ChangeHosts",
+ "ListHosts",
+ "SetAccessControl",
+ "SetCloseDownMode",
+ "KillClient",
+ "RotateProperties",
+ "ForceScreenSaver",
+ "SetPointerMapping",
+ "GetPointerMapping",
+ "SetModifierMapping",
+ "GetModifierMapping",
+ "Unknown"
+};
+
+#ifdef Q_XCB_DEBUG
+void QXcbConnection::log(const char *file, int line, int sequence)
+{
+ CallInfo info;
+ info.sequence = sequence;
+ info.file = file;
+ info.line = line;
+ m_callLog << info;
+}
+#endif
+
+void QXcbConnection::handleXcbError(xcb_generic_error_t *error)
+{
+ uint clamped_error_code = qMin<uint>(error->error_code, (sizeof(xcb_errors) / sizeof(xcb_errors[0])) - 1);
+ uint clamped_major_code = qMin<uint>(error->major_code, (sizeof(xcb_protocol_request_codes) / sizeof(xcb_protocol_request_codes[0])) - 1);
+
+ printf("XCB error: %d (%s), sequence: %d, resource id: %d, major code: %d (%s), minor code: %d\n",
+ int(error->error_code), xcb_errors[clamped_error_code],
+ int(error->sequence), int(error->resource_id),
+ int(error->major_code), xcb_protocol_request_codes[clamped_major_code],
+ int(error->minor_code));
+#ifdef Q_XCB_DEBUG
+ int i = 0;
+ for (; i < m_callLog.size(); ++i) {
+ if (m_callLog.at(i).sequence == error->sequence) {
+ printf("Caused by: %s:%d\n", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line);
+ break;
+ } else if (m_callLog.at(i).sequence > error->sequence) {
+ printf("Caused some time before: %s:%d\n", qPrintable(m_callLog.at(i).file), m_callLog.at(i).line);
+ if (i > 0)
+ printf("and after: %s:%d\n", qPrintable(m_callLog.at(i-1).file), m_callLog.at(i-1).line);
+ break;
+ }
+ }
+ if (i == m_callLog.size() && !m_callLog.isEmpty())
+ printf("Caused some time after: %s:%d\n", qPrintable(m_callLog.first().file), m_callLog.first().line);
+#endif
+}
+
+void QXcbConnection::processXcbEvents()
+{
+ while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection())) {
+ bool handled = true;
+
+ uint response_type = event->response_type & ~0x80;
+
+ if (!response_type) {
+ handleXcbError((xcb_generic_error_t *)event);
+ continue;
+ }
+
+#ifdef Q_XCB_DEBUG
+ {
+ int i = 0;
+ for (; i < m_callLog.size(); ++i)
+ if (m_callLog.at(i).sequence >= event->sequence)
+ break;
+ m_callLog.remove(0, i);
+ }
+#endif
+
+ switch (response_type) {
+ case XCB_EXPOSE:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_expose_event_t, window, handleExposeEvent);
+ case XCB_BUTTON_PRESS:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_press_event_t, event, handleButtonPressEvent);
+ case XCB_BUTTON_RELEASE:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_release_event_t, event, handleButtonReleaseEvent);
+ case XCB_MOTION_NOTIFY:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_motion_notify_event_t, event, handleMotionNotifyEvent);
+ case XCB_CONFIGURE_NOTIFY:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_configure_notify_event_t, event, handleConfigureNotifyEvent);
+ case XCB_CLIENT_MESSAGE:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_client_message_event_t, window, handleClientMessageEvent);
+ case XCB_ENTER_NOTIFY:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_enter_notify_event_t, event, handleEnterNotifyEvent);
+ case XCB_LEAVE_NOTIFY:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_leave_notify_event_t, event, handleLeaveNotifyEvent);
+ case XCB_FOCUS_IN:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_focus_in_event_t, event, handleFocusInEvent);
+ case XCB_FOCUS_OUT:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_focus_out_event_t, event, handleFocusOutEvent);
+ case XCB_KEY_PRESS:
+ HANDLE_KEYBOARD_EVENT(xcb_key_press_event_t, handleKeyPressEvent);
+ case XCB_KEY_RELEASE:
+ HANDLE_KEYBOARD_EVENT(xcb_key_release_event_t, handleKeyReleaseEvent);
+ case XCB_MAPPING_NOTIFY:
+ m_keyboard->handleMappingNotifyEvent((xcb_mapping_notify_event_t *)event);
+ break;
+ default:
+ handled = false;
+ break;
+ }
+ if (handled)
+ printXcbEvent("Handled XCB event", event);
+ else
+ printXcbEvent("Unhandled XCB event", event);
+ }
+
+ xcb_flush(xcb_connection());
+}
+
+static const char * xcb_atomnames = {
+ // window-manager <-> client protocols
+ "WM_PROTOCOLS\0"
+ "WM_DELETE_WINDOW\0"
+ "WM_TAKE_FOCUS\0"
+ "_NET_WM_PING\0"
+ "_NET_WM_CONTEXT_HELP\0"
+ "_NET_WM_SYNC_REQUEST\0"
+ "_NET_WM_SYNC_REQUEST_COUNTER\0"
+
+ // ICCCM window state
+ "WM_STATE\0"
+ "WM_CHANGE_STATE\0"
+
+ // Session management
+ "WM_CLIENT_LEADER\0"
+ "WM_WINDOW_ROLE\0"
+ "SM_CLIENT_ID\0"
+
+ // Clipboard
+ "CLIPBOARD\0"
+ "INCR\0"
+ "TARGETS\0"
+ "MULTIPLE\0"
+ "TIMESTAMP\0"
+ "SAVE_TARGETS\0"
+ "CLIP_TEMPORARY\0"
+ "_QT_SELECTION\0"
+ "_QT_CLIPBOARD_SENTINEL\0"
+ "_QT_SELECTION_SENTINEL\0"
+ "CLIPBOARD_MANAGER\0"
+
+ "RESOURCE_MANAGER\0"
+
+ "_XSETROOT_ID\0"
+
+ "_QT_SCROLL_DONE\0"
+ "_QT_INPUT_ENCODING\0"
+
+ "_MOTIF_WM_HINTS\0"
+
+ "DTWM_IS_RUNNING\0"
+ "ENLIGHTENMENT_DESKTOP\0"
+ "_DT_SAVE_MODE\0"
+ "_SGI_DESKS_MANAGER\0"
+
+ // EWMH (aka NETWM)
+ "_NET_SUPPORTED\0"
+ "_NET_VIRTUAL_ROOTS\0"
+ "_NET_WORKAREA\0"
+
+ "_NET_MOVERESIZE_WINDOW\0"
+ "_NET_WM_MOVERESIZE\0"
+
+ "_NET_WM_NAME\0"
+ "_NET_WM_ICON_NAME\0"
+ "_NET_WM_ICON\0"
+
+ "_NET_WM_PID\0"
+
+ "_NET_WM_WINDOW_OPACITY\0"
+
+ "_NET_WM_STATE\0"
+ "_NET_WM_STATE_ABOVE\0"
+ "_NET_WM_STATE_BELOW\0"
+ "_NET_WM_STATE_FULLSCREEN\0"
+ "_NET_WM_STATE_MAXIMIZED_HORZ\0"
+ "_NET_WM_STATE_MAXIMIZED_VERT\0"
+ "_NET_WM_STATE_MODAL\0"
+ "_NET_WM_STATE_STAYS_ON_TOP\0"
+ "_NET_WM_STATE_DEMANDS_ATTENTION\0"
+
+ "_NET_WM_USER_TIME\0"
+ "_NET_WM_USER_TIME_WINDOW\0"
+ "_NET_WM_FULL_PLACEMENT\0"
+
+ "_NET_WM_WINDOW_TYPE\0"
+ "_NET_WM_WINDOW_TYPE_DESKTOP\0"
+ "_NET_WM_WINDOW_TYPE_DOCK\0"
+ "_NET_WM_WINDOW_TYPE_TOOLBAR\0"
+ "_NET_WM_WINDOW_TYPE_MENU\0"
+ "_NET_WM_WINDOW_TYPE_UTILITY\0"
+ "_NET_WM_WINDOW_TYPE_SPLASH\0"
+ "_NET_WM_WINDOW_TYPE_DIALOG\0"
+ "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0"
+ "_NET_WM_WINDOW_TYPE_POPUP_MENU\0"
+ "_NET_WM_WINDOW_TYPE_TOOLTIP\0"
+ "_NET_WM_WINDOW_TYPE_NOTIFICATION\0"
+ "_NET_WM_WINDOW_TYPE_COMBO\0"
+ "_NET_WM_WINDOW_TYPE_DND\0"
+ "_NET_WM_WINDOW_TYPE_NORMAL\0"
+ "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE\0"
+
+ "_KDE_NET_WM_FRAME_STRUT\0"
+
+ "_NET_STARTUP_INFO\0"
+ "_NET_STARTUP_INFO_BEGIN\0"
+
+ "_NET_SUPPORTING_WM_CHECK\0"
+
+ "_NET_WM_CM_S0\0"
+
+ "_NET_SYSTEM_TRAY_VISUAL\0"
+
+ "_NET_ACTIVE_WINDOW\0"
+
+ // Property formats
+ "COMPOUND_TEXT\0"
+ "TEXT\0"
+ "UTF8_STRING\0"
+
+ // xdnd
+ "XdndEnter\0"
+ "XdndPosition\0"
+ "XdndStatus\0"
+ "XdndLeave\0"
+ "XdndDrop\0"
+ "XdndFinished\0"
+ "XdndTypeList\0"
+ "XdndActionList\0"
+
+ "XdndSelection\0"
+
+ "XdndAware\0"
+ "XdndProxy\0"
+
+ "XdndActionCopy\0"
+ "XdndActionLink\0"
+ "XdndActionMove\0"
+ "XdndActionPrivate\0"
+
+ // Motif DND
+ "_MOTIF_DRAG_AND_DROP_MESSAGE\0"
+ "_MOTIF_DRAG_INITIATOR_INFO\0"
+ "_MOTIF_DRAG_RECEIVER_INFO\0"
+ "_MOTIF_DRAG_WINDOW\0"
+ "_MOTIF_DRAG_TARGETS\0"
+
+ "XmTRANSFER_SUCCESS\0"
+ "XmTRANSFER_FAILURE\0"
+
+ // Xkb
+ "_XKB_RULES_NAMES\0"
+
+ // XEMBED
+ "_XEMBED\0"
+ "_XEMBED_INFO\0"
+
+ // Wacom old. (before version 0.10)
+ "Wacom Stylus\0"
+ "Wacom Cursor\0"
+ "Wacom Eraser\0"
+
+ // Tablet
+ "STYLUS\0"
+ "ERASER\0"
+};
+
+xcb_atom_t QXcbConnection::atom(QXcbAtom::Atom atom)
+{
+ return m_allAtoms[atom];
+}
+
+void QXcbConnection::initializeAllAtoms() {
+ const char *names[QXcbAtom::NAtoms];
+ const char *ptr = xcb_atomnames;
+
+ int i = 0;
+ while (*ptr) {
+ names[i++] = ptr;
+ while (*ptr)
+ ++ptr;
+ ++ptr;
+ }
+
+ Q_ASSERT(i == QXcbAtom::NPredefinedAtoms);
+
+ QByteArray settings_atom_name("_QT_SETTINGS_TIMESTAMP_");
+ settings_atom_name += m_displayName;
+ names[i++] = settings_atom_name;
+
+ xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms];
+
+ Q_ASSERT(i == QXcbAtom::NAtoms);
+ for (i = 0; i < QXcbAtom::NAtoms; ++i)
+ cookies[i] = xcb_intern_atom(xcb_connection(), false, strlen(names[i]), names[i]);
+
+ for (i = 0; i < QXcbAtom::NAtoms; ++i)
+ m_allAtoms[i] = xcb_intern_atom_reply(xcb_connection(), cookies[i], 0)->atom;
+}
+
+void QXcbConnection::sync()
+{
+ // from xcb_aux_sync
+ xcb_get_input_focus_cookie_t cookie = Q_XCB_CALL(xcb_get_input_focus(xcb_connection()));
+ free(xcb_get_input_focus_reply(xcb_connection(), cookie, 0));
+}
+
+#if defined(XCB_USE_EGL)
+bool QXcbConnection::hasEgl() const
+{
+ return m_has_egl;
+}
+#endif // defined(XCB_USE_EGL)
+
+#ifdef XCB_USE_DRI2
+void QXcbConnection::initializeDri2()
+{
+ xcb_dri2_connect_cookie_t connect_cookie = xcb_dri2_connect_unchecked (m_connection,
+ m_screens[0]->root(),
+ XCB_DRI2_DRIVER_TYPE_DRI);
+
+ xcb_dri2_connect_reply_t *connect = xcb_dri2_connect_reply (m_connection,
+ connect_cookie, NULL);
+
+ if (! connect || connect->driver_name_length + connect->device_name_length == 0) {
+ qDebug() << "Failed to connect to dri2";
+ return;
+ }
+
+ m_dri2_device_name = QByteArray(xcb_dri2_connect_device_name (connect),
+ xcb_dri2_connect_device_name_length (connect));
+ delete connect;
+
+ int fd = open(m_dri2_device_name.constData(), O_RDWR);
+ if (fd < 0) {
+ qDebug() << "InitializeDri2: Could'nt open device << dri2DeviceName";
+ m_dri2_device_name = QByteArray();
+ return;
+ }
+
+ drm_magic_t magic;
+ if (drmGetMagic(fd, &magic)) {
+ qDebug() << "Failed to get drmMagic";
+ return;
+ }
+
+ xcb_dri2_authenticate_cookie_t authenticate_cookie = xcb_dri2_authenticate_unchecked(m_connection,
+ m_screens[0]->root(), magic);
+ xcb_dri2_authenticate_reply_t *authenticate = xcb_dri2_authenticate_reply(m_connection,
+ authenticate_cookie, NULL);
+ if (authenticate == NULL || !authenticate->authenticated) {
+ fprintf(stderr, "DRI2: failed to authenticate\n");
+ free(authenticate);
+ return;
+ }
+
+ delete authenticate;
+
+ EGLDisplay display = eglGetDRMDisplayMESA(fd);
+ if (!display) {
+ fprintf(stderr, "failed to create display\n");
+ return;
+ }
+
+ m_egl_display = display;
+ EGLint major,minor;
+ if (!eglInitialize(display, &major, &minor)) {
+ fprintf(stderr, "failed to initialize display\n");
+ return;
+ }
+}
+
+bool QXcbConnection::hasSupportForDri2() const
+{
+ if (!m_dri2_support_probed) {
+ xcb_generic_error_t *error = 0;
+
+ xcb_prefetch_extension_data (m_connection, &xcb_xfixes_id);
+ xcb_prefetch_extension_data (m_connection, &xcb_dri2_id);
+
+ xcb_xfixes_query_version_cookie_t xfixes_query_cookie = xcb_xfixes_query_version(m_connection,
+ XCB_XFIXES_MAJOR_VERSION,
+ XCB_XFIXES_MINOR_VERSION);
+
+ xcb_dri2_query_version_cookie_t dri2_query_cookie = xcb_dri2_query_version (m_connection,
+ XCB_DRI2_MAJOR_VERSION,
+ XCB_DRI2_MINOR_VERSION);
+
+ xcb_xfixes_query_version_reply_t *xfixes_query = xcb_xfixes_query_version_reply (m_connection,
+ xfixes_query_cookie, &error);
+ if (!xfixes_query || error || xfixes_query->major_version < 2) {
+ delete error;
+ delete xfixes_query;
+ return false;
+ }
+ delete xfixes_query;
+
+ xcb_dri2_query_version_reply_t *dri2_query = xcb_dri2_query_version_reply (m_connection,
+ dri2_query_cookie, &error);
+ if (!dri2_query || error) {
+ delete error;
+ delete dri2_query;
+ return false;
+ }
+
+ QXcbConnection *that = const_cast<QXcbConnection *>(this);
+ that->m_dri2_major = dri2_query->major_version;
+ that->m_dri2_minor = dri2_query->minor_version;
+
+ that->m_has_support_for_dri2 = true;
+ that->m_dri2_support_probed = true;
+ }
+ return m_has_support_for_dri2;
+}
+#endif //XCB_USE_DRI2
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h
new file mode 100644
index 0000000000..6b5f81047d
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbconnection.h
@@ -0,0 +1,331 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBCONNECTION_H
+#define QXCBCONNECTION_H
+
+#include <xcb/xcb.h>
+
+#include <QList>
+#include <QObject>
+#include <QVector>
+
+#define Q_XCB_DEBUG
+
+class QXcbScreen;
+
+namespace QXcbAtom {
+ enum Atom {
+ // window-manager <-> client protocols
+ WM_PROTOCOLS,
+ WM_DELETE_WINDOW,
+ WM_TAKE_FOCUS,
+ _NET_WM_PING,
+ _NET_WM_CONTEXT_HELP,
+ _NET_WM_SYNC_REQUEST,
+ _NET_WM_SYNC_REQUEST_COUNTER,
+
+ // ICCCM window state
+ WM_STATE,
+ WM_CHANGE_STATE,
+
+ // Session management
+ WM_CLIENT_LEADER,
+ WM_WINDOW_ROLE,
+ SM_CLIENT_ID,
+
+ // Clipboard
+ CLIPBOARD,
+ INCR,
+ TARGETS,
+ MULTIPLE,
+ TIMESTAMP,
+ SAVE_TARGETS,
+ CLIP_TEMPORARY,
+ _QT_SELECTION,
+ _QT_CLIPBOARD_SENTINEL,
+ _QT_SELECTION_SENTINEL,
+ CLIPBOARD_MANAGER,
+
+ RESOURCE_MANAGER,
+
+ _XSETROOT_ID,
+
+ _QT_SCROLL_DONE,
+ _QT_INPUT_ENCODING,
+
+ _MOTIF_WM_HINTS,
+
+ DTWM_IS_RUNNING,
+ ENLIGHTENMENT_DESKTOP,
+ _DT_SAVE_MODE,
+ _SGI_DESKS_MANAGER,
+
+ // EWMH (aka NETWM)
+ _NET_SUPPORTED,
+ _NET_VIRTUAL_ROOTS,
+ _NET_WORKAREA,
+
+ _NET_MOVERESIZE_WINDOW,
+ _NET_WM_MOVERESIZE,
+
+ _NET_WM_NAME,
+ _NET_WM_ICON_NAME,
+ _NET_WM_ICON,
+
+ _NET_WM_PID,
+
+ _NET_WM_WINDOW_OPACITY,
+
+ _NET_WM_STATE,
+ _NET_WM_STATE_ABOVE,
+ _NET_WM_STATE_BELOW,
+ _NET_WM_STATE_FULLSCREEN,
+ _NET_WM_STATE_MAXIMIZED_HORZ,
+ _NET_WM_STATE_MAXIMIZED_VERT,
+ _NET_WM_STATE_MODAL,
+ _NET_WM_STATE_STAYS_ON_TOP,
+ _NET_WM_STATE_DEMANDS_ATTENTION,
+
+ _NET_WM_USER_TIME,
+ _NET_WM_USER_TIME_WINDOW,
+ _NET_WM_FULL_PLACEMENT,
+
+ _NET_WM_WINDOW_TYPE,
+ _NET_WM_WINDOW_TYPE_DESKTOP,
+ _NET_WM_WINDOW_TYPE_DOCK,
+ _NET_WM_WINDOW_TYPE_TOOLBAR,
+ _NET_WM_WINDOW_TYPE_MENU,
+ _NET_WM_WINDOW_TYPE_UTILITY,
+ _NET_WM_WINDOW_TYPE_SPLASH,
+ _NET_WM_WINDOW_TYPE_DIALOG,
+ _NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
+ _NET_WM_WINDOW_TYPE_POPUP_MENU,
+ _NET_WM_WINDOW_TYPE_TOOLTIP,
+ _NET_WM_WINDOW_TYPE_NOTIFICATION,
+ _NET_WM_WINDOW_TYPE_COMBO,
+ _NET_WM_WINDOW_TYPE_DND,
+ _NET_WM_WINDOW_TYPE_NORMAL,
+ _KDE_NET_WM_WINDOW_TYPE_OVERRIDE,
+
+ _KDE_NET_WM_FRAME_STRUT,
+
+ _NET_STARTUP_INFO,
+ _NET_STARTUP_INFO_BEGIN,
+
+ _NET_SUPPORTING_WM_CHECK,
+
+ _NET_WM_CM_S0,
+
+ _NET_SYSTEM_TRAY_VISUAL,
+
+ _NET_ACTIVE_WINDOW,
+
+ // Property formats
+ COMPOUND_TEXT,
+ TEXT,
+ UTF8_STRING,
+
+ // Xdnd
+ XdndEnter,
+ XdndPosition,
+ XdndStatus,
+ XdndLeave,
+ XdndDrop,
+ XdndFinished,
+ XdndTypelist,
+ XdndActionList,
+
+ XdndSelection,
+
+ XdndAware,
+ XdndProxy,
+
+ XdndActionCopy,
+ XdndActionLink,
+ XdndActionMove,
+ XdndActionPrivate,
+
+ // Motif DND
+ _MOTIF_DRAG_AND_DROP_MESSAGE,
+ _MOTIF_DRAG_INITIATOR_INFO,
+ _MOTIF_DRAG_RECEIVER_INFO,
+ _MOTIF_DRAG_WINDOW,
+ _MOTIF_DRAG_TARGETS,
+
+ XmTRANSFER_SUCCESS,
+ XmTRANSFER_FAILURE,
+
+ // Xkb
+ _XKB_RULES_NAMES,
+
+ // XEMBED
+ _XEMBED,
+ _XEMBED_INFO,
+
+ XWacomStylus,
+ XWacomCursor,
+ XWacomEraser,
+
+ XTabletStylus,
+ XTabletEraser,
+
+ NPredefinedAtoms,
+
+ _QT_SETTINGS_TIMESTAMP = NPredefinedAtoms,
+ NAtoms
+ };
+}
+
+class QXcbKeyboard;
+
+class QXcbConnection : public QObject
+{
+ Q_OBJECT
+public:
+ QXcbConnection(const char *displayName = 0);
+ ~QXcbConnection();
+
+ QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); }
+
+ QList<QXcbScreen *> screens() const { return m_screens; }
+ int primaryScreen() const { return m_primaryScreen; }
+
+ xcb_atom_t atom(QXcbAtom::Atom atom);
+
+ const char *displayName() const { return m_displayName.constData(); }
+
+ xcb_connection_t *xcb_connection() const { return m_connection; }
+
+ QXcbKeyboard *keyboard() const { return m_keyboard; }
+
+#ifdef XCB_USE_XLIB
+ void *xlib_display() const { return m_xlib_display; }
+#endif
+
+#ifdef XCB_USE_DRI2
+ bool hasSupportForDri2() const;
+ QByteArray dri2DeviceName() const { return m_dri2_device_name; }
+#endif
+#ifdef XCB_USE_EGL
+ bool hasEgl() const;
+#endif
+#if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
+ void *egl_display() const { return m_egl_display; }
+#endif
+
+ void sync();
+ void handleXcbError(xcb_generic_error_t *error);
+
+private slots:
+ void processXcbEvents();
+
+private:
+ void initializeAllAtoms();
+ void sendConnectionEvent(QXcbAtom::Atom atom, uint id = 0);
+#ifdef XCB_USE_DRI2
+ void initializeDri2();
+#endif
+
+ xcb_connection_t *m_connection;
+ const xcb_setup_t *m_setup;
+
+ QList<QXcbScreen *> m_screens;
+ int m_primaryScreen;
+
+ xcb_atom_t m_allAtoms[QXcbAtom::NAtoms];
+
+ QByteArray m_displayName;
+
+ QXcbKeyboard *m_keyboard;
+
+#if defined(XCB_USE_XLIB)
+ void *m_xlib_display;
+#endif
+
+#ifdef XCB_USE_DRI2
+ uint32_t m_dri2_major;
+ uint32_t m_dri2_minor;
+ bool m_dri2_support_probed;
+ bool m_has_support_for_dri2;
+ QByteArray m_dri2_device_name;
+#endif
+#if defined(XCB_USE_EGL) || defined(XCB_USE_DRI2)
+ void *m_egl_display;
+ bool m_has_egl;
+#endif
+#ifdef Q_XCB_DEBUG
+ struct CallInfo {
+ int sequence;
+ QByteArray file;
+ int line;
+ };
+ QVector<CallInfo> m_callLog;
+ void log(const char *file, int line, int sequence);
+ template <typename cookie_t>
+ friend cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line);
+#endif
+};
+
+#define DISPLAY_FROM_XCB(object) ((Display *)(object->connection()->xlib_display()))
+
+#ifdef Q_XCB_DEBUG
+template <typename cookie_t>
+cookie_t q_xcb_call_template(const cookie_t &cookie, QXcbConnection *connection, const char *file, int line)
+{
+ connection->log(file, line, cookie.sequence);
+ return cookie;
+}
+#define Q_XCB_CALL(x) q_xcb_call_template(x, connection(), __FILE__, __LINE__)
+#define Q_XCB_CALL2(x, connection) q_xcb_call_template(x, connection, __FILE__, __LINE__)
+#define Q_XCB_NOOP(c) q_xcb_call_template(xcb_no_operation(c->xcb_connection()), c, __FILE__, __LINE__);
+#else
+#define Q_XCB_CALL(x) x
+#define Q_XCB_CALL2(x, connection) x
+#define Q_XCB_NOOP(c)
+#endif
+
+
+#if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL)
+#define EGL_DISPLAY_FROM_XCB(object) ((EGLDisplay)(object->connection()->egl_display()))
+#endif //endifXCB_USE_DRI2
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp
new file mode 100644
index 0000000000..9df5f14114
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbintegration.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qxcbintegration.h"
+#include "qxcbconnection.h"
+#include "qxcbscreen.h"
+#include "qxcbwindow.h"
+#include "qxcbwindowsurface.h"
+#include "qxcbnativeinterface.h"
+
+#include <xcb/xcb.h>
+
+#include <private/qpixmap_raster_p.h>
+
+#include "qgenericunixfontdatabase.h"
+
+#include <stdio.h>
+
+#ifdef XCB_USE_EGL
+#include <EGL/egl.h>
+#endif
+
+QXcbIntegration::QXcbIntegration()
+ : m_connection(new QXcbConnection)
+{
+ foreach (QXcbScreen *screen, m_connection->screens())
+ m_screens << screen;
+
+ m_fontDatabase = new QGenericUnixFontDatabase();
+ m_nativeInterface = new QXcbNativeInterface;
+}
+
+QXcbIntegration::~QXcbIntegration()
+{
+ delete m_connection;
+}
+
+bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
+{
+ switch (cap) {
+ case ThreadedPixmaps: return true;
+ case OpenGL: return hasOpenGL();
+ default: return QPlatformIntegration::hasCapability(cap);
+ }
+}
+
+QPixmapData *QXcbIntegration::createPixmapData(QPixmapData::PixelType type) const
+{
+ return new QRasterPixmapData(type);
+}
+
+QPlatformWindow *QXcbIntegration::createPlatformWindow(QWidget *widget, WId winId) const
+{
+ Q_UNUSED(winId);
+ return new QXcbWindow(widget);
+}
+
+QWindowSurface *QXcbIntegration::createWindowSurface(QWidget *widget, WId winId) const
+{
+ Q_UNUSED(winId);
+ return new QXcbWindowSurface(widget);
+}
+
+QList<QPlatformScreen *> QXcbIntegration::screens() const
+{
+ return m_screens;
+}
+
+void QXcbIntegration::moveToScreen(QWidget *window, int screen)
+{
+ Q_UNUSED(window);
+ Q_UNUSED(screen);
+}
+
+bool QXcbIntegration::isVirtualDesktop()
+{
+ return false;
+}
+
+QPlatformFontDatabase *QXcbIntegration::fontDatabase() const
+{
+ return m_fontDatabase;
+}
+
+QPixmap QXcbIntegration::grabWindow(WId window, int x, int y, int width, int height) const
+{
+ Q_UNUSED(window);
+ Q_UNUSED(x);
+ Q_UNUSED(y);
+ Q_UNUSED(width);
+ Q_UNUSED(height);
+ return QPixmap();
+}
+
+
+bool QXcbIntegration::hasOpenGL() const
+{
+#if defined(XCB_USE_GLX)
+ return true;
+#elif defined(XCB_USE_EGL)
+ return m_connection->hasEgl();
+#elif defined(XCB_USE_DRI2)
+ if (m_connection->hasSupportForDri2()) {
+ return true;
+ }
+#endif
+ return false;
+}
+
+QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
+{
+ return m_nativeInterface;
+}
diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h
new file mode 100644
index 0000000000..d27fd716ab
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbintegration.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBINTEGRATION_H
+#define QXCBINTEGRATION_H
+
+#include <QtGui/QPlatformIntegration>
+#include <QtGui/QPlatformScreen>
+
+QT_BEGIN_NAMESPACE
+
+class QXcbConnection;
+
+class QXcbIntegration : public QPlatformIntegration
+{
+public:
+ QXcbIntegration();
+ ~QXcbIntegration();
+
+ bool hasCapability(Capability cap) const;
+ QPixmapData *createPixmapData(QPixmapData::PixelType type) const;
+ QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const;
+ QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const;
+
+ QList<QPlatformScreen *> screens() const;
+ void moveToScreen(QWidget *window, int screen);
+ bool isVirtualDesktop();
+ QPixmap grabWindow(WId window, int x, int y, int width, int height) const;
+
+ QPlatformFontDatabase *fontDatabase() const;
+
+ QPlatformNativeInterface *nativeInterface()const;
+
+private:
+ bool hasOpenGL() const;
+ QList<QPlatformScreen *> m_screens;
+ QXcbConnection *m_connection;
+
+ QPlatformFontDatabase *m_fontDatabase;
+ QPlatformNativeInterface *m_nativeInterface;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp
new file mode 100644
index 0000000000..f501c00e94
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp
@@ -0,0 +1,973 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qxcbkeyboard.h"
+
+#include <xcb/xcb_keysyms.h>
+
+#include <X11/keysym.h>
+
+#include <QtGui/QWindowSystemInterface>
+#include <QtCore/QTextCodec>
+
+#include <stdio.h>
+
+#ifndef XK_ISO_Left_Tab
+#define XK_ISO_Left_Tab 0xFE20
+#endif
+
+#ifndef XK_dead_hook
+#define XK_dead_hook 0xFE61
+#endif
+
+#ifndef XK_dead_horn
+#define XK_dead_horn 0xFE62
+#endif
+
+#ifndef XK_Codeinput
+#define XK_Codeinput 0xFF37
+#endif
+
+#ifndef XK_Kanji_Bangou
+#define XK_Kanji_Bangou 0xFF37 /* same as codeinput */
+#endif
+
+// Fix old X libraries
+#ifndef XK_KP_Home
+#define XK_KP_Home 0xFF95
+#endif
+#ifndef XK_KP_Left
+#define XK_KP_Left 0xFF96
+#endif
+#ifndef XK_KP_Up
+#define XK_KP_Up 0xFF97
+#endif
+#ifndef XK_KP_Right
+#define XK_KP_Right 0xFF98
+#endif
+#ifndef XK_KP_Down
+#define XK_KP_Down 0xFF99
+#endif
+#ifndef XK_KP_Prior
+#define XK_KP_Prior 0xFF9A
+#endif
+#ifndef XK_KP_Next
+#define XK_KP_Next 0xFF9B
+#endif
+#ifndef XK_KP_End
+#define XK_KP_End 0xFF9C
+#endif
+#ifndef XK_KP_Insert
+#define XK_KP_Insert 0xFF9E
+#endif
+#ifndef XK_KP_Delete
+#define XK_KP_Delete 0xFF9F
+#endif
+
+// the next lines are taken on 10/2009 from X.org (X11/XF86keysym.h), defining some special
+// multimedia keys. They are included here as not every system has them.
+#define XF86XK_MonBrightnessUp 0x1008FF02
+#define XF86XK_MonBrightnessDown 0x1008FF03
+#define XF86XK_KbdLightOnOff 0x1008FF04
+#define XF86XK_KbdBrightnessUp 0x1008FF05
+#define XF86XK_KbdBrightnessDown 0x1008FF06
+#define XF86XK_Standby 0x1008FF10
+#define XF86XK_AudioLowerVolume 0x1008FF11
+#define XF86XK_AudioMute 0x1008FF12
+#define XF86XK_AudioRaiseVolume 0x1008FF13
+#define XF86XK_AudioPlay 0x1008FF14
+#define XF86XK_AudioStop 0x1008FF15
+#define XF86XK_AudioPrev 0x1008FF16
+#define XF86XK_AudioNext 0x1008FF17
+#define XF86XK_HomePage 0x1008FF18
+#define XF86XK_Mail 0x1008FF19
+#define XF86XK_Start 0x1008FF1A
+#define XF86XK_Search 0x1008FF1B
+#define XF86XK_AudioRecord 0x1008FF1C
+#define XF86XK_Calculator 0x1008FF1D
+#define XF86XK_Memo 0x1008FF1E
+#define XF86XK_ToDoList 0x1008FF1F
+#define XF86XK_Calendar 0x1008FF20
+#define XF86XK_PowerDown 0x1008FF21
+#define XF86XK_ContrastAdjust 0x1008FF22
+#define XF86XK_Back 0x1008FF26
+#define XF86XK_Forward 0x1008FF27
+#define XF86XK_Stop 0x1008FF28
+#define XF86XK_Refresh 0x1008FF29
+#define XF86XK_PowerOff 0x1008FF2A
+#define XF86XK_WakeUp 0x1008FF2B
+#define XF86XK_Eject 0x1008FF2C
+#define XF86XK_ScreenSaver 0x1008FF2D
+#define XF86XK_WWW 0x1008FF2E
+#define XF86XK_Sleep 0x1008FF2F
+#define XF86XK_Favorites 0x1008FF30
+#define XF86XK_AudioPause 0x1008FF31
+#define XF86XK_AudioMedia 0x1008FF32
+#define XF86XK_MyComputer 0x1008FF33
+#define XF86XK_LightBulb 0x1008FF35
+#define XF86XK_Shop 0x1008FF36
+#define XF86XK_History 0x1008FF37
+#define XF86XK_OpenURL 0x1008FF38
+#define XF86XK_AddFavorite 0x1008FF39
+#define XF86XK_HotLinks 0x1008FF3A
+#define XF86XK_BrightnessAdjust 0x1008FF3B
+#define XF86XK_Finance 0x1008FF3C
+#define XF86XK_Community 0x1008FF3D
+#define XF86XK_AudioRewind 0x1008FF3E
+#define XF86XK_BackForward 0x1008FF3F
+#define XF86XK_Launch0 0x1008FF40
+#define XF86XK_Launch1 0x1008FF41
+#define XF86XK_Launch2 0x1008FF42
+#define XF86XK_Launch3 0x1008FF43
+#define XF86XK_Launch4 0x1008FF44
+#define XF86XK_Launch5 0x1008FF45
+#define XF86XK_Launch6 0x1008FF46
+#define XF86XK_Launch7 0x1008FF47
+#define XF86XK_Launch8 0x1008FF48
+#define XF86XK_Launch9 0x1008FF49
+#define XF86XK_LaunchA 0x1008FF4A
+#define XF86XK_LaunchB 0x1008FF4B
+#define XF86XK_LaunchC 0x1008FF4C
+#define XF86XK_LaunchD 0x1008FF4D
+#define XF86XK_LaunchE 0x1008FF4E
+#define XF86XK_LaunchF 0x1008FF4F
+#define XF86XK_ApplicationLeft 0x1008FF50
+#define XF86XK_ApplicationRight 0x1008FF51
+#define XF86XK_Book 0x1008FF52
+#define XF86XK_CD 0x1008FF53
+#define XF86XK_Calculater 0x1008FF54
+#define XF86XK_Clear 0x1008FF55
+#define XF86XK_ClearGrab 0x1008FE21
+#define XF86XK_Close 0x1008FF56
+#define XF86XK_Copy 0x1008FF57
+#define XF86XK_Cut 0x1008FF58
+#define XF86XK_Display 0x1008FF59
+#define XF86XK_DOS 0x1008FF5A
+#define XF86XK_Documents 0x1008FF5B
+#define XF86XK_Excel 0x1008FF5C
+#define XF86XK_Explorer 0x1008FF5D
+#define XF86XK_Game 0x1008FF5E
+#define XF86XK_Go 0x1008FF5F
+#define XF86XK_iTouch 0x1008FF60
+#define XF86XK_LogOff 0x1008FF61
+#define XF86XK_Market 0x1008FF62
+#define XF86XK_Meeting 0x1008FF63
+#define XF86XK_MenuKB 0x1008FF65
+#define XF86XK_MenuPB 0x1008FF66
+#define XF86XK_MySites 0x1008FF67
+#define XF86XK_News 0x1008FF69
+#define XF86XK_OfficeHome 0x1008FF6A
+#define XF86XK_Option 0x1008FF6C
+#define XF86XK_Paste 0x1008FF6D
+#define XF86XK_Phone 0x1008FF6E
+#define XF86XK_Reply 0x1008FF72
+#define XF86XK_Reload 0x1008FF73
+#define XF86XK_RotateWindows 0x1008FF74
+#define XF86XK_RotationPB 0x1008FF75
+#define XF86XK_RotationKB 0x1008FF76
+#define XF86XK_Save 0x1008FF77
+#define XF86XK_Send 0x1008FF7B
+#define XF86XK_Spell 0x1008FF7C
+#define XF86XK_SplitScreen 0x1008FF7D
+#define XF86XK_Support 0x1008FF7E
+#define XF86XK_TaskPane 0x1008FF7F
+#define XF86XK_Terminal 0x1008FF80
+#define XF86XK_Tools 0x1008FF81
+#define XF86XK_Travel 0x1008FF82
+#define XF86XK_Video 0x1008FF87
+#define XF86XK_Word 0x1008FF89
+#define XF86XK_Xfer 0x1008FF8A
+#define XF86XK_ZoomIn 0x1008FF8B
+#define XF86XK_ZoomOut 0x1008FF8C
+#define XF86XK_Away 0x1008FF8D
+#define XF86XK_Messenger 0x1008FF8E
+#define XF86XK_WebCam 0x1008FF8F
+#define XF86XK_MailForward 0x1008FF90
+#define XF86XK_Pictures 0x1008FF91
+#define XF86XK_Music 0x1008FF92
+#define XF86XK_Battery 0x1008FF93
+#define XF86XK_Bluetooth 0x1008FF94
+#define XF86XK_WLAN 0x1008FF95
+#define XF86XK_UWB 0x1008FF96
+#define XF86XK_AudioForward 0x1008FF97
+#define XF86XK_AudioRepeat 0x1008FF98
+#define XF86XK_AudioRandomPlay 0x1008FF99
+#define XF86XK_Subtitle 0x1008FF9A
+#define XF86XK_AudioCycleTrack 0x1008FF9B
+#define XF86XK_Time 0x1008FF9F
+#define XF86XK_Select 0x1008FFA0
+#define XF86XK_View 0x1008FFA1
+#define XF86XK_TopMenu 0x1008FFA2
+#define XF86XK_Suspend 0x1008FFA7
+#define XF86XK_Hibernate 0x1008FFA8
+
+
+// end of XF86keysyms.h
+
+// Special keys used by Qtopia, mapped into the X11 private keypad range.
+#define QTOPIAXK_Select 0x11000601
+#define QTOPIAXK_Yes 0x11000602
+#define QTOPIAXK_No 0x11000603
+#define QTOPIAXK_Cancel 0x11000604
+#define QTOPIAXK_Printer 0x11000605
+#define QTOPIAXK_Execute 0x11000606
+#define QTOPIAXK_Sleep 0x11000607
+#define QTOPIAXK_Play 0x11000608
+#define QTOPIAXK_Zoom 0x11000609
+#define QTOPIAXK_Context1 0x1100060A
+#define QTOPIAXK_Context2 0x1100060B
+#define QTOPIAXK_Context3 0x1100060C
+#define QTOPIAXK_Context4 0x1100060D
+#define QTOPIAXK_Call 0x1100060E
+#define QTOPIAXK_Hangup 0x1100060F
+#define QTOPIAXK_Flip 0x11000610
+
+// 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,
+
+ // Special keys from X.org - This include multimedia keys,
+ // wireless/bluetooth/uwb keys, special launcher keys, etc.
+ 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,
+ 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,
+ XF86XK_Mail, Qt::Key_LaunchMail,
+ XF86XK_MyComputer, Qt::Key_Launch0, // ### Qt 5: remap properly
+ XF86XK_Calculator, Qt::Key_Launch1,
+ XF86XK_Memo, Qt::Key_Memo,
+ XF86XK_ToDoList, Qt::Key_ToDoList,
+ XF86XK_Calendar, Qt::Key_Calendar,
+ XF86XK_PowerDown, Qt::Key_PowerDown,
+ XF86XK_ContrastAdjust, Qt::Key_ContrastAdjust,
+ XF86XK_Standby, Qt::Key_Standby,
+ XF86XK_MonBrightnessUp, Qt::Key_MonBrightnessUp,
+ XF86XK_MonBrightnessDown, Qt::Key_MonBrightnessDown,
+ XF86XK_KbdLightOnOff, Qt::Key_KeyboardLightOnOff,
+ XF86XK_KbdBrightnessUp, Qt::Key_KeyboardBrightnessUp,
+ XF86XK_KbdBrightnessDown, Qt::Key_KeyboardBrightnessDown,
+ XF86XK_PowerOff, Qt::Key_PowerOff,
+ XF86XK_WakeUp, Qt::Key_WakeUp,
+ XF86XK_Eject, Qt::Key_Eject,
+ XF86XK_ScreenSaver, Qt::Key_ScreenSaver,
+ XF86XK_WWW, Qt::Key_WWW,
+ XF86XK_Sleep, Qt::Key_Sleep,
+ XF86XK_LightBulb, Qt::Key_LightBulb,
+ XF86XK_Shop, Qt::Key_Shop,
+ XF86XK_History, Qt::Key_History,
+ XF86XK_AddFavorite, Qt::Key_AddFavorite,
+ XF86XK_HotLinks, Qt::Key_HotLinks,
+ XF86XK_BrightnessAdjust, Qt::Key_BrightnessAdjust,
+ XF86XK_Finance, Qt::Key_Finance,
+ XF86XK_Community, Qt::Key_Community,
+ XF86XK_AudioRewind, Qt::Key_AudioRewind,
+ XF86XK_BackForward, Qt::Key_BackForward,
+ XF86XK_ApplicationLeft, Qt::Key_ApplicationLeft,
+ XF86XK_ApplicationRight, Qt::Key_ApplicationRight,
+ XF86XK_Book, Qt::Key_Book,
+ XF86XK_CD, Qt::Key_CD,
+ XF86XK_Calculater, Qt::Key_Calculator,
+ XF86XK_Clear, Qt::Key_Clear,
+ XF86XK_ClearGrab, Qt::Key_ClearGrab,
+ XF86XK_Close, Qt::Key_Close,
+ XF86XK_Copy, Qt::Key_Copy,
+ XF86XK_Cut, Qt::Key_Cut,
+ XF86XK_Display, Qt::Key_Display,
+ XF86XK_DOS, Qt::Key_DOS,
+ XF86XK_Documents, Qt::Key_Documents,
+ XF86XK_Excel, Qt::Key_Excel,
+ XF86XK_Explorer, Qt::Key_Explorer,
+ XF86XK_Game, Qt::Key_Game,
+ XF86XK_Go, Qt::Key_Go,
+ XF86XK_iTouch, Qt::Key_iTouch,
+ XF86XK_LogOff, Qt::Key_LogOff,
+ XF86XK_Market, Qt::Key_Market,
+ XF86XK_Meeting, Qt::Key_Meeting,
+ XF86XK_MenuKB, Qt::Key_MenuKB,
+ XF86XK_MenuPB, Qt::Key_MenuPB,
+ XF86XK_MySites, Qt::Key_MySites,
+ XF86XK_News, Qt::Key_News,
+ XF86XK_OfficeHome, Qt::Key_OfficeHome,
+ XF86XK_Option, Qt::Key_Option,
+ XF86XK_Paste, Qt::Key_Paste,
+ XF86XK_Phone, Qt::Key_Phone,
+ XF86XK_Reply, Qt::Key_Reply,
+ XF86XK_Reload, Qt::Key_Reload,
+ XF86XK_RotateWindows, Qt::Key_RotateWindows,
+ XF86XK_RotationPB, Qt::Key_RotationPB,
+ XF86XK_RotationKB, Qt::Key_RotationKB,
+ XF86XK_Save, Qt::Key_Save,
+ XF86XK_Send, Qt::Key_Send,
+ XF86XK_Spell, Qt::Key_Spell,
+ XF86XK_SplitScreen, Qt::Key_SplitScreen,
+ XF86XK_Support, Qt::Key_Support,
+ XF86XK_TaskPane, Qt::Key_TaskPane,
+ XF86XK_Terminal, Qt::Key_Terminal,
+ XF86XK_Tools, Qt::Key_Tools,
+ XF86XK_Travel, Qt::Key_Travel,
+ XF86XK_Video, Qt::Key_Video,
+ XF86XK_Word, Qt::Key_Word,
+ XF86XK_Xfer, Qt::Key_Xfer,
+ XF86XK_ZoomIn, Qt::Key_ZoomIn,
+ XF86XK_ZoomOut, Qt::Key_ZoomOut,
+ XF86XK_Away, Qt::Key_Away,
+ XF86XK_Messenger, Qt::Key_Messenger,
+ XF86XK_WebCam, Qt::Key_WebCam,
+ XF86XK_MailForward, Qt::Key_MailForward,
+ XF86XK_Pictures, Qt::Key_Pictures,
+ XF86XK_Music, Qt::Key_Music,
+ XF86XK_Battery, Qt::Key_Battery,
+ XF86XK_Bluetooth, Qt::Key_Bluetooth,
+ XF86XK_WLAN, Qt::Key_WLAN,
+ XF86XK_UWB, Qt::Key_UWB,
+ XF86XK_AudioForward, Qt::Key_AudioForward,
+ XF86XK_AudioRepeat, Qt::Key_AudioRepeat,
+ XF86XK_AudioRandomPlay, Qt::Key_AudioRandomPlay,
+ XF86XK_Subtitle, Qt::Key_Subtitle,
+ XF86XK_AudioCycleTrack, Qt::Key_AudioCycleTrack,
+ XF86XK_Time, Qt::Key_Time,
+ XF86XK_Select, Qt::Key_Select,
+ XF86XK_View, Qt::Key_View,
+ XF86XK_TopMenu, Qt::Key_TopMenu,
+ XF86XK_Bluetooth, Qt::Key_Bluetooth,
+ XF86XK_Suspend, Qt::Key_Suspend,
+ XF86XK_Hibernate, Qt::Key_Hibernate,
+ XF86XK_Launch0, Qt::Key_Launch2, // ### Qt 5: remap properly
+ 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,
+ XF86XK_LaunchE, Qt::Key_LaunchG,
+ XF86XK_LaunchF, Qt::Key_LaunchH,
+
+ // 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,
+
+ 0, 0
+};
+
+static const unsigned short katakanaKeysymsToUnicode[] = {
+ 0x0000, 0x3002, 0x300C, 0x300D, 0x3001, 0x30FB, 0x30F2, 0x30A1,
+ 0x30A3, 0x30A5, 0x30A7, 0x30A9, 0x30E3, 0x30E5, 0x30E7, 0x30C3,
+ 0x30FC, 0x30A2, 0x30A4, 0x30A6, 0x30A8, 0x30AA, 0x30AB, 0x30AD,
+ 0x30AF, 0x30B1, 0x30B3, 0x30B5, 0x30B7, 0x30B9, 0x30BB, 0x30BD,
+ 0x30BF, 0x30C1, 0x30C4, 0x30C6, 0x30C8, 0x30CA, 0x30CB, 0x30CC,
+ 0x30CD, 0x30CE, 0x30CF, 0x30D2, 0x30D5, 0x30D8, 0x30DB, 0x30DE,
+ 0x30DF, 0x30E0, 0x30E1, 0x30E2, 0x30E4, 0x30E6, 0x30E8, 0x30E9,
+ 0x30EA, 0x30EB, 0x30EC, 0x30ED, 0x30EF, 0x30F3, 0x309B, 0x309C
+};
+
+static const unsigned short cyrillicKeysymsToUnicode[] = {
+ 0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457,
+ 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0000, 0x045e, 0x045f,
+ 0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407,
+ 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x0000, 0x040e, 0x040f,
+ 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433,
+ 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e,
+ 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432,
+ 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a,
+ 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
+ 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e,
+ 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
+ 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a
+};
+
+static const unsigned short greekKeysymsToUnicode[] = {
+ 0x0000, 0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c,
+ 0x038e, 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015,
+ 0x0000, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc,
+ 0x03cd, 0x03cb, 0x03b0, 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
+ 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f,
+ 0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
+ 0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
+ 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
+ 0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7,
+ 0x03c8, 0x03c9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
+};
+
+static const unsigned short technicalKeysymsToUnicode[] = {
+ 0x0000, 0x23B7, 0x250C, 0x2500, 0x2320, 0x2321, 0x2502, 0x23A1,
+ 0x23A3, 0x23A4, 0x23A6, 0x239B, 0x239D, 0x239E, 0x23A0, 0x23A8,
+ 0x23AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x2264, 0x2260, 0x2265, 0x222B,
+ 0x2234, 0x221D, 0x221E, 0x0000, 0x0000, 0x2207, 0x0000, 0x0000,
+ 0x223C, 0x2243, 0x0000, 0x0000, 0x0000, 0x21D4, 0x21D2, 0x2261,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x221A, 0x0000,
+ 0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222A, 0x2227, 0x2228,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x2190, 0x2191, 0x2192, 0x2193, 0x0000
+};
+
+static const unsigned short specialKeysymsToUnicode[] = {
+ 0x25C6, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x0000, 0x0000,
+ 0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0x23BA,
+ 0x23BB, 0x2500, 0x23BC, 0x23BD, 0x251C, 0x2524, 0x2534, 0x252C,
+ 0x2502, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
+};
+
+static const unsigned short publishingKeysymsToUnicode[] = {
+ 0x0000, 0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009,
+ 0x200a, 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025,
+ 0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a,
+ 0x2105, 0x0000, 0x0000, 0x2012, 0x2329, 0x0000, 0x232a, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000,
+ 0x0000, 0x2122, 0x2613, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25af,
+ 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x0000, 0x2032, 0x2033,
+ 0x0000, 0x271d, 0x0000, 0x25ac, 0x25c0, 0x25b6, 0x25cf, 0x25ae,
+ 0x25e6, 0x25ab, 0x25ad, 0x25b3, 0x25bd, 0x2606, 0x2022, 0x25aa,
+ 0x25b2, 0x25bc, 0x261c, 0x261e, 0x2663, 0x2666, 0x2665, 0x0000,
+ 0x2720, 0x2020, 0x2021, 0x2713, 0x2717, 0x266f, 0x266d, 0x2642,
+ 0x2640, 0x260e, 0x2315, 0x2117, 0x2038, 0x201a, 0x201e, 0x0000
+};
+
+static const unsigned short aplKeysymsToUnicode[] = {
+ 0x0000, 0x0000, 0x0000, 0x003c, 0x0000, 0x0000, 0x003e, 0x0000,
+ 0x2228, 0x2227, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x00af, 0x0000, 0x22a5, 0x2229, 0x230a, 0x0000, 0x005f, 0x0000,
+ 0x0000, 0x0000, 0x2218, 0x0000, 0x2395, 0x0000, 0x22a4, 0x25cb,
+ 0x0000, 0x0000, 0x0000, 0x2308, 0x0000, 0x0000, 0x222a, 0x0000,
+ 0x2283, 0x0000, 0x2282, 0x0000, 0x22a2, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x22a3, 0x0000, 0x0000, 0x0000
+};
+
+static const unsigned short koreanKeysymsToUnicode[] = {
+ 0x0000, 0x3131, 0x3132, 0x3133, 0x3134, 0x3135, 0x3136, 0x3137,
+ 0x3138, 0x3139, 0x313a, 0x313b, 0x313c, 0x313d, 0x313e, 0x313f,
+ 0x3140, 0x3141, 0x3142, 0x3143, 0x3144, 0x3145, 0x3146, 0x3147,
+ 0x3148, 0x3149, 0x314a, 0x314b, 0x314c, 0x314d, 0x314e, 0x314f,
+ 0x3150, 0x3151, 0x3152, 0x3153, 0x3154, 0x3155, 0x3156, 0x3157,
+ 0x3158, 0x3159, 0x315a, 0x315b, 0x315c, 0x315d, 0x315e, 0x315f,
+ 0x3160, 0x3161, 0x3162, 0x3163, 0x11a8, 0x11a9, 0x11aa, 0x11ab,
+ 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3,
+ 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb,
+ 0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x316d,
+ 0x3171, 0x3178, 0x317f, 0x3181, 0x3184, 0x3186, 0x318d, 0x318e,
+ 0x11eb, 0x11f0, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9
+};
+
+static QChar keysymToUnicode(unsigned char byte3, unsigned char byte4)
+{
+ switch (byte3) {
+ case 0x04:
+ // katakana
+ if (byte4 > 0xa0 && byte4 < 0xe0)
+ return QChar(katakanaKeysymsToUnicode[byte4 - 0xa0]);
+ else if (byte4 == 0x7e)
+ return QChar(0x203e); // Overline
+ break;
+ case 0x06:
+ // russian, use lookup table
+ if (byte4 > 0xa0)
+ return QChar(cyrillicKeysymsToUnicode[byte4 - 0xa0]);
+ break;
+ case 0x07:
+ // greek
+ if (byte4 > 0xa0)
+ return QChar(greekKeysymsToUnicode[byte4 - 0xa0]);
+ break;
+ case 0x08:
+ // technical
+ if (byte4 > 0xa0)
+ return QChar(technicalKeysymsToUnicode[byte4 - 0xa0]);
+ break;
+ case 0x09:
+ // special
+ if (byte4 >= 0xe0)
+ return QChar(specialKeysymsToUnicode[byte4 - 0xe0]);
+ break;
+ case 0x0a:
+ // publishing
+ if (byte4 > 0xa0)
+ return QChar(publishingKeysymsToUnicode[byte4 - 0xa0]);
+ break;
+ case 0x0b:
+ // APL
+ if (byte4 > 0xa0)
+ return QChar(aplKeysymsToUnicode[byte4 - 0xa0]);
+ break;
+ case 0x0e:
+ // Korean
+ if (byte4 > 0xa0)
+ return QChar(koreanKeysymsToUnicode[byte4 - 0xa0]);
+ break;
+ default:
+ break;
+ }
+ return QChar(0x0);
+}
+
+Qt::KeyboardModifiers QXcbKeyboard::translateModifiers(int s)
+{
+ Qt::KeyboardModifiers ret = 0;
+ if (s & XCB_MOD_MASK_SHIFT)
+ ret |= Qt::ShiftModifier;
+ if (s & XCB_MOD_MASK_CONTROL)
+ ret |= Qt::ControlModifier;
+ if (s & m_alt_mask)
+ ret |= Qt::AltModifier;
+ if (s & m_meta_mask)
+ ret |= Qt::MetaModifier;
+ return ret;
+}
+
+int QXcbKeyboard::translateKeySym(uint key) const
+{
+ int code = -1;
+ int i = 0; // any other keys
+ while (KeyTbl[i]) {
+ if (key == KeyTbl[i]) {
+ code = (int)KeyTbl[i+1];
+ break;
+ }
+ i += 2;
+ }
+ if (m_meta_mask) {
+ // translate Super/Hyper keys to Meta if we're using them as the MetaModifier
+ if (m_meta_mask == m_super_mask && (code == Qt::Key_Super_L || code == Qt::Key_Super_R)) {
+ code = Qt::Key_Meta;
+ } else if (m_meta_mask == m_hyper_mask && (code == Qt::Key_Hyper_L || code == Qt::Key_Hyper_R)) {
+ code = Qt::Key_Meta;
+ }
+ }
+ return code;
+}
+
+QString QXcbKeyboard::translateKeySym(xcb_keysym_t keysym, uint xmodifiers,
+ int &code, Qt::KeyboardModifiers &modifiers,
+ QByteArray &chars, int &count)
+{
+ // all keysyms smaller than 0xff00 are actally keys that can be mapped to unicode chars
+
+ QTextCodec *mapper = QTextCodec::codecForLocale();
+ QChar converted;
+
+ if (/*count == 0 &&*/ keysym < 0xff00) {
+ unsigned char byte3 = (unsigned char)(keysym >> 8);
+ int mib = -1;
+ switch(byte3) {
+ case 0: // Latin 1
+ case 1: // Latin 2
+ case 2: //latin 3
+ case 3: // latin4
+ mib = byte3 + 4; break;
+ case 5: // arabic
+ mib = 82; break;
+ case 12: // Hebrew
+ mib = 85; break;
+ case 13: // Thai
+ mib = 2259; break;
+ case 4: // kana
+ case 6: // cyrillic
+ case 7: // greek
+ case 8: // technical, no mapping here at the moment
+ case 9: // Special
+ case 10: // Publishing
+ case 11: // APL
+ case 14: // Korean, no mapping
+ mib = -1; // manual conversion
+ mapper= 0;
+#if !defined(QT_NO_XIM)
+ converted = keysymToUnicode(byte3, keysym & 0xff);
+#endif
+ case 0x20:
+ // currency symbols
+ if (keysym >= 0x20a0 && keysym <= 0x20ac) {
+ mib = -1; // manual conversion
+ mapper = 0;
+ converted = (uint)keysym;
+ }
+ break;
+ default:
+ break;
+ }
+ if (mib != -1) {
+ mapper = QTextCodec::codecForMib(mib);
+ if (chars.isEmpty())
+ chars.resize(1);
+ chars[0] = (unsigned char) (keysym & 0xff); // get only the fourth bit for conversion later
+ count = 1;
+ }
+ } else if (keysym >= 0x1000000 && keysym <= 0x100ffff) {
+ converted = (ushort) (keysym - 0x1000000);
+ mapper = 0;
+ }
+ if (count < (int)chars.size()-1)
+ chars[count] = '\0';
+
+ QString text;
+ if (!mapper && converted.unicode() != 0x0) {
+ text = converted;
+ } else if (!chars.isEmpty()) {
+ // convert chars (8bit) to text (unicode).
+ if (mapper)
+ text = mapper->toUnicode(chars.data(), count, 0);
+ if (text.isEmpty()) {
+ // no mapper, or codec couldn't convert to unicode (this
+ // can happen when running in the C locale or with no LANG
+ // set). try converting from latin-1
+ text = QString::fromLatin1(chars);
+ }
+ }
+
+ modifiers = translateModifiers(xmodifiers);
+
+ // Commentary in X11/keysymdef says that X codes match ASCII, so it
+ // is safe to use the locale functions to process X codes in ISO8859-1.
+ //
+ // This is mainly for compatibility - applications should not use the
+ // Qt keycodes between 128 and 255, but should rather use the
+ // QKeyEvent::text().
+ //
+ if (keysym < 128 || (keysym < 256 && (!mapper || mapper->mibEnum()==4))) {
+ // upper-case key, if known
+ code = isprint((int)keysym) ? toupper((int)keysym) : 0;
+ } else if (keysym >= XK_F1 && keysym <= XK_F35) {
+ // function keys
+ code = Qt::Key_F1 + ((int)keysym - XK_F1);
+ } else if (keysym >= XK_KP_Space && keysym <= XK_KP_9) {
+ if (keysym >= XK_KP_0) {
+ // numeric keypad keys
+ code = Qt::Key_0 + ((int)keysym - XK_KP_0);
+ } else {
+ code = translateKeySym(keysym);
+ }
+ modifiers |= Qt::KeypadModifier;
+ } else if (text.length() == 1 && text.unicode()->unicode() > 0x1f && text.unicode()->unicode() != 0x7f && !(keysym >= XK_dead_grave && keysym <= XK_dead_horn)) {
+ code = text.unicode()->toUpper().unicode();
+ } else {
+ // any other keys
+ code = translateKeySym(keysym);
+
+ if (code == Qt::Key_Tab && (modifiers & Qt::ShiftModifier)) {
+ // map shift+tab to shift+backtab, QShortcutMap knows about it
+ // and will handle it.
+ code = Qt::Key_Backtab;
+ text = QString();
+ }
+ }
+
+ return text;
+}
+
+QXcbKeyboard::QXcbKeyboard(QXcbConnection *connection)
+ : QXcbObject(connection)
+ , m_alt_mask(0)
+ , m_super_mask(0)
+ , m_hyper_mask(0)
+ , m_meta_mask(0)
+{
+ m_key_symbols = xcb_key_symbols_alloc(xcb_connection());
+}
+
+QXcbKeyboard::~QXcbKeyboard()
+{
+ xcb_key_symbols_free(m_key_symbols);
+}
+
+// #define XCB_KEYBOARD_DEBUG
+
+void QXcbKeyboard::handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keycode_t code, quint16 state, xcb_timestamp_t time)
+{
+ int col = state & XCB_MOD_MASK_SHIFT ? 1 : 0;
+
+ const int altGrOffset = 4;
+ if (state & 128)
+ col += altGrOffset;
+
+ Q_XCB_NOOP(connection());
+
+#ifdef XCB_KEYBOARD_DEBUG
+ printf("key code: %d, state: %d, syms: ", code, state);
+ for (int i = 0; i <= 5; ++i) {
+ printf("%d ", xcb_key_symbols_get_keysym(m_key_symbols, code, i));
+ }
+ printf("\n");
+#endif
+
+ Q_XCB_NOOP(connection());
+
+ xcb_keysym_t sym = xcb_key_symbols_get_keysym(m_key_symbols, code, col);
+ if (sym == XCB_NO_SYMBOL)
+ sym = xcb_key_symbols_get_keysym(m_key_symbols, code, col ^ 0x1);
+
+ if (state & XCB_MOD_MASK_LOCK && sym <= 0x7f && isprint(sym)) {
+ if (isupper(sym))
+ sym = tolower(sym);
+ else
+ sym = toupper(sym);
+ }
+
+ Q_XCB_NOOP(connection());
+
+ QByteArray chars;
+
+ Qt::KeyboardModifiers modifiers;
+ int qtcode = 0;
+ int count = 0;
+
+ QString string = translateKeySym(sym, state, qtcode, modifiers, chars, count);
+
+ QWindowSystemInterface::handleExtendedKeyEvent(widget, time, type, qtcode, modifiers, code, 0, state, string.left(count));
+}
+
+void QXcbKeyboard::handleKeyPressEvent(QWidget *widget, const xcb_key_press_event_t *event)
+{
+ handleKeyEvent(widget, QEvent::KeyPress, event->detail, event->state, event->time);
+}
+
+void QXcbKeyboard::handleKeyReleaseEvent(QWidget *widget, const xcb_key_release_event_t *event)
+{
+ handleKeyEvent(widget, QEvent::KeyRelease, event->detail, event->state, event->time);
+}
+
+void QXcbKeyboard::handleMappingNotifyEvent(const xcb_mapping_notify_event_t *event)
+{
+ xcb_refresh_keyboard_mapping(m_key_symbols, const_cast<xcb_mapping_notify_event_t *>(event));
+}
diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.h b/src/plugins/platforms/xcb/qxcbkeyboard.h
new file mode 100644
index 0000000000..ddade79d51
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbkeyboard.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBKEYBOARD_H
+#define QXCBKEYBOARD_H
+
+#include "qxcbobject.h"
+
+#include "xcb/xcb_keysyms.h"
+
+#include <QEvent>
+
+class QXcbKeyboard : public QXcbObject
+{
+public:
+ QXcbKeyboard(QXcbConnection *connection);
+ ~QXcbKeyboard();
+
+ void handleKeyPressEvent(QWidget *widget, const xcb_key_press_event_t *event);
+ void handleKeyReleaseEvent(QWidget *widget, const xcb_key_release_event_t *event);
+
+ void handleMappingNotifyEvent(const xcb_mapping_notify_event_t *event);
+
+ Qt::KeyboardModifiers translateModifiers(int s);
+
+private:
+ void handleKeyEvent(QWidget *widget, QEvent::Type type, xcb_keycode_t code, quint16 state, xcb_timestamp_t time);
+
+ int translateKeySym(uint key) const;
+ QString translateKeySym(xcb_keysym_t keysym, uint xmodifiers,
+ int &code, Qt::KeyboardModifiers &modifiers,
+ QByteArray &chars, int &count);
+
+ uint m_alt_mask;
+ uint m_super_mask;
+ uint m_hyper_mask;
+ uint m_meta_mask;
+ uint m_mode_switch_mask;
+ uint m_num_lock_mask;
+
+ xcb_key_symbols_t *m_key_symbols;
+};
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
new file mode 100644
index 0000000000..b2ca1beb6e
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
@@ -0,0 +1,185 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qxcbnativeinterface.h"
+
+#include "qxcbscreen.h"
+
+#include <QtGui/private/qapplication_p.h>
+#include <QtCore/QMap>
+
+#include <QtCore/QDebug>
+
+#if defined(XCB_USE_EGL)
+#include "../eglconvenience/qeglplatformcontext.h"
+#elif defined (XCB_USE_DRI2)
+#include "qdri2context.h"
+#endif
+
+class QXcbResourceMap : public QMap<QByteArray, QXcbNativeInterface::ResourceType>
+{
+public:
+ QXcbResourceMap()
+ :QMap<QByteArray, QXcbNativeInterface::ResourceType>()
+ {
+ insert("display",QXcbNativeInterface::Display);
+ insert("egldisplay",QXcbNativeInterface::EglDisplay);
+ insert("connection",QXcbNativeInterface::Connection);
+ insert("screen",QXcbNativeInterface::Screen);
+ insert("graphicsdevice",QXcbNativeInterface::GraphicsDevice);
+ insert("eglcontext",QXcbNativeInterface::EglContext);
+ }
+};
+
+Q_GLOBAL_STATIC(QXcbResourceMap, qXcbResourceMap)
+
+void *QXcbNativeInterface::nativeResourceForWidget(const QByteArray &resourceString, QWidget *widget)
+{
+ QByteArray lowerCaseResource = resourceString.toLower();
+ ResourceType resource = qXcbResourceMap()->value(lowerCaseResource);
+ void *result = 0;
+ switch(resource) {
+ case Display:
+ result = displayForWidget(widget);
+ break;
+ case EglDisplay:
+ result = eglDisplayForWidget(widget);
+ break;
+ case Connection:
+ result = connectionForWidget(widget);
+ break;
+ case Screen:
+ result = qPlatformScreenForWidget(widget);
+ break;
+ case GraphicsDevice:
+ result = graphicsDeviceForWidget(widget);
+ break;
+ case EglContext:
+ result = eglContextForWidget(widget);
+ break;
+ default:
+ result = 0;
+ }
+ return result;
+}
+
+QXcbScreen *QXcbNativeInterface::qPlatformScreenForWidget(QWidget *widget)
+{
+ QXcbScreen *screen;
+ if (widget) {
+ screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(widget));
+ }else {
+ screen = static_cast<QXcbScreen *>(QApplicationPrivate::platformIntegration()->screens()[0]);
+ }
+ return screen;
+}
+
+void *QXcbNativeInterface::displayForWidget(QWidget *widget)
+{
+#if defined(XCB_USE_XLIB)
+ QXcbScreen *screen = qPlatformScreenForWidget(widget);
+ return screen->connection()->xlib_display();
+#else
+ Q_UNUSED(widget);
+ return 0;
+#endif
+}
+
+void *QXcbNativeInterface::eglDisplayForWidget(QWidget *widget)
+{
+#if defined(XCB_USE_DRI2) || defined(XCB_USE_EGL)
+ QXcbScreen *screen = qPlatformScreenForWidget(widget);
+ return screen->connection()->egl_display();
+#else
+ Q_UNUSED(widget)
+ return 0;
+#endif
+}
+
+void *QXcbNativeInterface::connectionForWidget(QWidget *widget)
+{
+ QXcbScreen *screen = qPlatformScreenForWidget(widget);
+ return screen->xcb_connection();
+}
+
+void *QXcbNativeInterface::screenForWidget(QWidget *widget)
+{
+ QXcbScreen *screen = qPlatformScreenForWidget(widget);
+ return screen->screen();
+}
+
+void *QXcbNativeInterface::graphicsDeviceForWidget(QWidget *widget)
+{
+#if defined(XCB_USE_DRI2)
+ QXcbScreen *screen = qPlatformScreenForWidget(widget);
+ QByteArray deviceName = screen->connection()->dri2DeviceName();
+ return deviceName.data();
+#else
+ Q_UNUSED(widget);
+ return 0;
+#endif
+
+}
+
+void * QXcbNativeInterface::eglContextForWidget(QWidget *widget)
+{
+ Q_ASSERT(widget);
+ if (!widget->platformWindow()) {
+ qDebug() << "QPlatformWindow does not exist for widget" << widget
+ << "cannot return EGLContext";
+ return 0;
+ }
+ QPlatformGLContext *platformContext = widget->platformWindow()->glContext();
+ if (!platformContext) {
+ qDebug() << "QPlatformWindow" << widget->platformWindow() << "does not have a glContext"
+ << "cannot return EGLContext";
+ return 0;
+ }
+#if defined(XCB_USE_EGL)
+ QEGLPlatformContext *eglPlatformContext = static_cast<QEGLPlatformContext *>(platformContext);
+ return eglPlatformContext->eglContext();
+#elif defined (XCB_USE_DRI2)
+ QDri2Context *dri2Context = static_cast<QDri2Context *>(platformContext);
+ return dri2Context->eglContext();
+#else
+ return 0;
+#endif
+}
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h
new file mode 100644
index 0000000000..f60905cc3d
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBNATIVEINTERFACE_H
+#define QXCBNATIVEINTERFACE_H
+
+#include <QtGui/QPlatformNativeInterface>
+
+class QWidget;
+class QXcbScreen;
+
+class QXcbNativeInterface : public QPlatformNativeInterface
+{
+public:
+ enum ResourceType {
+ Display,
+ EglDisplay,
+ Connection,
+ Screen,
+ GraphicsDevice,
+ EglContext
+ };
+
+ void *nativeResourceForWidget(const QByteArray &resourceString, QWidget *widget);
+
+ void *displayForWidget(QWidget *widget);
+ void *eglDisplayForWidget(QWidget *widget);
+ void *connectionForWidget(QWidget *widget);
+ void *screenForWidget(QWidget *widget);
+ void *graphicsDeviceForWidget(QWidget *widget);
+ void *eglContextForWidget(QWidget *widget);
+
+private:
+ static QXcbScreen *qPlatformScreenForWidget(QWidget *widget);
+};
+
+#endif // QXCBNATIVEINTERFACE_H
diff --git a/src/plugins/platforms/xcb/qxcbobject.h b/src/plugins/platforms/xcb/qxcbobject.h
new file mode 100644
index 0000000000..69494b0349
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbobject.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBOBJECT_H
+#define QXCBOBJECT_H
+
+#include "qxcbconnection.h"
+
+class QXcbObject
+{
+public:
+ QXcbObject(QXcbConnection *connection = 0) : m_connection(connection) {}
+
+ void setConnection(QXcbConnection *connection) { m_connection = connection; }
+ QXcbConnection *connection() const { return m_connection; }
+
+ xcb_atom_t atom(QXcbAtom::Atom atom) const { return m_connection->atom(atom); }
+ xcb_connection_t *xcb_connection() const { return m_connection->xcb_connection(); }
+
+private:
+ QXcbConnection *m_connection;
+};
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp
new file mode 100644
index 0000000000..1c12ee3059
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbscreen.cpp
@@ -0,0 +1,134 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qxcbscreen.h"
+
+#include <stdio.h>
+
+QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int number)
+ : QXcbObject(connection)
+ , m_screen(screen)
+ , m_number(number)
+{
+ printf ("\n");
+ printf ("Information of screen %d:\n", screen->root);
+ printf (" width.........: %d\n", screen->width_in_pixels);
+ printf (" height........: %d\n", screen->height_in_pixels);
+ printf (" depth.........: %d\n", screen->root_depth);
+ printf (" white pixel...: %x\n", screen->white_pixel);
+ printf (" black pixel...: %x\n", screen->black_pixel);
+ printf ("\n");
+
+ const quint32 mask = XCB_CW_EVENT_MASK;
+ const quint32 values[] = {
+ // XCB_CW_EVENT_MASK
+ XCB_EVENT_MASK_ENTER_WINDOW
+ | XCB_EVENT_MASK_LEAVE_WINDOW
+ | XCB_EVENT_MASK_PROPERTY_CHANGE
+ };
+
+ xcb_change_window_attributes(xcb_connection(), screen->root, mask, values);
+
+ xcb_generic_error_t *error;
+
+ xcb_get_property_reply_t *reply =
+ xcb_get_property_reply(xcb_connection(),
+ xcb_get_property(xcb_connection(), false, screen->root,
+ atom(QXcbAtom::_NET_SUPPORTING_WM_CHECK),
+ XCB_ATOM_WINDOW, 0, 1024), &error);
+
+ if (reply && reply->format == 32 && reply->type == XCB_ATOM_WINDOW) {
+ xcb_window_t windowManager = *((xcb_window_t *)xcb_get_property_value(reply));
+
+ if (windowManager != XCB_WINDOW_NONE) {
+ xcb_get_property_reply_t *windowManagerReply =
+ xcb_get_property_reply(xcb_connection(),
+ xcb_get_property(xcb_connection(), false, windowManager,
+ atom(QXcbAtom::_NET_WM_NAME),
+ atom(QXcbAtom::UTF8_STRING), 0, 1024), &error);
+ if (windowManagerReply && windowManagerReply->format == 8 && windowManagerReply->type == atom(QXcbAtom::UTF8_STRING)) {
+ m_windowManagerName = QString::fromUtf8((const char *)xcb_get_property_value(windowManagerReply), xcb_get_property_value_length(windowManagerReply));
+ printf("Running window manager: %s\n", qPrintable(m_windowManagerName));
+ } else if (error) {
+ connection->handleXcbError(error);
+ free(error);
+ }
+
+ free(windowManagerReply);
+ }
+ } else if (error) {
+ connection->handleXcbError(error);
+ free(error);
+ }
+
+ free(reply);
+
+ m_syncRequestSupported = m_windowManagerName != QLatin1String("KWin");
+}
+
+QXcbScreen::~QXcbScreen()
+{
+}
+
+QRect QXcbScreen::geometry() const
+{
+ return QRect(0, 0, m_screen->width_in_pixels, m_screen->height_in_pixels);
+}
+
+int QXcbScreen::depth() const
+{
+ return m_screen->root_depth;
+}
+
+QImage::Format QXcbScreen::format() const
+{
+ return QImage::Format_RGB32;
+}
+
+QSize QXcbScreen::physicalSize() const
+{
+ return QSize(m_screen->width_in_millimeters, m_screen->height_in_millimeters);
+}
+
+int QXcbScreen::screenNumber() const
+{
+ return m_number;
+}
diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h
new file mode 100644
index 0000000000..9547d016b7
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbscreen.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBSCREEN_H
+#define QXCBSCREEN_H
+
+#include <QtGui/QPlatformScreen>
+#include <QtCore/QString>
+
+#include <xcb/xcb.h>
+
+#include "qxcbobject.h"
+
+class QXcbConnection;
+
+class QXcbScreen : public QXcbObject, public QPlatformScreen
+{
+public:
+ QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int number);
+ ~QXcbScreen();
+
+ QRect geometry() const;
+ int depth() const;
+ QImage::Format format() const;
+ QSize physicalSize() const;
+
+ int screenNumber() const;
+
+ xcb_screen_t *screen() const { return m_screen; }
+ xcb_window_t root() const { return m_screen->root; }
+
+ QString windowManagerName() const { return m_windowManagerName; }
+ bool syncRequestSupported() const { return m_syncRequestSupported; }
+
+private:
+ xcb_screen_t *m_screen;
+ int m_number;
+ QString m_windowManagerName;
+ bool m_syncRequestSupported;
+};
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
new file mode 100644
index 0000000000..0456638ab9
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -0,0 +1,683 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qxcbwindow.h"
+
+#include <QtDebug>
+
+#include "qxcbconnection.h"
+#include "qxcbscreen.h"
+#ifdef XCB_USE_DRI2
+#include "qdri2context.h"
+#endif
+
+#include <xcb/xcb_icccm.h>
+
+#include <private/qapplication_p.h>
+#include <private/qwindowsurface_p.h>
+
+#include <QtGui/QWindowSystemInterface>
+
+#include <stdio.h>
+
+#ifdef XCB_USE_XLIB
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#endif
+
+#if defined(XCB_USE_GLX)
+#include "qglxintegration.h"
+#include "qglxconvenience.h"
+#elif defined(XCB_USE_EGL)
+#include "../eglconvenience/qeglplatformcontext.h"
+#include "../eglconvenience/qeglconvenience.h"
+#include "../eglconvenience/qxlibeglintegration.h"
+#endif
+
+// 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));
+}
+
+QXcbWindow::QXcbWindow(QWidget *tlw)
+ : QPlatformWindow(tlw)
+ , m_context(0)
+{
+ m_screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(tlw));
+
+ setConnection(m_screen->connection());
+
+ const quint32 mask = XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK;
+ const quint32 values[] = {
+ // XCB_CW_BACK_PIXMAP
+ XCB_NONE,
+ // XCB_CW_EVENT_MASK
+ XCB_EVENT_MASK_EXPOSURE
+ | XCB_EVENT_MASK_STRUCTURE_NOTIFY
+ | XCB_EVENT_MASK_KEY_PRESS
+ | XCB_EVENT_MASK_KEY_RELEASE
+ | XCB_EVENT_MASK_BUTTON_PRESS
+ | XCB_EVENT_MASK_BUTTON_RELEASE
+ | XCB_EVENT_MASK_BUTTON_MOTION
+ | XCB_EVENT_MASK_ENTER_WINDOW
+ | XCB_EVENT_MASK_LEAVE_WINDOW
+ | XCB_EVENT_MASK_PROPERTY_CHANGE
+ | XCB_EVENT_MASK_FOCUS_CHANGE
+ };
+
+#if defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
+ if (tlw->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL
+ && QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL))
+ {
+#if defined(XCB_USE_GLX)
+ XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), tlw->platformWindowFormat());
+#elif defined(XCB_USE_EGL)
+ EGLDisplay eglDisplay = connection()->egl_display();
+ EGLConfig eglConfig = q_configFromQPlatformWindowFormat(eglDisplay,tlw->platformWindowFormat(),true);
+ VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig);
+
+ XVisualInfo visualInfoTemplate;
+ memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
+ visualInfoTemplate.visualid = id;
+
+ XVisualInfo *visualInfo;
+ int matchingCount = 0;
+ visualInfo = XGetVisualInfo(DISPLAY_FROM_XCB(this), VisualIDMask, &visualInfoTemplate, &matchingCount);
+#endif //XCB_USE_GLX
+ if (visualInfo) {
+ Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), m_screen->root(), visualInfo->visual, AllocNone);
+
+ XSetWindowAttributes a;
+ a.colormap = cmap;
+ m_window = XCreateWindow(DISPLAY_FROM_XCB(this), m_screen->root(), tlw->x(), tlw->y(), tlw->width(), tlw->height(),
+ 0, visualInfo->depth, InputOutput, visualInfo->visual,
+ CWColormap, &a);
+
+ printf("created GL window: %d\n", m_window);
+ } else {
+ qFatal("no window!");
+ }
+ } else
+#endif //defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
+ {
+ m_window = xcb_generate_id(xcb_connection());
+
+ Q_XCB_CALL(xcb_create_window(xcb_connection(),
+ XCB_COPY_FROM_PARENT, // depth -- same as root
+ m_window, // window id
+ m_screen->root(), // parent window id
+ tlw->x(),
+ tlw->y(),
+ tlw->width(),
+ tlw->height(),
+ 0, // border width
+ XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class
+ m_screen->screen()->root_visual, // visual
+ 0, // value mask
+ 0)); // value list
+
+ printf("created regular window: %d\n", m_window);
+ }
+
+ Q_XCB_CALL(xcb_change_window_attributes(xcb_connection(), m_window, mask, values));
+
+ xcb_atom_t properties[4];
+ int propertyCount = 0;
+ properties[propertyCount++] = atom(QXcbAtom::WM_DELETE_WINDOW);
+ properties[propertyCount++] = atom(QXcbAtom::WM_TAKE_FOCUS);
+ properties[propertyCount++] = atom(QXcbAtom::_NET_WM_PING);
+
+ if (m_screen->syncRequestSupported())
+ properties[propertyCount++] = atom(QXcbAtom::_NET_WM_SYNC_REQUEST);
+
+ if (tlw->windowFlags() & Qt::WindowContextHelpButtonHint)
+ properties[propertyCount++] = atom(QXcbAtom::_NET_WM_CONTEXT_HELP);
+
+ Q_XCB_CALL(xcb_change_property(xcb_connection(),
+ XCB_PROP_MODE_REPLACE,
+ m_window,
+ atom(QXcbAtom::WM_PROTOCOLS),
+ XCB_ATOM_ATOM,
+ 32,
+ propertyCount,
+ properties));
+ m_syncValue.hi = 0;
+ m_syncValue.lo = 0;
+
+ if (m_screen->syncRequestSupported()) {
+ m_syncCounter = xcb_generate_id(xcb_connection());
+ Q_XCB_CALL(xcb_sync_create_counter(xcb_connection(), m_syncCounter, m_syncValue));
+
+ Q_XCB_CALL(xcb_change_property(xcb_connection(),
+ XCB_PROP_MODE_REPLACE,
+ m_window,
+ atom(QXcbAtom::_NET_WM_SYNC_REQUEST_COUNTER),
+ XCB_ATOM_CARDINAL,
+ 32,
+ 1,
+ &m_syncCounter));
+ }
+
+ if (isTransient(tlw) && tlw->parentWidget()) {
+ // ICCCM 4.1.2.6
+ QWidget *p = tlw->parentWidget()->window();
+ xcb_window_t parentWindow = p->winId();
+ Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
+ XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 32,
+ 1, &parentWindow));
+
+ }
+
+ // set the PID to let the WM kill the application if unresponsive
+ long pid = getpid();
+ Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
+ atom(QXcbAtom::_NET_WM_PID), XCB_ATOM_CARDINAL, 32,
+ 1, &pid));
+}
+
+QXcbWindow::~QXcbWindow()
+{
+ delete m_context;
+ if (m_screen->syncRequestSupported())
+ Q_XCB_CALL(xcb_sync_destroy_counter(xcb_connection(), m_syncCounter));
+ Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window));
+}
+
+void QXcbWindow::setGeometry(const QRect &rect)
+{
+ QPlatformWindow::setGeometry(rect);
+
+ const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
+ const quint32 values[] = { rect.x(), rect.y(), rect.width(), rect.height() };
+
+ Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
+}
+
+void QXcbWindow::setVisible(bool visible)
+{
+ xcb_wm_hints_t hints;
+ if (visible) {
+ if (widget()->isMinimized())
+ xcb_wm_hints_set_iconic(&hints);
+ else
+ xcb_wm_hints_set_normal(&hints);
+ xcb_set_wm_hints(xcb_connection(), m_window, &hints);
+ Q_XCB_CALL(xcb_map_window(xcb_connection(), m_window));
+ connection()->sync();
+ } else {
+ Q_XCB_CALL(xcb_unmap_window(xcb_connection(), m_window));
+
+ // send synthetic UnmapNotify event according to icccm 4.1.4
+ xcb_unmap_notify_event_t event;
+ event.response_type = XCB_UNMAP_NOTIFY;
+ event.sequence = 0; // does this matter?
+ event.event = m_screen->root();
+ event.window = m_window;
+ event.from_configure = false;
+ Q_XCB_CALL(xcb_send_event(xcb_connection(), false, m_screen->root(),
+ XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&event));
+
+ xcb_flush(xcb_connection());
+ }
+}
+
+struct QtMWMHints {
+ quint32 flags, functions, decorations;
+ qint32 input_mode;
+ quint32 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
+};
+
+Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
+{
+ Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
+
+ setNetWmWindowTypes(flags);
+
+ 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);
+ Q_UNUSED(tool);
+
+ bool tooltip = (type == Qt::ToolTip);
+
+ QtMWMHints mwmhints;
+ mwmhints.flags = 0L;
+ mwmhints.functions = 0L;
+ mwmhints.decorations = 0;
+ mwmhints.input_mode = 0L;
+ mwmhints.status = 0L;
+
+ if (type != Qt::SplashScreen) {
+ 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 (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;
+ }
+
+ if (mwmhints.flags != 0l) {
+ Q_XCB_CALL(xcb_change_property(xcb_connection(),
+ XCB_PROP_MODE_REPLACE,
+ m_window,
+ atom(QXcbAtom::_MOTIF_WM_HINTS),
+ atom(QXcbAtom::_MOTIF_WM_HINTS),
+ 32,
+ 5,
+ &mwmhints));
+ } else {
+ Q_XCB_CALL(xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_MOTIF_WM_HINTS)));
+ }
+
+ if (popup || tooltip) {
+ const quint32 mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_SAVE_UNDER;
+ const quint32 values[] = { true, true };
+
+ Q_XCB_CALL(xcb_change_window_attributes(xcb_connection(), m_window, mask, values));
+ }
+
+ return QPlatformWindow::setWindowFlags(flags);
+}
+
+void QXcbWindow::setNetWmWindowTypes(Qt::WindowFlags flags)
+{
+ // in order of decreasing priority
+ QVector<uint> windowTypes;
+
+ Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
+
+ switch (type) {
+ case Qt::Dialog:
+ case Qt::Sheet:
+ windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_DIALOG));
+ break;
+ case Qt::Tool:
+ case Qt::Drawer:
+ windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_UTILITY));
+ break;
+ case Qt::ToolTip:
+ windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_TOOLTIP));
+ break;
+ case Qt::SplashScreen:
+ windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_SPLASH));
+ break;
+ default:
+ break;
+ }
+
+ if (flags & Qt::FramelessWindowHint)
+ windowTypes.append(atom(QXcbAtom::_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
+
+ windowTypes.append(atom(QXcbAtom::_NET_WM_WINDOW_TYPE_NORMAL));
+
+ Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window,
+ atom(QXcbAtom::_NET_WM_WINDOW_TYPE), XCB_ATOM_ATOM, 32,
+ windowTypes.count(), windowTypes.constData()));
+}
+
+WId QXcbWindow::winId() const
+{
+ return m_window;
+}
+
+void QXcbWindow::setParent(const QPlatformWindow *parent)
+{
+ QPoint topLeft = geometry().topLeft();
+ Q_XCB_CALL(xcb_reparent_window(xcb_connection(), window(), static_cast<const QXcbWindow *>(parent)->window(), topLeft.x(), topLeft.y()));
+}
+
+void QXcbWindow::setWindowTitle(const QString &title)
+{
+ QByteArray ba = title.toUtf8();
+ Q_XCB_CALL(xcb_change_property(xcb_connection(),
+ XCB_PROP_MODE_REPLACE,
+ m_window,
+ atom(QXcbAtom::_NET_WM_NAME),
+ atom(QXcbAtom::UTF8_STRING),
+ 8,
+ ba.length(),
+ ba.constData()));
+}
+
+void QXcbWindow::raise()
+{
+ const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
+ const quint32 values[] = { XCB_STACK_MODE_ABOVE };
+ Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
+}
+
+void QXcbWindow::lower()
+{
+ const quint32 mask = XCB_CONFIG_WINDOW_STACK_MODE;
+ const quint32 values[] = { XCB_STACK_MODE_BELOW };
+ Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
+}
+
+void QXcbWindow::requestActivateWindow()
+{
+ Q_XCB_CALL(xcb_set_input_focus(xcb_connection(), XCB_INPUT_FOCUS_PARENT, m_window, XCB_TIME_CURRENT_TIME));
+ connection()->sync();
+}
+
+QPlatformGLContext *QXcbWindow::glContext() const
+{
+ if (!QApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) {
+ printf("no opengl\n");
+ return 0;
+ }
+ if (!m_context) {
+#if defined(XCB_USE_GLX)
+ QXcbWindow *that = const_cast<QXcbWindow *>(this);
+ that->m_context = new QGLXContext(m_window, m_screen, widget()->platformWindowFormat());
+#elif defined(XCB_USE_EGL)
+ EGLDisplay display = connection()->egl_display();
+ EGLConfig config = q_configFromQPlatformWindowFormat(display,widget()->platformWindowFormat(),true);
+ QVector<EGLint> eglContextAttrs;
+ eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
+ eglContextAttrs.append(2);
+ eglContextAttrs.append(EGL_NONE);
+
+ EGLSurface eglSurface = eglCreateWindowSurface(display,config,(EGLNativeWindowType)m_window,0);
+ QXcbWindow *that = const_cast<QXcbWindow *>(this);
+ that->m_context = new QEGLPlatformContext(display, config, eglContextAttrs.data(), eglSurface, EGL_OPENGL_ES_API);
+#elif defined(XCB_USE_DRI2)
+ QXcbWindow *that = const_cast<QXcbWindow *>(this);
+ that->m_context = new QDri2Context(that);
+#endif
+ }
+ return m_context;
+}
+
+void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
+{
+ QWindowSurface *surface = widget()->windowSurface();
+ if (surface) {
+ QRect rect(event->x, event->y, event->width, event->height);
+
+ surface->flush(widget(), rect, QPoint());
+ }
+}
+
+void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event)
+{
+ if (event->format == 32 && event->type == atom(QXcbAtom::WM_PROTOCOLS)) {
+ if (event->data.data32[0] == atom(QXcbAtom::WM_DELETE_WINDOW)) {
+ QWindowSystemInterface::handleCloseEvent(widget());
+ } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_PING)) {
+ xcb_client_message_event_t reply = *event;
+
+ reply.response_type = XCB_CLIENT_MESSAGE;
+ reply.window = m_screen->root();
+
+ xcb_send_event(xcb_connection(), 0, m_screen->root(), XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (const char *)&reply);
+ xcb_flush(xcb_connection());
+ } else if (event->data.data32[0] == atom(QXcbAtom::_NET_WM_SYNC_REQUEST)) {
+ if (!m_hasReceivedSyncRequest) {
+ m_hasReceivedSyncRequest = true;
+ printf("Window manager supports _NET_WM_SYNC_REQUEST, syncing resizes\n");
+ }
+ m_syncValue.lo = event->data.data32[2];
+ m_syncValue.hi = event->data.data32[3];
+ }
+ }
+}
+
+void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event)
+{
+ int xpos = geometry().x();
+ int ypos = geometry().y();
+
+ if ((event->width == geometry().width() && event->height == geometry().height()) || event->x != 0 || event->y != 0) {
+ xpos = event->x;
+ ypos = event->y;
+ }
+
+ QRect rect(xpos, ypos, event->width, event->height);
+
+ if (rect == geometry())
+ return;
+
+ QPlatformWindow::setGeometry(rect);
+ QWindowSystemInterface::handleGeometryChange(widget(), rect);
+
+#if XCB_USE_DRI2
+ if (m_context)
+ static_cast<QDri2Context *>(m_context)->resize(rect.size());
+#endif
+}
+
+static Qt::MouseButtons translateMouseButtons(int s)
+{
+ Qt::MouseButtons ret = 0;
+ if (s & XCB_BUTTON_MASK_1)
+ ret |= Qt::LeftButton;
+ if (s & XCB_BUTTON_MASK_2)
+ ret |= Qt::MidButton;
+ if (s & XCB_BUTTON_MASK_3)
+ ret |= Qt::RightButton;
+ return ret;
+}
+
+static Qt::MouseButton translateMouseButton(xcb_button_t s)
+{
+ switch (s) {
+ case 1:
+ return Qt::LeftButton;
+ case 2:
+ return Qt::MidButton;
+ case 3:
+ return Qt::RightButton;
+ default:
+ return Qt::NoButton;
+ }
+}
+
+void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
+{
+ QPoint local(event->event_x, event->event_y);
+ QPoint global(event->root_x, event->root_y);
+
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier;
+
+ if (event->detail >= 4 && event->detail <= 7) {
+ //logic borrowed from qapplication_x11.cpp
+ int delta = 120 * ((event->detail == 4 || event->detail == 6) ? 1 : -1);
+ bool hor = (((event->detail == 4 || event->detail == 5)
+ && (modifiers & Qt::AltModifier))
+ || (event->detail == 6 || event->detail == 7));
+
+ QWindowSystemInterface::handleWheelEvent(widget(), event->time,
+ local, global, delta, hor ? Qt::Horizontal : Qt::Vertical);
+ return;
+ }
+
+ handleMouseEvent(event->detail, event->state, event->time, local, global);
+}
+
+void QXcbWindow::handleButtonReleaseEvent(const xcb_button_release_event_t *event)
+{
+ QPoint local(event->event_x, event->event_y);
+ QPoint global(event->root_x, event->root_y);
+
+ handleMouseEvent(event->detail, event->state, event->time, local, global);
+}
+
+void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
+{
+ QPoint local(event->event_x, event->event_y);
+ QPoint global(event->root_x, event->root_y);
+
+ handleMouseEvent(event->detail, event->state, event->time, local, global);
+}
+
+void QXcbWindow::handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global)
+{
+ Qt::MouseButtons buttons = translateMouseButtons(state);
+ Qt::MouseButton button = translateMouseButton(detail);
+
+ buttons ^= button; // X event uses state *before*, Qt uses state *after*
+
+ QWindowSystemInterface::handleMouseEvent(widget(), time, local, global, buttons);
+}
+
+void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *)
+{
+ QWindowSystemInterface::handleEnterEvent(widget());
+}
+
+void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *)
+{
+ QWindowSystemInterface::handleLeaveEvent(widget());
+}
+
+void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *)
+{
+ QWindowSystemInterface::handleWindowActivated(widget());
+}
+
+void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *)
+{
+ QWindowSystemInterface::handleWindowActivated(0);
+}
+
+void QXcbWindow::updateSyncRequestCounter()
+{
+ if (m_screen->syncRequestSupported() && (m_syncValue.lo != 0 || m_syncValue.hi != 0)) {
+ Q_XCB_CALL(xcb_sync_set_counter(xcb_connection(), m_syncCounter, m_syncValue));
+ xcb_flush(xcb_connection());
+ connection()->sync();
+
+ m_syncValue.lo = 0;
+ m_syncValue.hi = 0;
+ }
+}
diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h
new file mode 100644
index 0000000000..e049837253
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbwindow.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBWINDOW_H
+#define QXCBWINDOW_H
+
+#include <QtGui/QPlatformWindow>
+#include <QtGui/QPlatformWindowFormat>
+
+#include <xcb/xcb.h>
+#include <xcb/sync.h>
+
+#include "qxcbobject.h"
+
+class QXcbScreen;
+
+class QXcbWindow : public QXcbObject, public QPlatformWindow
+{
+public:
+ QXcbWindow(QWidget *tlw);
+ ~QXcbWindow();
+
+ void setGeometry(const QRect &rect);
+
+ void setVisible(bool visible);
+ Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags);
+ WId winId() const;
+ void setParent(const QPlatformWindow *window);
+
+ void setWindowTitle(const QString &title);
+ void raise();
+ void lower();
+
+ void requestActivateWindow();
+
+ QPlatformGLContext *glContext() const;
+
+ xcb_window_t window() const { return m_window; }
+
+ void handleExposeEvent(const xcb_expose_event_t *event);
+ void handleClientMessageEvent(const xcb_client_message_event_t *event);
+ void handleConfigureNotifyEvent(const xcb_configure_notify_event_t *event);
+ void handleButtonPressEvent(const xcb_button_press_event_t *event);
+ void handleButtonReleaseEvent(const xcb_button_release_event_t *event);
+ void handleMotionNotifyEvent(const xcb_motion_notify_event_t *event);
+
+ void handleEnterNotifyEvent(const xcb_enter_notify_event_t *event);
+ void handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event);
+ void handleFocusInEvent(const xcb_focus_in_event_t *event);
+ void handleFocusOutEvent(const xcb_focus_out_event_t *event);
+
+ void handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global);
+
+ void updateSyncRequestCounter();
+
+private:
+ void setNetWmWindowTypes(Qt::WindowFlags flags);
+
+ QXcbScreen *m_screen;
+
+ xcb_window_t m_window;
+ QPlatformGLContext *m_context;
+
+ xcb_sync_int64_t m_syncValue;
+ xcb_sync_counter_t m_syncCounter;
+
+ bool m_hasReceivedSyncRequest;
+};
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp
new file mode 100644
index 0000000000..718f09383c
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp
@@ -0,0 +1,258 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 "qxcbwindowsurface.h"
+
+#include "qxcbconnection.h"
+#include "qxcbscreen.h"
+#include "qxcbwindow.h"
+
+#include <xcb/shm.h>
+#include <xcb/xcb_image.h>
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <stdio.h>
+
+#include <qdebug.h>
+
+class QXcbShmImage : public QXcbObject
+{
+public:
+ QXcbShmImage(QXcbScreen *connection, const QSize &size);
+ ~QXcbShmImage() { destroy(); }
+
+ QImage *image() { return &m_qimage; }
+
+ void put(xcb_window_t window, const QPoint &dst, const QRect &source);
+ void preparePaint(const QRegion &region);
+
+private:
+ void destroy();
+
+ xcb_shm_segment_info_t m_shm_info;
+
+ xcb_image_t *m_xcb_image;
+
+ QImage m_qimage;
+
+ xcb_gcontext_t m_gc;
+ xcb_window_t m_gc_window;
+
+ QRegion m_dirty;
+};
+
+QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size)
+ : QXcbObject(screen->connection())
+ , m_gc(0)
+ , m_gc_window(0)
+{
+ Q_XCB_NOOP(connection());
+ m_xcb_image = xcb_image_create_native(xcb_connection(),
+ size.width(),
+ size.height(),
+ XCB_IMAGE_FORMAT_Z_PIXMAP,
+ screen->depth(),
+ 0,
+ ~0,
+ 0);
+
+ m_shm_info.shmid = shmget (IPC_PRIVATE,
+ m_xcb_image->stride * m_xcb_image->height, IPC_CREAT|0777);
+
+ m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat (m_shm_info.shmid, 0, 0);
+ m_shm_info.shmseg = xcb_generate_id(xcb_connection());
+
+ xcb_generic_error_t *error = xcb_request_check(xcb_connection(), xcb_shm_attach_checked(xcb_connection(), m_shm_info.shmseg, m_shm_info.shmid, false));
+ if (error) {
+ qWarning() << "QXcbWindowSurface: Unable to attach to shared memory segment";
+ free(error);
+ }
+
+ if (shmctl(m_shm_info.shmid, IPC_RMID, 0) == -1)
+ qWarning() << "QXcbWindowSurface: Error while marking the shared memory segment to be destroyed";
+
+ m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, screen->format());
+}
+
+void QXcbShmImage::destroy()
+{
+ Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg));
+ xcb_image_destroy(m_xcb_image);
+ shmdt(m_shm_info.shmaddr);
+ shmctl(m_shm_info.shmid, IPC_RMID, 0);
+ if (m_gc)
+ Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));
+}
+
+void QXcbShmImage::put(xcb_window_t window, const QPoint &target, const QRect &source)
+{
+ Q_XCB_NOOP(connection());
+ if (m_gc_window != window) {
+ if (m_gc)
+ Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));
+
+ m_gc = xcb_generate_id(xcb_connection());
+ Q_XCB_CALL(xcb_create_gc(xcb_connection(), m_gc, window, 0, 0));
+
+ m_gc_window = window;
+ }
+
+ Q_XCB_NOOP(connection());
+ xcb_image_shm_put(xcb_connection(),
+ window,
+ m_gc,
+ m_xcb_image,
+ m_shm_info,
+ source.x(),
+ source.y(),
+ target.x(),
+ target.y(),
+ source.width(),
+ source.height(),
+ false);
+ Q_XCB_NOOP(connection());
+
+ m_dirty = m_dirty | source;
+
+ xcb_flush(xcb_connection());
+ Q_XCB_NOOP(connection());
+}
+
+void QXcbShmImage::preparePaint(const QRegion &region)
+{
+ // to prevent X from reading from the image region while we're writing to it
+ if (m_dirty.intersects(region)) {
+ connection()->sync();
+ m_dirty = QRegion();
+ }
+}
+
+QXcbWindowSurface::QXcbWindowSurface(QWidget *widget, bool setDefaultSurface)
+ : QWindowSurface(widget, setDefaultSurface)
+ , m_image(0)
+ , m_syncingResize(false)
+{
+ QXcbScreen *screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(widget));
+ setConnection(screen->connection());
+}
+
+QXcbWindowSurface::~QXcbWindowSurface()
+{
+ delete m_image;
+}
+
+QPaintDevice *QXcbWindowSurface::paintDevice()
+{
+ return m_image->image();
+}
+
+void QXcbWindowSurface::beginPaint(const QRegion &region)
+{
+ m_image->preparePaint(region);
+}
+
+void QXcbWindowSurface::endPaint(const QRegion &)
+{
+}
+
+void QXcbWindowSurface::flush(QWidget *widget, const QRegion &region, const QPoint &offset)
+{
+ QRect bounds = region.boundingRect();
+
+ if (size().isEmpty() || !geometry().contains(bounds))
+ return;
+
+ Q_XCB_NOOP(connection());
+
+ QXcbWindow *window = static_cast<QXcbWindow *>(widget->window()->platformWindow());
+
+ extern QWidgetData* qt_widget_data(QWidget *);
+ QPoint widgetOffset = qt_qwidget_data(widget)->wrect.topLeft();
+
+ QVector<QRect> rects = region.rects();
+ for (int i = 0; i < rects.size(); ++i)
+ m_image->put(window->window(), rects.at(i).topLeft() - widgetOffset, rects.at(i).translated(offset));
+
+ Q_XCB_NOOP(connection());
+
+ if (m_syncingResize) {
+ xcb_flush(xcb_connection());
+ connection()->sync();
+ m_syncingResize = false;
+ window->updateSyncRequestCounter();
+ }
+}
+
+void QXcbWindowSurface::resize(const QSize &size)
+{
+ if (size == QWindowSurface::size())
+ return;
+
+ Q_XCB_NOOP(connection());
+ QWindowSurface::resize(size);
+
+ QXcbScreen *screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(window()));
+
+ delete m_image;
+ m_image = new QXcbShmImage(screen, size);
+ Q_XCB_NOOP(connection());
+
+ m_syncingResize = true;
+}
+
+extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
+
+bool QXcbWindowSurface::scroll(const QRegion &area, int dx, int dy)
+{
+ if (m_image->image()->isNull())
+ return false;
+
+ m_image->preparePaint(area);
+
+ const QVector<QRect> rects = area.rects();
+ for (int i = 0; i < rects.size(); ++i)
+ qt_scrollRectInImage(*m_image->image(), rects.at(i), QPoint(dx, dy));
+
+ return true;
+}
+
diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.h b/src/plugins/platforms/xcb/qxcbwindowsurface.h
new file mode 100644
index 0000000000..23d32ef445
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbwindowsurface.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QXCBWINDOWSURFACE_H
+#define QXCBWINDOWSURFACE_H
+
+#include <private/qwindowsurface_p.h>
+
+#include <xcb/xcb.h>
+
+#include "qxcbobject.h"
+
+class QXcbShmImage;
+
+class QXcbWindowSurface : public QXcbObject, public QWindowSurface
+{
+public:
+ QXcbWindowSurface(QWidget *widget, bool setDefaultSurface = true);
+ ~QXcbWindowSurface();
+
+ QPaintDevice *paintDevice();
+ void flush(QWidget *widget, const QRegion &region, const QPoint &offset);
+ void resize(const QSize &size);
+ bool scroll(const QRegion &area, int dx, int dy);
+
+ void beginPaint(const QRegion &);
+ void endPaint(const QRegion &);
+
+private:
+ QXcbShmImage *m_image;
+ bool m_syncingResize;
+};
+
+#endif
diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro
new file mode 100644
index 0000000000..101bdcd3c1
--- /dev/null
+++ b/src/plugins/platforms/xcb/xcb.pro
@@ -0,0 +1,70 @@
+TARGET = xcb
+
+include(../../qpluginbase.pri)
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms
+
+SOURCES = \
+ qxcbconnection.cpp \
+ qxcbintegration.cpp \
+ qxcbkeyboard.cpp \
+ qxcbscreen.cpp \
+ qxcbwindow.cpp \
+ qxcbwindowsurface.cpp \
+ main.cpp \
+ qxcbnativeinterface.cpp
+
+HEADERS = \
+ qxcbconnection.h \
+ qxcbintegration.h \
+ qxcbkeyboard.h \
+ qxcbobject.h \
+ qxcbscreen.h \
+ qxcbwindow.h \
+ qxcbwindowsurface.h \
+ qxcbnativeinterface.h
+
+contains(QT_CONFIG, opengl) {
+ QT += opengl
+
+# DEFINES += XCB_USE_DRI2
+ contains(DEFINES, XCB_USE_DRI2) {
+ LIBS += -lxcb-dri2 -lxcb-xfixes -lEGL
+
+ CONFIG += link_pkgconfig
+ PKGCONFIG += libdrm
+
+ HEADERS += qdri2context.h
+ SOURCES += qdri2context.cpp
+
+ } else {
+ DEFINES += XCB_USE_XLIB
+ LIBS += -lX11 -lX11-xcb
+
+ contains(QT_CONFIG, opengles2) {
+ DEFINES += XCB_USE_EGL
+ HEADERS += \
+ ../eglconvenience/qeglplatformcontext.h \
+ ../eglconvenience/qeglconvenience.h \
+ ../eglconvenience/qxlibeglintegration.h
+
+ SOURCES += \
+ ../eglconvenience/qeglplatformcontext.cpp \
+ ../eglconvenience/qeglconvenience.cpp \
+ ../eglconvenience/qxlibeglintegration.cpp
+
+ LIBS += -lEGL
+ } else {
+ DEFINES += XCB_USE_GLX
+ include (../glxconvenience/glxconvenience.pri)
+ HEADERS += qglxintegration.h
+ SOURCES += qglxintegration.cpp
+ }
+ }
+}
+
+LIBS += -lxcb -lxcb-image -lxcb-keysyms -lxcb-icccm -lxcb-sync
+
+include (../fontdatabases/genericunix/genericunix.pri)
+
+target.path += $$[QT_INSTALL_PLUGINS]/platforms
+INSTALLS += target