diff options
author | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2013-03-20 13:46:57 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2013-03-20 13:49:28 +0100 |
commit | 76c0be34cd4ff4564693162fa7528463e23ce9d8 (patch) | |
tree | f165b7bc319548fb0082365411a871028f92e89e /src/plugins/platforms/xcb | |
parent | 27b4fe96b59e9e63d1e570e802c072e9afdfb2d4 (diff) | |
parent | 36cb3f3f655a9090c82de609010cbfb88651a0f3 (diff) |
Merge branch 'dev' into stable
This starts Qt 5.1 release cycle
Conflicts:
src/gui/text/qfontdatabase.cpp
src/gui/text/qharfbuzz_copy_p.h
src/widgets/kernel/qapplication.cpp
src/widgets/kernel/qcoreapplication.cpp
Change-Id: I72fbf83ab3c2206aeea1b089428b0fc2a89bd62b
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r-- | src/plugins/platforms/xcb/qglxintegration.cpp | 193 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qglxintegration.h | 20 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 6 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbcursor.cpp | 34 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 22 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbkeyboard.cpp | 9 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 242 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.h | 9 |
10 files changed, 455 insertions, 84 deletions
diff --git a/src/plugins/platforms/xcb/qglxintegration.cpp b/src/plugins/platforms/xcb/qglxintegration.cpp index 2a6ef5a6ee..516b35dac8 100644 --- a/src/plugins/platforms/xcb/qglxintegration.cpp +++ b/src/plugins/platforms/xcb/qglxintegration.cpp @@ -50,6 +50,7 @@ #include <GL/glx.h> #include <QtGui/QOpenGLContext> +#include <QtGui/QOffscreenSurface> #include "qglxintegration.h" #include <QtPlatformSupport/private/qglxconvenience_p.h> @@ -70,6 +71,10 @@ typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXC #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 #endif +#ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT +#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 +#endif + #ifndef GLX_CONTEXT_PROFILE_MASK_ARB #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 #endif @@ -122,46 +127,53 @@ static void updateFormatFromContext(QSurfaceFormat &format) } format.setProfile(QSurfaceFormat::NoProfile); + format.setOption(QSurfaceFormat::FormatOptions()); - const int version = (major << 8) + minor; - if (version < 0x0300) { - format.setProfile(QSurfaceFormat::NoProfile); - format.setOption(QSurfaceFormat::DeprecatedFunctions); - return; - } - - // Version 3.0 onwards - check if it includes deprecated functionality or is - // a debug context - GLint value = 0; - glGetIntegerv(GL_CONTEXT_FLAGS, &value); - if (!(value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)) - format.setOption(QSurfaceFormat::DeprecatedFunctions); - if (value & GL_CONTEXT_FLAG_DEBUG_BIT) - format.setOption(QSurfaceFormat::DebugContext); - if (version < 0x0302) - return; - - // Version 3.2 and newer have a profile - value = 0; - glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value); + if (format.renderableType() == QSurfaceFormat::OpenGL) { + if (format.version() < qMakePair(3, 0)) { + format.setOption(QSurfaceFormat::DeprecatedFunctions); + return; + } - if (value & GL_CONTEXT_CORE_PROFILE_BIT) - format.setProfile(QSurfaceFormat::CoreProfile); - else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) - format.setProfile(QSurfaceFormat::CompatibilityProfile); + // Version 3.0 onwards - check if it includes deprecated functionality or is + // a debug context + GLint value = 0; + glGetIntegerv(GL_CONTEXT_FLAGS, &value); + if (!(value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)) + format.setOption(QSurfaceFormat::DeprecatedFunctions); + if (value & GL_CONTEXT_FLAG_DEBUG_BIT) + format.setOption(QSurfaceFormat::DebugContext); + if (format.version() < qMakePair(3, 2)) + return; + + // Version 3.2 and newer have a profile + value = 0; + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value); + + if (value & GL_CONTEXT_CORE_PROFILE_BIT) + format.setProfile(QSurfaceFormat::CoreProfile); + else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) + format.setProfile(QSurfaceFormat::CompatibilityProfile); + } } QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share) : QPlatformOpenGLContext() , m_screen(screen) , m_context(0) + , m_shareContext(0) , m_format(format) + , m_isPBufferCurrent(false) { - m_shareContext = 0; + if (m_format.renderableType() == QSurfaceFormat::DefaultRenderableType) + m_format.setRenderableType(QSurfaceFormat::OpenGL); + if (m_format.renderableType() != QSurfaceFormat::OpenGL && m_format.renderableType() != QSurfaceFormat::OpenGLES) + return; + if (share) m_shareContext = static_cast<const QGLXContext*>(share)->glxContext(); - GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),format); + GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),m_format); XVisualInfo *visualInfo = 0; Window window = 0; // Temporary window used to query OpenGL context @@ -174,17 +186,31 @@ QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlat bool supportsProfiles = glxExt.contains("GLX_ARB_create_context_profile"); // Use glXCreateContextAttribsARB if available - if (glxExt.contains("GLX_ARB_create_context") && glXCreateContextAttribsARB != 0) { + // Also, GL ES context creation requires GLX_EXT_create_context_es2_profile + if (glxExt.contains("GLX_ARB_create_context") && glXCreateContextAttribsARB != 0 + && (m_format.renderableType() != QSurfaceFormat::OpenGLES || (supportsProfiles && glxExt.contains("GLX_EXT_create_context_es2_profile")))) { // Try to create an OpenGL context for each known OpenGL version in descending // order from the requested version. const int requestedVersion = format.majorVersion() * 10 + qMin(format.minorVersion(), 9); QVector<int> glVersions; - if (requestedVersion > 43) - glVersions << requestedVersion; + if (m_format.renderableType() == QSurfaceFormat::OpenGL) { + if (requestedVersion > 43) + glVersions << requestedVersion; + + // Don't bother with versions below 2.0 + glVersions << 43 << 42 << 41 << 40 << 33 << 32 << 31 << 30 << 21 << 20; + } else if (m_format.renderableType() == QSurfaceFormat::OpenGLES) { + if (requestedVersion > 30) + glVersions << requestedVersion; + + // Don't bother with versions below ES 2.0 + glVersions << 30 << 20; + // ES does not support any format option + m_format.setOption(QSurfaceFormat::FormatOptions()); + } - // Don't bother with versions below 2.0 - glVersions << 43 << 42 << 41 << 40 << 33 << 32 << 31 << 30 << 21 << 20; + Q_ASSERT(glVersions.count() > 0); for (int i = 0; !m_context && i < glVersions.count(); i++) { const int version = glVersions[i]; @@ -198,25 +224,30 @@ QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlat contextAttributes << GLX_CONTEXT_MAJOR_VERSION_ARB << majorVersion << GLX_CONTEXT_MINOR_VERSION_ARB << minorVersion; - // If asking for OpenGL 3.2 or newer we should also specify a profile - if (version >= 32 && supportsProfiles) { - if (m_format.profile() == QSurfaceFormat::CoreProfile) - contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_CORE_PROFILE_BIT_ARB; - else - contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - } - int flags = 0; + if (m_format.renderableType() == QSurfaceFormat::OpenGL) { + // If asking for OpenGL 3.2 or newer we should also specify a profile + if (version >= 32 && supportsProfiles) { + if (m_format.profile() == QSurfaceFormat::CoreProfile) + contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_CORE_PROFILE_BIT_ARB; + else + contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + } + + int flags = 0; - if (m_format.testOption(QSurfaceFormat::DebugContext)) - flags |= GLX_CONTEXT_DEBUG_BIT_ARB; + if (m_format.testOption(QSurfaceFormat::DebugContext)) + flags |= GLX_CONTEXT_DEBUG_BIT_ARB; - // A forward-compatible context may be requested for 3.0 and later - if (version >= 30 && !m_format.testOption(QSurfaceFormat::DeprecatedFunctions)) - flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + // A forward-compatible context may be requested for 3.0 and later + if (version >= 30 && !m_format.testOption(QSurfaceFormat::DeprecatedFunctions)) + flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - if (flags != 0) - contextAttributes << GLX_CONTEXT_FLAGS_ARB << flags; + if (flags != 0) + contextAttributes << GLX_CONTEXT_FLAGS_ARB << flags; + } else if (m_format.renderableType() == QSurfaceFormat::OpenGLES) { + contextAttributes << GLX_CONTEXT_PROFILE_MASK_ARB << GLX_CONTEXT_ES2_PROFILE_BIT_EXT; + } contextAttributes << None; @@ -232,6 +263,10 @@ QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlat // Could not create a context using glXCreateContextAttribsARB, falling back to glXCreateNewContext. if (!m_context) { + // requesting an OpenGL ES context requires glXCreateContextAttribsARB, so bail out + if (m_format.renderableType() == QSurfaceFormat::OpenGLES) + return; + m_context = glXCreateNewContext(DISPLAY_FROM_XCB(screen), config, GLX_RGBA_TYPE, m_shareContext, true); if (!m_context && m_shareContext) { // re-try without a shared glx context @@ -243,11 +278,15 @@ QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlat // Get the basic surface format details if (m_context) - m_format = qglx_surfaceFormatFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context); + qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(screen), config, m_context); // Create a temporary window so that we can make the new context current window = createDummyWindow(screen, config); } else { + // requesting an OpenGL ES context requires glXCreateContextAttribsARB, so bail out + if (m_format.renderableType() == QSurfaceFormat::OpenGLES) + return; + // Note that m_format gets updated with the used surface format visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(screen), screen->screenNumber(), &m_format); if (!visualInfo) @@ -286,19 +325,35 @@ bool QGLXContext::makeCurrent(QPlatformSurface *surface) { Q_ASSERT(surface->surface()->surfaceType() == QSurface::OpenGLSurface); - GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window(); - - return glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), glxDrawable, m_context); + QSurface::SurfaceClass surfaceClass = surface->surface()->surfaceClass(); + if (surfaceClass == QSurface::Window) { + m_isPBufferCurrent = false; + QXcbWindow *window = static_cast<QXcbWindow *>(surface); + return glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), window->xcb_window(), m_context); + } else if (surfaceClass == QSurface::Offscreen) { + m_isPBufferCurrent = true; + QGLXPbuffer *pbuffer = static_cast<QGLXPbuffer *>(surface); + return glXMakeContextCurrent(DISPLAY_FROM_XCB(m_screen), pbuffer->pbuffer(), pbuffer->pbuffer(), m_context); + } + return false; } void QGLXContext::doneCurrent() { - glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0); + if (m_isPBufferCurrent) + glXMakeContextCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0, 0); + else + glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0); + m_isPBufferCurrent = false; } void QGLXContext::swapBuffers(QPlatformSurface *surface) { - GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window(); + GLXDrawable glxDrawable = 0; + if (surface->surface()->surfaceClass() == QSurface::Offscreen) + glxDrawable = static_cast<QGLXPbuffer *>(surface)->pbuffer(); + else + glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window(); glXSwapBuffers(DISPLAY_FROM_XCB(m_screen), glxDrawable); } @@ -350,4 +405,36 @@ bool QGLXContext::isValid() const return m_context != 0; } + +QGLXPbuffer::QGLXPbuffer(QOffscreenSurface *offscreenSurface) + : QPlatformOffscreenSurface(offscreenSurface) + , m_format(offscreenSurface->requestedFormat()) + , m_screen(static_cast<QXcbScreen *>(offscreenSurface->screen()->handle())) + , m_pbuffer(0) +{ + GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), m_format); + + if (config) { + const int attributes[] = { + GLX_PBUFFER_WIDTH, offscreenSurface->size().width(), + GLX_PBUFFER_HEIGHT, offscreenSurface->size().height(), + GLX_LARGEST_PBUFFER, False, + GLX_PRESERVED_CONTENTS, False, + GLX_NONE + }; + + m_pbuffer = glXCreatePbuffer(DISPLAY_FROM_XCB(m_screen), config, attributes); + + if (m_pbuffer) + qglx_surfaceFormatFromGLXFBConfig(&m_format, DISPLAY_FROM_XCB(m_screen), config); + } +} + +QGLXPbuffer::~QGLXPbuffer() +{ + if (m_pbuffer) + glXDestroyPbuffer(DISPLAY_FROM_XCB(m_screen), m_pbuffer); +} + + QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qglxintegration.h b/src/plugins/platforms/xcb/qglxintegration.h index 98aee78b14..7116b2389d 100644 --- a/src/plugins/platforms/xcb/qglxintegration.h +++ b/src/plugins/platforms/xcb/qglxintegration.h @@ -46,6 +46,7 @@ #include "qxcbscreen.h" #include <qpa/qplatformopenglcontext.h> +#include <qpa/qplatformoffscreensurface.h> #include <QtGui/QSurfaceFormat> #include <QtCore/QMutex> @@ -76,6 +77,25 @@ private: GLXContext m_context; GLXContext m_shareContext; QSurfaceFormat m_format; + bool m_isPBufferCurrent; +}; + + +class QGLXPbuffer : public QPlatformOffscreenSurface +{ +public: + explicit QGLXPbuffer(QOffscreenSurface *offscreenSurface); + ~QGLXPbuffer(); + + QSurfaceFormat format() const { return m_format; } + bool isValid() const { return m_pbuffer != 0; } + + GLXPbuffer pbuffer() const { return m_pbuffer; } + +private: + QSurfaceFormat m_format; + QXcbScreen *m_screen; + GLXPbuffer m_pbuffer; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 4525cb8ccb..1504bd99d2 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -184,7 +184,7 @@ void QXcbConnection::updateScreens() activeScreens << screen; ++screenNumber; if (!primaryScreen && primary) { - if (primary->output == XCB_NONE || outputs[i] == primary->output) { + if (m_primaryScreen == xcbScreenNumber && (primary->output == XCB_NONE || outputs[i] == primary->output)) { primaryScreen = screen; siblings.prepend(siblings.takeLast()); #ifdef Q_XCB_DEBUG @@ -1066,7 +1066,7 @@ void QXcbConnection::processXcbEvents() while (it != m_peekFuncs.end()) { // These callbacks return true if the event is what they were // waiting for, remove them from the list in that case. - if ((*it)(event)) + if ((*it)(this, event)) it = m_peekFuncs.erase(it); else ++it; @@ -1086,7 +1086,7 @@ void QXcbConnection::processXcbEvents() // Indicate with a null event that the event the callbacks are waiting for // is not in the queue currently. Q_FOREACH (PeekFunc f, m_peekFuncs) - f(0); + f(this, 0); m_peekFuncs.clear(); xcb_flush(xcb_connection()); diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index b499f75b78..f69a8a9f35 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -364,7 +364,7 @@ public: template<typename T> inline xcb_generic_event_t *checkEvent(T &checker); - typedef bool (*PeekFunc)(xcb_generic_event_t *); + typedef bool (*PeekFunc)(QXcbConnection *, xcb_generic_event_t *); void addPeekFunc(PeekFunc f); inline xcb_timestamp_t time() const { return m_time; } diff --git a/src/plugins/platforms/xcb/qxcbcursor.cpp b/src/plugins/platforms/xcb/qxcbcursor.cpp index e29b21c9c8..ff40c6a9ab 100644 --- a/src/plugins/platforms/xcb/qxcbcursor.cpp +++ b/src/plugins/platforms/xcb/qxcbcursor.cpp @@ -287,8 +287,14 @@ QXcbCursor::QXcbCursor(QXcbConnection *conn, QXcbScreen *screen) QXcbCursor::~QXcbCursor() { + xcb_connection_t *conn = xcb_connection(); if (!--cursorCount) - xcb_close_font(xcb_connection(), cursorFont); + xcb_close_font(conn, cursorFont); + + foreach (xcb_cursor_t cursor, m_bitmapCursorMap) + xcb_free_cursor(conn, cursor); + foreach (xcb_cursor_t cursor, m_shapeCursorMap) + xcb_free_cursor(conn, cursor); } #ifndef QT_NO_CURSOR @@ -300,18 +306,20 @@ void QXcbCursor::changeCursor(QCursor *cursor, QWindow *widget) else // No X11 cursor control when there is no widget under the cursor return; - - xcb_cursor_t c; - if (cursor->shape() == Qt::BitmapCursor) { - qint64 id = cursor->pixmap().cacheKey(); - if (!m_bitmapCursorMap.contains(id)) - m_bitmapCursorMap.insert(id, createBitmapCursor(cursor)); - c = m_bitmapCursorMap.value(id); - } else { - int id = cursor->shape(); - if (!m_shapeCursorMap.contains(id)) - m_shapeCursorMap.insert(id, createFontCursor(cursor->shape())); - c = m_shapeCursorMap.value(id); + + xcb_cursor_t c = XCB_CURSOR_NONE; + if (cursor) { + if (cursor->shape() == Qt::BitmapCursor) { + qint64 id = cursor->pixmap().cacheKey(); + if (!m_bitmapCursorMap.contains(id)) + m_bitmapCursorMap.insert(id, createBitmapCursor(cursor)); + c = m_bitmapCursorMap.value(id); + } else { + int id = cursor->shape(); + if (!m_shapeCursorMap.contains(id)) + m_shapeCursorMap.insert(id, createFontCursor(cursor->shape())); + c = m_shapeCursorMap.value(id); + } } w->setCursor(c); diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 60acf1ff02..f0cabea43d 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -78,10 +78,12 @@ #elif defined(XCB_USE_EGL) #include "qxcbeglsurface.h" #include <QtPlatformSupport/private/qeglplatformcontext_p.h> +#include <QtPlatformSupport/private/qeglpbuffer_p.h> #endif #include <QtGui/QOpenGLContext> #include <QtGui/QScreen> +#include <QtGui/QOffscreenSurface> #ifndef QT_NO_ACCESSIBILITY #include <qpa/qplatformaccessibility.h> #ifndef QT_NO_ACCESSIBILITY_ATSPI_BRIDGE @@ -165,7 +167,10 @@ public: EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) { - return static_cast<QXcbWindow *>(surface)->eglSurface()->surface(); + if (surface->surface()->surfaceClass() == QSurface::Window) + return static_cast<QXcbWindow *>(surface)->eglSurface()->surface(); + else + return static_cast<QEGLPbuffer *>(surface)->pbuffer(); } private: @@ -195,6 +200,20 @@ QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *wind return new QXcbBackingStore(window); } +QPlatformOffscreenSurface *QXcbIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const +{ +#if defined(XCB_USE_GLX) + return new QGLXPbuffer(surface); +#elif defined(XCB_USE_EGL) + QXcbScreen *screen = static_cast<QXcbScreen *>(surface->screen()->handle()); + return new QEGLPbuffer(screen->connection()->egl_display(), surface->requestedFormat(), surface); +#else + Q_UNUSED(surface); + qWarning("QXcbIntegration: Cannot create platform offscreen surface, neither GLX nor EGL are enabled"); + return 0; +#endif +} + bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const { switch (cap) { @@ -209,6 +228,7 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const case ThreadedOpenGL: return m_connections.at(0)->supportsThreadedRendering(); case WindowMasks: return true; case MultipleWindows: return true; + case ForeignWindows: return true; default: return QPlatformIntegration::hasCapability(cap); } } diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h index 1dd8d4576b..6db9d82cca 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.h +++ b/src/plugins/platforms/xcb/qxcbintegration.h @@ -64,6 +64,8 @@ public: #endif QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; + QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const; + bool hasCapability(Capability cap) const; QAbstractEventDispatcher *guiThreadEventDispatcher() const; diff --git a/src/plugins/platforms/xcb/qxcbkeyboard.cpp b/src/plugins/platforms/xcb/qxcbkeyboard.cpp index bda54b4682..4ac60f6077 100644 --- a/src/plugins/platforms/xcb/qxcbkeyboard.cpp +++ b/src/plugins/platforms/xcb/qxcbkeyboard.cpp @@ -1081,6 +1081,7 @@ void QXcbKeyboard::handleKeyEvent(QWindow *window, QEvent::Type type, xcb_keycod int qtcode = 0; int count = chars.count(); QString string = translateKeySym(sym, state, qtcode, modifiers, chars, count); + string.truncate(count); bool isAutoRepeat = false; @@ -1102,7 +1103,7 @@ void QXcbKeyboard::handleKeyEvent(QWindow *window, QEvent::Type type, xcb_keycod bool filtered = false; if (inputContext) { - QKeyEvent event(type, qtcode, modifiers, code, sym, state, string.left(count), isAutoRepeat, count); + QKeyEvent event(type, qtcode, modifiers, code, sym, state, string, isAutoRepeat, count); event.setTimestamp(time); filtered = inputContext->filterEvent(&event); } @@ -1114,7 +1115,7 @@ void QXcbKeyboard::handleKeyEvent(QWindow *window, QEvent::Type type, xcb_keycod QWindowSystemInterface::handleContextMenuEvent(window, false, pos, globalPos, modifiers); } QWindowSystemInterface::handleExtendedKeyEvent(window, time, type, qtcode, modifiers, - code, sym, state, string.left(count), isAutoRepeat); + code, sym, state, string, isAutoRepeat); } if (isAutoRepeat && type == QEvent::KeyRelease) { @@ -1130,13 +1131,13 @@ void QXcbKeyboard::handleKeyEvent(QWindow *window, QEvent::Type type, xcb_keycod } if (!filtered && inputContext) { - QKeyEvent event(QEvent::KeyPress, qtcode, modifiers, code, sym, state, string.left(count), isAutoRepeat, count); + QKeyEvent event(QEvent::KeyPress, qtcode, modifiers, code, sym, state, string, isAutoRepeat, count); event.setTimestamp(time); filtered = inputContext->filterEvent(&event); } if (!filtered) QWindowSystemInterface::handleExtendedKeyEvent(window, time, QEvent::KeyPress, qtcode, modifiers, - code, sym, state, string.left(count), isAutoRepeat); + code, sym, state, string, isAutoRepeat); } } diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 11ce1126ae..5af6a9ec9d 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -122,6 +122,36 @@ enum { QT_BEGIN_NAMESPACE +#undef FocusIn + +enum QX11EmbedFocusInDetail { + XEMBED_FOCUS_CURRENT = 0, + XEMBED_FOCUS_FIRST = 1, + XEMBED_FOCUS_LAST = 2 +}; + +enum QX11EmbedInfoFlags { + XEMBED_MAPPED = (1 << 0), +}; + +enum QX11EmbedMessageType { + XEMBED_EMBEDDED_NOTIFY = 0, + XEMBED_WINDOW_ACTIVATE = 1, + XEMBED_WINDOW_DEACTIVATE = 2, + XEMBED_REQUEST_FOCUS = 3, + XEMBED_FOCUS_IN = 4, + XEMBED_FOCUS_OUT = 5, + XEMBED_FOCUS_NEXT = 6, + XEMBED_FOCUS_PREV = 7, + XEMBED_MODALITY_ON = 10, + XEMBED_MODALITY_OFF = 11, + XEMBED_REGISTER_ACCELERATOR = 12, + XEMBED_UNREGISTER_ACCELERATOR = 13, + XEMBED_ACTIVATE_ACCELERATOR = 14 +}; + +static unsigned int XEMBED_VERSION = 0; + // Returns true if we should set WM_TRANSIENT_FOR on \a w static inline bool isTransient(const QWindow *w) { @@ -158,6 +188,7 @@ QXcbWindow::QXcbWindow(QWindow *window) , m_transparent(false) , m_usingSyncProtocol(false) , m_deferredActivation(false) + , m_embedded(false) , m_netWmUserTimeWindow(XCB_NONE) , m_dirtyFrameMargins(false) #if defined(XCB_USE_EGL) @@ -169,7 +200,10 @@ QXcbWindow::QXcbWindow(QWindow *window) setConnection(m_screen->connection()); - create(); + if (window->type() != Qt::ForeignWindow) + create(); + else + m_window = window->winId(); } void QXcbWindow::create() @@ -236,8 +270,10 @@ void QXcbWindow::create() } xcb_window_t xcb_parent_id = m_screen->root(); - if (parent()) + if (parent()) { xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window(); + m_embedded = parent()->window()->type() == Qt::ForeignWindow; + } m_format = window()->requestedFormat(); @@ -371,6 +407,14 @@ void QXcbWindow::create() atom(QXcbAtom::WM_CLIENT_LEADER), XCB_ATOM_WINDOW, 32, 1, &leader)); + /* Add XEMBED info; this operation doesn't initiate the embedding. */ + long data[] = { XEMBED_VERSION, XEMBED_MAPPED }; + Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, + atom(QXcbAtom::_XEMBED_INFO), + atom(QXcbAtom::_XEMBED_INFO), + 32, 2, (void *)data)); + + #ifdef XCB_USE_XINPUT2_MAEMO if (connection()->isUsingXInput2Maemo()) { XIEventMask xieventmask; @@ -413,7 +457,8 @@ void QXcbWindow::create() QXcbWindow::~QXcbWindow() { - destroy(); + if (window()->type() != Qt::ForeignWindow) + destroy(); } void QXcbWindow::destroy() @@ -577,9 +622,10 @@ void QXcbWindow::show() propagateSizeHints(); // update WM_TRANSIENT_FOR - if (isTransient(window())) { + const QWindow *tp = window()->transientParent(); + if (isTransient(window()) || tp != 0) { xcb_window_t transientXcbParent = 0; - if (const QWindow *tp = window()->transientParent()) + if (tp) transientXcbParent = static_cast<const QXcbWindow *>(tp->handle())->winId(); // Default to client leader if there is no transient parent, else modal dialogs can // be hidden by their parents. @@ -1143,7 +1189,15 @@ void QXcbWindow::setParent(const QPlatformWindow *parent) { QPoint topLeft = geometry().topLeft(); - xcb_window_t xcb_parent_id = parent ? static_cast<const QXcbWindow *>(parent)->xcb_window() : m_screen->root(); + xcb_window_t xcb_parent_id; + if (parent) { + const QXcbWindow *qXcbParent = static_cast<const QXcbWindow *>(parent); + xcb_parent_id = qXcbParent->xcb_window(); + m_embedded = qXcbParent->window()->type() == Qt::ForeignWindow; + } else { + xcb_parent_id = m_screen->root(); + m_embedded = false; + } Q_XCB_CALL(xcb_reparent_window(xcb_connection(), xcb_window(), xcb_parent_id, topLeft.x(), topLeft.y())); } @@ -1274,6 +1328,13 @@ void QXcbWindow::propagateSizeHints() void QXcbWindow::requestActivateWindow() { + /* Never activate embedded windows; doing that would prevent the container + * to re-gain the keyboard focus later. */ + if (m_embedded) { + QPlatformWindow::requestActivateWindow(); + return; + } + if (!m_mapped) { m_deferredActivation = true; return; @@ -1437,7 +1498,8 @@ void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *even } else if (event->type == atom(QXcbAtom::XdndDrop)) { connection()->drag()->handleDrop(window(), event); #endif - } else if (event->type == atom(QXcbAtom::_XEMBED)) { // QSystemTrayIcon + } else if (event->type == atom(QXcbAtom::_XEMBED)) { + handleXEmbedMessage(event); } else { qWarning() << "QXcbWindow: Unhandled client message:" << connection()->atomName(event->type); } @@ -1479,6 +1541,53 @@ bool QXcbWindow::isExposed() const return m_mapped; } +bool QXcbWindow::isEmbedded(const QPlatformWindow *parentWindow) const +{ + if (!m_embedded) + return false; + + return parentWindow ? (parentWindow == parent()) : true; +} + +QPoint QXcbWindow::mapToGlobal(const QPoint &pos) const +{ + if (!m_embedded) + return pos; + + QPoint ret; + xcb_translate_coordinates_cookie_t cookie = + xcb_translate_coordinates(xcb_connection(), xcb_window(), m_screen->root(), + pos.x(), pos.y()); + xcb_translate_coordinates_reply_t *reply = + xcb_translate_coordinates_reply(xcb_connection(), cookie, NULL); + if (reply) { + ret.setX(reply->dst_x); + ret.setY(reply->dst_y); + free(reply); + } + + return ret; +} + +QPoint QXcbWindow::mapFromGlobal(const QPoint &pos) const +{ + if (!m_embedded) + return pos; + QPoint ret; + xcb_translate_coordinates_cookie_t cookie = + xcb_translate_coordinates(xcb_connection(), m_screen->root(), xcb_window(), + pos.x(), pos.y()); + xcb_translate_coordinates_reply_t *reply = + xcb_translate_coordinates_reply(xcb_connection(), cookie, NULL); + if (reply) { + ret.setX(reply->dst_x); + ret.setY(reply->dst_y); + free(reply); + } + + return ret; +} + void QXcbWindow::handleMapNotifyEvent(const xcb_map_notify_event_t *event) { if (event->window == m_window) { @@ -1509,6 +1618,15 @@ void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event) updateNetWmUserTime(event->time); + if (m_embedded) { + if (window() != QGuiApplication::focusWindow()) { + const QXcbWindow *container = static_cast<const QXcbWindow *>(parent()); + Q_ASSERT(container != 0); + + sendXEmbedMessage(container->xcb_window(), XEMBED_REQUEST_FOCUS); + } + } + QPoint local(event->event_x, event->event_y); QPoint global(event->root_x, event->root_y); @@ -1664,6 +1782,7 @@ void QXcbWindow::handlePropertyNotifyEvent(const xcb_property_notify_event_t *ev QWindowSystemInterface::handleWindowStateChanged(window(), newState); m_lastWindowStateEvent = newState; } + return; } } @@ -1675,7 +1794,7 @@ void QXcbWindow::handleFocusInEvent(const xcb_focus_in_event_t *) QWindowSystemInterface::handleWindowActivated(w); } -static bool focusInPeeker(xcb_generic_event_t *event) +static bool focusInPeeker(QXcbConnection *connection, xcb_generic_event_t *event) { if (!event) { // FocusIn event is not in the queue, proceed with FocusOut normally. @@ -1683,7 +1802,18 @@ static bool focusInPeeker(xcb_generic_event_t *event) return true; } uint response_type = event->response_type & ~0x80; - return response_type == XCB_FOCUS_IN; + if (response_type == XCB_FOCUS_IN) + return true; + + /* We are also interested in XEMBED_FOCUS_IN events */ + if (response_type == XCB_CLIENT_MESSAGE) { + xcb_client_message_event_t *cme = (xcb_client_message_event_t *)event; + if (cme->type == connection->atom(QXcbAtom::_XEMBED) + && cme->data.data32[1] == XEMBED_FOCUS_IN) + return true; + } + + return false; } void QXcbWindow::handleFocusOutEvent(const xcb_focus_out_event_t *) @@ -1747,6 +1877,35 @@ void QXcbWindow::setCursor(xcb_cursor_t cursor) xcb_flush(xcb_connection()); } +void QXcbWindow::windowEvent(QEvent *event) +{ + switch (event->type()) { + case QEvent::FocusIn: + if (m_embedded && !event->spontaneous()) { + QFocusEvent *focusEvent = static_cast<QFocusEvent *>(event); + switch (focusEvent->reason()) { + case Qt::TabFocusReason: + case Qt::BacktabFocusReason: + { + const QXcbWindow *container = + static_cast<const QXcbWindow *>(parent()); + sendXEmbedMessage(container->xcb_window(), + focusEvent->reason() == Qt::TabFocusReason ? + XEMBED_FOCUS_NEXT : XEMBED_FOCUS_PREV); + event->accept(); + } + break; + default: + break; + } + } + break; + default: + break; + } + QPlatformWindow::windowEvent(event); +} + bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner) { const xcb_atom_t moveResize = connection()->atom(QXcbAtom::_NET_WM_MOVERESIZE); @@ -1775,6 +1934,71 @@ bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner) return true; } +// Sends an XEmbed message. +void QXcbWindow::sendXEmbedMessage(xcb_window_t window, long message, + long detail, long data1, long data2) +{ + xcb_client_message_event_t event; + + event.response_type = XCB_CLIENT_MESSAGE; + event.format = 32; + event.window = window; + event.type = atom(QXcbAtom::_XEMBED); + event.data.data32[0] = connection()->time(); + event.data.data32[1] = message; + event.data.data32[2] = detail; + event.data.data32[3] = data1; + event.data.data32[4] = data2; + Q_XCB_CALL(xcb_send_event(xcb_connection(), false, window, + XCB_EVENT_MASK_NO_EVENT, (const char *)&event)); +} + +static bool activeWindowChangeQueued(const QWindow *window) +{ + /* Check from window system event queue if the next queued activation + * targets a window other than @window. + */ + QWindowSystemInterfacePrivate::ActivatedWindowEvent *systemEvent = + static_cast<QWindowSystemInterfacePrivate::ActivatedWindowEvent *> + (QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::ActivatedWindow)); + return systemEvent && systemEvent->activated != window; +} + +void QXcbWindow::handleXEmbedMessage(const xcb_client_message_event_t *event) +{ + connection()->setTime(event->data.data32[0]); + switch (event->data.data32[1]) { + case XEMBED_WINDOW_ACTIVATE: + case XEMBED_WINDOW_DEACTIVATE: + case XEMBED_EMBEDDED_NOTIFY: + break; + case XEMBED_FOCUS_IN: + Qt::FocusReason reason; + switch (event->data.data32[2]) { + case XEMBED_FOCUS_FIRST: + reason = Qt::TabFocusReason; + break; + case XEMBED_FOCUS_LAST: + reason = Qt::BacktabFocusReason; + break; + case XEMBED_FOCUS_CURRENT: + default: + reason = Qt::OtherFocusReason; + break; + } + connection()->setFocusWindow(static_cast<QXcbWindow*>(window()->handle())); + QWindowSystemInterface::handleWindowActivated(window(), reason); + break; + case XEMBED_FOCUS_OUT: + if (window() == QGuiApplication::focusWindow() + && !activeWindowChangeQueued(window())) { + connection()->setFocusWindow(0); + QWindowSystemInterface::handleWindowActivated(0); + } + break; + } +} + #if !defined(QT_NO_SHAPE) static inline xcb_rectangle_t qRectToXCBRectangle(const QRect &r) diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index 6a8b98ff0d..f4bd2d96ff 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -87,6 +87,9 @@ public: void setParent(const QPlatformWindow *window); bool isExposed() const; + bool isEmbedded(const QPlatformWindow *parentWindow) const; + QPoint mapToGlobal(const QPoint &pos) const; + QPoint mapFromGlobal(const QPoint &pos) const; void setWindowTitle(const QString &title); void setWindowIcon(const QIcon &icon); @@ -107,6 +110,8 @@ public: QSurfaceFormat format() const; + void windowEvent(QEvent *event); + bool startSystemResize(const QPoint &pos, Qt::Corner corner); void setOpacity(qreal level); @@ -158,6 +163,9 @@ private: void updateDoesNotAcceptFocus(bool doesNotAcceptFocus); QRect windowToWmGeometry(QRect r) const; + void sendXEmbedMessage(xcb_window_t window, long message, + long detail = 0, long data1 = 0, long data2 = 0); + void handleXEmbedMessage(const xcb_client_message_event_t *event); void create(); void destroy(); @@ -185,6 +193,7 @@ private: bool m_deferredActivation; bool m_deferredExpose; bool m_configureNotifyPending; + bool m_embedded; xcb_window_t m_netWmUserTimeWindow; QSurfaceFormat m_format; |