QPlatformWindow: Add Window masks.
[profile/ivi/qtbase.git] / src / plugins / platforms / xcb / qxcbintegration.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
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"
51 #include "qxcbdrag.h"
52
53 #include <xcb/xcb.h>
54
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>
59
60 #include <stdio.h>
61
62 //this has to be included before egl, since egl pulls in X headers
63 #include <QtGui/private/qguiapplication_p.h>
64
65 #ifdef XCB_USE_EGL
66 #include <EGL/egl.h>
67 #endif
68
69 #ifdef XCB_USE_XLIB
70 #include <X11/Xlib.h>
71 #endif
72
73 #include <qpa/qplatforminputcontextfactory_p.h>
74 #include <private/qgenericunixthemes_p.h>
75 #include <qpa/qplatforminputcontext.h>
76
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>
82 #endif
83
84 #include <QtGui/QOpenGLContext>
85 #include <QtGui/QScreen>
86 #ifndef QT_NO_ACCESSIBILITY
87 #include <qpa/qplatformaccessibility.h>
88 #endif
89
90 QT_BEGIN_NAMESPACE
91
92 QXcbIntegration::QXcbIntegration(const QStringList &parameters)
93     : m_eventDispatcher(createUnixEventDispatcher()),
94       m_services(new QGenericUnixServices)
95 {
96     QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
97
98 #ifdef XCB_USE_XLIB
99     XInitThreads();
100 #endif
101     m_nativeInterface.reset(new QXcbNativeInterface);
102
103     m_connections << new QXcbConnection(m_nativeInterface.data());
104
105     for (int i = 0; i < parameters.size() - 1; i += 2) {
106 #ifdef Q_XCB_DEBUG
107         qDebug() << "QXcbIntegration: Connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
108 #endif
109         QString display = parameters.at(i) + ':' + parameters.at(i+1);
110         m_connections << new QXcbConnection(m_nativeInterface.data(), display.toLatin1().constData());
111     }
112
113     foreach (QXcbConnection *connection, m_connections)
114         foreach (QXcbScreen *screen, connection->screens())
115             screenAdded(screen);
116
117     m_fontDatabase.reset(new QGenericUnixFontDatabase());
118     m_inputContext.reset(QPlatformInputContextFactory::create());
119 #ifndef QT_NO_ACCESSIBILITY
120     m_accessibility.reset(new QPlatformAccessibility());
121 #endif
122 }
123
124 QXcbIntegration::~QXcbIntegration()
125 {
126     qDeleteAll(m_connections);
127 }
128
129 QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
130 {
131     return new QXcbWindow(window);
132 }
133
134 #if defined(XCB_USE_EGL)
135 class QEGLXcbPlatformContext : public QEGLPlatformContext
136 {
137 public:
138     QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share,
139                            EGLDisplay display, QXcbConnection *c)
140         : QEGLPlatformContext(glFormat, share, display)
141         , m_connection(c)
142     {
143         Q_XCB_NOOP(m_connection);
144     }
145
146     void swapBuffers(QPlatformSurface *surface)
147     {
148         Q_XCB_NOOP(m_connection);
149         QEGLPlatformContext::swapBuffers(surface);
150         Q_XCB_NOOP(m_connection);
151     }
152
153     bool makeCurrent(QPlatformSurface *surface)
154     {
155         Q_XCB_NOOP(m_connection);
156         bool ret = QEGLPlatformContext::makeCurrent(surface);
157         Q_XCB_NOOP(m_connection);
158         return ret;
159     }
160
161     void doneCurrent()
162     {
163         Q_XCB_NOOP(m_connection);
164         QEGLPlatformContext::doneCurrent();
165         Q_XCB_NOOP(m_connection);
166     }
167
168     EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
169     {
170         return static_cast<QXcbWindow *>(surface)->eglSurface()->surface();
171     }
172
173 private:
174     QXcbConnection *m_connection;
175 };
176 #endif
177
178 #ifndef QT_NO_OPENGL
179 QPlatformOpenGLContext *QXcbIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
180 {
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());
189 #endif
190     qWarning("QXcbIntegration: Cannot create platform OpenGL context, none of GLX, EGL, or DRI2 are enabled");
191     return 0;
192 }
193 #endif
194
195 QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const
196 {
197     return new QXcbBackingStore(window);
198 }
199
200 bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
201 {
202     switch (cap) {
203     case ThreadedPixmaps: return true;
204     case OpenGL: return true;
205     case ThreadedOpenGL: return false;
206     case WindowMasks: return true;
207     default: return QPlatformIntegration::hasCapability(cap);
208     }
209 }
210
211 QAbstractEventDispatcher *QXcbIntegration::guiThreadEventDispatcher() const
212 {
213     return m_eventDispatcher;
214 }
215
216 void QXcbIntegration::moveToScreen(QWindow *window, int screen)
217 {
218     Q_UNUSED(window);
219     Q_UNUSED(screen);
220 }
221
222 QPlatformFontDatabase *QXcbIntegration::fontDatabase() const
223 {
224     return m_fontDatabase.data();
225 }
226
227 QPlatformNativeInterface * QXcbIntegration::nativeInterface() const
228 {
229     return m_nativeInterface.data();
230 }
231
232 #ifndef QT_NO_CLIPBOARD
233 QPlatformClipboard *QXcbIntegration::clipboard() const
234 {
235     return m_connections.at(0)->clipboard();
236 }
237 #endif
238
239 #ifndef QT_NO_DRAGANDDROP
240 QPlatformDrag *QXcbIntegration::drag() const
241 {
242     return m_connections.at(0)->drag();
243 }
244 #endif
245
246 QPlatformInputContext *QXcbIntegration::inputContext() const
247 {
248     return m_inputContext.data();
249 }
250
251 #ifndef QT_NO_ACCESSIBILITY
252 QPlatformAccessibility *QXcbIntegration::accessibility() const
253 {
254     return m_accessibility.data();
255 }
256 #endif
257
258 QPlatformServices *QXcbIntegration::services() const
259 {
260     return m_services.data();
261 }
262
263 Qt::KeyboardModifiers QXcbIntegration::queryKeyboardModifiers() const
264 {
265     int keybMask = 0;
266     QXcbConnection* conn = m_connections.at(0);
267     QXcbCursor::queryPointer(conn->xcb_connection(), 0, 0, &keybMask);
268     return conn->keyboard()->translateModifiers(keybMask);
269 }
270
271 QStringList QXcbIntegration::themeNames() const
272 {
273     return QGenericUnixTheme::themeNames();
274 }
275
276 QPlatformTheme *QXcbIntegration::createPlatformTheme(const QString &name) const
277 {
278     return QGenericUnixTheme::createUnixTheme(name);
279 }
280
281 QT_END_NAMESPACE