1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qxcbintegration.h"
43 #include "qxcbconnection.h"
44 #include "qxcbscreen.h"
45 #include "qxcbwindow.h"
46 #include "qxcbcursor.h"
47 #include "qxcbkeyboard.h"
48 #include "qxcbbackingstore.h"
49 #include "qxcbnativeinterface.h"
50 #include "qxcbclipboard.h"
55 #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
56 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
57 #include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
58 #include <QtPlatformSupport/private/qgenericunixservices_p.h>
62 //this has to be included before egl, since egl pulls in X headers
63 #include <QtGui/private/qguiapplication_p.h>
73 #include <qpa/qplatforminputcontextfactory_p.h>
74 #include <private/qgenericunixthemes_p.h>
75 #include <qpa/qplatforminputcontext.h>
77 #if defined(XCB_USE_GLX)
78 #include "qglxintegration.h"
79 #elif defined(XCB_USE_EGL)
80 #include "qxcbeglsurface.h"
81 #include <QtPlatformSupport/private/qeglplatformcontext_p.h>
84 #include <QtGui/QOpenGLContext>
85 #include <QtGui/QScreen>
86 #ifndef QT_NO_ACCESSIBILITY
87 #include <qpa/qplatformaccessibility.h>
92 QXcbIntegration::QXcbIntegration(const QStringList ¶meters)
93 : m_eventDispatcher(createUnixEventDispatcher()),
94 m_services(new QGenericUnixServices)
96 QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
101 m_nativeInterface.reset(new QXcbNativeInterface);
103 m_connections << new QXcbConnection(m_nativeInterface.data());
105 for (int i = 0; i < parameters.size() - 1; i += 2) {
107 qDebug() << "QXcbIntegration: Connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
109 QString display = parameters.at(i) + ':' + parameters.at(i+1);
110 m_connections << new QXcbConnection(m_nativeInterface.data(), display.toLatin1().constData());
113 foreach (QXcbConnection *connection, m_connections)
114 foreach (QXcbScreen *screen, connection->screens())
117 m_fontDatabase.reset(new QGenericUnixFontDatabase());
118 m_inputContext.reset(QPlatformInputContextFactory::create());
119 #ifndef QT_NO_ACCESSIBILITY
120 m_accessibility.reset(new QPlatformAccessibility());
124 QXcbIntegration::~QXcbIntegration()
126 qDeleteAll(m_connections);
129 QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
131 return new QXcbWindow(window);
134 #if defined(XCB_USE_EGL)
135 class QEGLXcbPlatformContext : public QEGLPlatformContext
138 QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share,
139 EGLDisplay display, QXcbConnection *c)
140 : QEGLPlatformContext(glFormat, share, display)
143 Q_XCB_NOOP(m_connection);
146 void swapBuffers(QPlatformSurface *surface)
148 Q_XCB_NOOP(m_connection);
149 QEGLPlatformContext::swapBuffers(surface);
150 Q_XCB_NOOP(m_connection);
153 bool makeCurrent(QPlatformSurface *surface)
155 Q_XCB_NOOP(m_connection);
156 bool ret = QEGLPlatformContext::makeCurrent(surface);
157 Q_XCB_NOOP(m_connection);
163 Q_XCB_NOOP(m_connection);
164 QEGLPlatformContext::doneCurrent();
165 Q_XCB_NOOP(m_connection);
168 EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
170 return static_cast<QXcbWindow *>(surface)->eglSurface()->surface();
174 QXcbConnection *m_connection;
179 QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
181 QXcbScreen *screen = static_cast<QXcbScreen *>(context->screen()->handle());
182 #if defined(XCB_USE_GLX)
183 return new QGLXContext(screen, context->format(), context->shareHandle());
184 #elif defined(XCB_USE_EGL)
185 return new QEGLXcbPlatformContext(context->format(), context->shareHandle(),
186 screen->connection()->egl_display(), screen->connection());
187 #elif defined(XCB_USE_DRI2)
188 return new QDri2Context(context->format(), context->shareHandle());
190 qWarning("QXcbIntegration: Cannot create platform OpenGL context, none of GLX, EGL, or DRI2 are enabled");
195 QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const
197 return new QXcbBackingStore(window);
200 bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
203 case ThreadedPixmaps: return true;
204 case OpenGL: return true;
205 case ThreadedOpenGL: return false;
206 default: return QPlatformIntegration::hasCapability(cap);
210 QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const
212 return m_eventDispatcher;
215 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
221 QPlatformFontDatabase *QXcbIntegration::fontDatabase() const
223 return m_fontDatabase.data();
226 QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
228 return m_nativeInterface.data();
231 #ifndef QT_NO_CLIPBOARD
232 QPlatformClipboard *QXcbIntegration::clipboard() const
234 return m_connections.at(0)->clipboard();
238 #ifndef QT_NO_DRAGANDDROP
239 QPlatformDrag *QXcbIntegration::drag() const
241 return m_connections.at(0)->drag();
245 QPlatformInputContext *QXcbIntegration::inputContext() const
247 return m_inputContext.data();
250 #ifndef QT_NO_ACCESSIBILITY
251 QPlatformAccessibility *QXcbIntegration::accessibility() const
253 return m_accessibility.data();
257 QPlatformServices *QXcbIntegration::services() const
259 return m_services.data();
262 Qt::KeyboardModifiers QXcbIntegration::queryKeyboardModifiers() const
265 QXcbConnection* conn = m_connections.at(0);
266 QXcbCursor::queryPointer(conn->xcb_connection(), 0, 0, &keybMask);
267 return conn->keyboard()->translateModifiers(keybMask);
270 QStringList QXcbIntegration::themeNames() const
272 return QGenericUnixTheme::themeNames();
275 QPlatformTheme *QXcbIntegration::createPlatformTheme(const QString &name) const
277 return QGenericUnixTheme::createUnixTheme(name);