From c3da77798b876716ce038a30e9aa8517ec158c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 21 Jul 2011 13:50:28 +0200 Subject: Added workable QScreen API on top of QPlatformScreen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QPlatformIntegration::screens() no longer has to be implemented, implementations should call QPlatformIntegration::screenAdded() for each screen instead. This is for being able to support adding screens at run-time later on, by connecting it to a signal in QGuiApplication. The QGuiGLContext API has changed a bit, by not sending in all the parameters in the constructor but instead having a create() function. The createPlatformGLContext() factory in QPlatformIntegration takes a QGuiGLContext * instead of a QSurfaceFormat and a share context, similar to how the window and backing store factory functions work. The XCB plugin has experimental support for connecting to multiple X displays simultaneously, creating one or more QScreen for each. Change-Id: I248a22a4fd3481280710110272c04a30a8021e8f Reviewed-on: http://codereview.qt.nokia.com/2103 Reviewed-by: Qt Sanity Bot Reviewed-by: Jørgen Lind --- examples/opengl/hellowindow/hellowindow.cpp | 4 +- examples/qpa/windows/main.cpp | 12 ++ examples/qpa/windows/window.cpp | 34 +++- examples/qpa/windows/window.h | 6 + src/gui/image/qbitmap.cpp | 1 + src/gui/image/qnativeimage.cpp | 3 +- src/gui/image/qpixmap_blitter.cpp | 3 +- src/gui/image/qpixmap_qpa.cpp | 3 +- src/gui/kernel/kernel.pri | 2 + src/gui/kernel/qdnd_p.h | 2 +- src/gui/kernel/qguiapplication.cpp | 27 ++- src/gui/kernel/qguiapplication.h | 5 + src/gui/kernel/qguiapplication_p.h | 1 + src/gui/kernel/qguiglcontext_qpa.cpp | 85 +++++++- src/gui/kernel/qguiglcontext_qpa.h | 18 +- src/gui/kernel/qplatformintegration_qpa.cpp | 59 +++--- src/gui/kernel/qplatformintegration_qpa.h | 15 +- src/gui/kernel/qplatformscreen_qpa.cpp | 63 +++++- src/gui/kernel/qplatformscreen_qpa.h | 33 +++- src/gui/kernel/qscreen.h | 95 +++++++++ src/gui/kernel/qwindow.cpp | 34 +++- src/gui/kernel/qwindow.h | 7 +- src/gui/kernel/qwindow_p.h | 2 + src/gui/painting/qbackingstore.cpp | 1 + src/gui/painting/qcolormap_qpa.cpp | 7 +- src/gui/text/qfont.cpp | 15 +- src/opengl/qgl_qpa.cpp | 13 +- .../eventdispatchers/qeventdispatcher_qpa.cpp | 2 - src/plugins/platforms/cocoa/qcocoaintegration.h | 6 +- src/plugins/platforms/cocoa/qcocoaintegration.mm | 12 +- .../platforms/minimal/qminimalbackingstore.cpp | 3 +- .../platforms/minimal/qminimalintegration.cpp | 7 +- .../platforms/minimal/qminimalintegration.h | 9 +- .../platforms/wayland/qwaylandintegration.cpp | 7 - .../platforms/wayland/qwaylandintegration.h | 1 - .../platforms/wayland/qwaylandnativeinterface.cpp | 5 +- src/plugins/platforms/wayland/qwaylandscreen.cpp | 1 - src/plugins/platforms/xcb/main.cpp | 5 +- src/plugins/platforms/xcb/qxcbbackingstore.cpp | 5 +- src/plugins/platforms/xcb/qxcbconnection.cpp | 5 +- src/plugins/platforms/xcb/qxcbintegration.cpp | 217 ++++----------------- src/plugins/platforms/xcb/qxcbintegration.h | 15 +- src/plugins/platforms/xcb/qxcbnativeinterface.cpp | 7 +- src/plugins/platforms/xcb/qxcbscreen.cpp | 125 ++++++++++++ src/plugins/platforms/xcb/qxcbscreen.h | 4 + src/plugins/platforms/xcb/qxcbwindow.cpp | 3 +- src/widgets/kernel/qapplication_qpa.cpp | 17 +- src/widgets/kernel/qdesktopwidget_qpa.cpp | 23 +-- src/widgets/kernel/qwidget.cpp | 3 +- src/widgets/kernel/qwidget_qpa.cpp | 5 +- 50 files changed, 673 insertions(+), 364 deletions(-) create mode 100644 src/gui/kernel/qscreen.h diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index 9575d3e3c7..5a232e6a7b 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -12,7 +12,9 @@ Renderer::Renderer() m_format.setDepthBufferSize(16); m_format.setSamples(4); - m_context = new QGuiGLContext(m_format); + m_context = new QGuiGLContext; + m_context->setFormat(m_format); + m_context->create(); } QSurfaceFormat Renderer::format() const diff --git a/examples/qpa/windows/main.cpp b/examples/qpa/windows/main.cpp index 99c24fa017..e4cd14398c 100644 --- a/examples/qpa/windows/main.cpp +++ b/examples/qpa/windows/main.cpp @@ -1,4 +1,5 @@ #include +#include #include "window.h" @@ -15,5 +16,16 @@ int main(int argc, char **argv) Window child(&b); child.setVisible(true); + // create one window on each additional screen as well + + QList screens = app.screens(); + foreach (QScreen *screen, screens) { + if (screen == app.primaryScreen()) + continue; + Window *window = new Window(screen); + window->setVisible(true); + window->setWindowTitle(screen->name()); + } + return app.exec(); } diff --git a/examples/qpa/windows/window.cpp b/examples/qpa/windows/window.cpp index bbfc6a3116..fecc22034a 100644 --- a/examples/qpa/windows/window.cpp +++ b/examples/qpa/windows/window.cpp @@ -14,13 +14,23 @@ QColor colorTable[] = QColor("#c0ef8f") }; +Window::Window(QScreen *screen) + : QWindow(screen) + , m_backgroundColorIndex(colorIndexId++) +{ + initialize(); +} + Window::Window(QWindow *parent) : QWindow(parent) , m_backgroundColorIndex(colorIndexId++) { - setWindowTitle(QLatin1String("Window")); + initialize(); +} - if (parent) +void Window::initialize() +{ + if (parent()) setGeometry(QRect(160, 120, 320, 240)); else { setGeometry(QRect(10, 10, 640, 480)); @@ -38,6 +48,7 @@ Window::Window(QWindow *parent) m_image.fill(colorTable[m_backgroundColorIndex % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba()); m_lastPos = QPoint(-1, -1); + m_renderTimer = 0; } void Window::mousePressEvent(QMouseEvent *event) @@ -54,7 +65,7 @@ void Window::mouseMoveEvent(QMouseEvent *event) m_lastPos = event->pos(); } - render(); + scheduleRender(); } void Window::mouseReleaseEvent(QMouseEvent *event) @@ -66,12 +77,12 @@ void Window::mouseReleaseEvent(QMouseEvent *event) m_lastPos = QPoint(-1, -1); } - render(); + scheduleRender(); } void Window::exposeEvent(QExposeEvent *) { - render(); + scheduleRender(); } void Window::resizeEvent(QResizeEvent *) @@ -106,7 +117,20 @@ void Window::keyPressEvent(QKeyEvent *event) m_text.append(event->text()); break; } + scheduleRender(); +} + +void Window::scheduleRender() +{ + if (!m_renderTimer) + m_renderTimer = startTimer(1); +} + +void Window::timerEvent(QTimerEvent *) +{ render(); + killTimer(m_renderTimer); + m_renderTimer = 0; } void Window::render() diff --git a/examples/qpa/windows/window.h b/examples/qpa/windows/window.h index 546cf67bce..bf664d148e 100644 --- a/examples/qpa/windows/window.h +++ b/examples/qpa/windows/window.h @@ -5,6 +5,7 @@ class Window : public QWindow { public: Window(QWindow *parent = 0); + Window(QScreen *screen); protected: void mousePressEvent(QMouseEvent *); @@ -16,12 +17,17 @@ protected: void exposeEvent(QExposeEvent *); void resizeEvent(QResizeEvent *); + void timerEvent(QTimerEvent *); + private: void render(); + void scheduleRender(); + void initialize(); QString m_text; QImage m_image; QPoint m_lastPos; int m_backgroundColorIndex; QBackingStore *m_backingStore; + int m_renderTimer; }; diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp index c614ba1b0a..f32c517f17 100644 --- a/src/gui/image/qbitmap.cpp +++ b/src/gui/image/qbitmap.cpp @@ -42,6 +42,7 @@ #include "qbitmap.h" #include "qplatformpixmap_qpa.h" #include "qimage.h" +#include "qscreen.h" #include "qvariant.h" #include #include diff --git a/src/gui/image/qnativeimage.cpp b/src/gui/image/qnativeimage.cpp index 64104a658e..d0f6c4c7d6 100644 --- a/src/gui/image/qnativeimage.cpp +++ b/src/gui/image/qnativeimage.cpp @@ -42,6 +42,7 @@ #include #include "qnativeimage_p.h" #include "qcolormap.h" +#include "qscreen.h" #include "private/qpaintengine_raster_p.h" @@ -207,7 +208,7 @@ QNativeImage::~QNativeImage() QImage::Format QNativeImage::systemFormat() { - return QGuiApplicationPrivate::platformIntegration()->screens().at(0)->format(); + return QGuiApplication::primaryScreen()->handle()->format(); } #endif // platforms diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp index 43876419d4..dc0f03abdc 100644 --- a/src/gui/image/qpixmap_blitter.cpp +++ b/src/gui/image/qpixmap_blitter.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -98,7 +99,7 @@ void QBlittablePlatformPixmap::resize(int width, int height) delete m_engine; m_engine = 0; #ifdef Q_WS_QPA - d = QGuiApplicationPrivate::platformIntegration()->screens().at(0)->depth(); + d = QGuiApplication::primaryScreen()->depth(); #endif w = width; h = height; diff --git a/src/gui/image/qpixmap_qpa.cpp b/src/gui/image/qpixmap_qpa.cpp index 724647f89d..9c69ddef7e 100644 --- a/src/gui/image/qpixmap_qpa.cpp +++ b/src/gui/image/qpixmap_qpa.cpp @@ -40,9 +40,10 @@ ****************************************************************************/ #include +#include #include QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h) { - return QGuiApplicationPrivate::platformIntegration()->grabWindow(window, x, y, w, h); + return QGuiApplication::primaryScreen()->handle()->grabWindow(window, x, y, w, h); } diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 7f9434e9b4..58291f5237 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -20,6 +20,7 @@ HEADERS += \ kernel/qpalette.h \ kernel/qsessionmanager.h \ kernel/qwindowdefs.h \ + kernel/qscreen.h SOURCES += \ kernel/qclipboard.cpp \ @@ -33,6 +34,7 @@ SOURCES += \ kernel/qmime.cpp \ kernel/qpalette.cpp \ kernel/qguivariant.cpp \ + kernel/qscreen.cpp qpa { HEADERS += \ diff --git a/src/gui/kernel/qdnd_p.h b/src/gui/kernel/qdnd_p.h index 2eebcf6158..7159acf594 100644 --- a/src/gui/kernel/qdnd_p.h +++ b/src/gui/kernel/qdnd_p.h @@ -113,7 +113,7 @@ class QShapedPixmapWindow : public QWindow { QPixmap pixmap; public: QShapedPixmapWindow() : - QWindow(0) + QWindow() { setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); // ### Should we set the surface type to raster? diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index ad01a72a45..a54dab6398 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -103,6 +104,8 @@ QGuiApplicationPrivate *QGuiApplicationPrivate::self = 0; QClipboard *QGuiApplicationPrivate::qt_clipboard = 0; #endif +QList QGuiApplicationPrivate::screen_list; + QWindowList QGuiApplicationPrivate::window_list; QWindow *QGuiApplicationPrivate::active_window = 0; @@ -179,21 +182,27 @@ QWindowList QGuiApplication::topLevelWindows() return QGuiApplicationPrivate::window_list; } -QWindow *QGuiApplication::topLevelAt(const QPoint &pos) +QScreen *QGuiApplication::primaryScreen() { - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); + if (QGuiApplicationPrivate::screen_list.isEmpty()) + return 0; + return QGuiApplicationPrivate::screen_list.at(0); +} - QList screens = pi->screens(); - QList::const_iterator screen = screens.constBegin(); - QList::const_iterator end = screens.constEnd(); +QList QGuiApplication::screens() +{ + return QGuiApplicationPrivate::screen_list; +} - // The first screen in a virtual environment should know about all top levels - if (pi->isVirtualDesktop()) - return (*screen)->topLevelAt(pos); +QWindow *QGuiApplication::topLevelAt(const QPoint &pos) +{ + QList screens = QGuiApplication::screens(); + QList::const_iterator screen = screens.constBegin(); + QList::const_iterator end = screens.constEnd(); while (screen != end) { if ((*screen)->geometry().contains(pos)) - return (*screen)->topLevelAt(pos); + return (*screen)->handle()->topLevelAt(pos); ++screen; } return 0; diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 4557b946a8..8338fa1f9a 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -57,6 +57,7 @@ QT_MODULE(Gui) class QGuiApplicationPrivate; class QPlatformNativeInterface; class QPalette; +class QScreen; #if defined(qApp) #undef qApp @@ -83,6 +84,8 @@ public: static QWindow *topLevelAt(const QPoint &pos); static QWindow *activeWindow(); + static QScreen *primaryScreen(); + static QList screens(); #ifndef QT_NO_CURSOR static QCursor *overrideCursor(); @@ -125,6 +128,7 @@ public: Q_SIGNALS: void fontDatabaseChanged(); + void screenAdded(QScreen *screen); protected: bool event(QEvent *); @@ -140,6 +144,7 @@ private: friend class QGestureManager; #endif friend class QFontDatabasePrivate; + friend class QPlatformIntegration; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 6d44caa35a..8391662a4a 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -162,6 +162,7 @@ public: #ifndef QT_NO_CURSOR QList cursor_list; #endif + static QList screen_list; static QFont *app_font; private: diff --git a/src/gui/kernel/qguiglcontext_qpa.cpp b/src/gui/kernel/qguiglcontext_qpa.cpp index fd827966c4..61a0479bd3 100644 --- a/src/gui/kernel/qguiglcontext_qpa.cpp +++ b/src/gui/kernel/qguiglcontext_qpa.cpp @@ -47,6 +47,7 @@ #include #include +#include #include @@ -69,6 +70,7 @@ public: : qGLContextHandle(0) , platformGLContext(0) , shareContext(0) + , screen(0) { } @@ -79,8 +81,11 @@ public: } void *qGLContextHandle; void (*qGLContextDeleteFunction)(void *handle); + + QSurfaceFormat requestedFormat; QPlatformGLContext *platformGLContext; QGuiGLContext *shareContext; + QScreen *screen; static void setCurrentContext(QGuiGLContext *context); }; @@ -117,29 +122,87 @@ QPlatformGLContext *QGuiGLContext::handle() const return d->platformGLContext; } +QPlatformGLContext *QGuiGLContext::shareHandle() const +{ + Q_D(const QGuiGLContext); + if (d->shareContext) + return d->shareContext->handle(); + return 0; +} + /*! - Creates a new GL context with the given format and shared context. + Creates a new GL context instance, you need to call create() before it can be used. */ -QGuiGLContext::QGuiGLContext(const QSurfaceFormat &format, QGuiGLContext *shareContext) +QGuiGLContext::QGuiGLContext() : d_ptr(new QGuiGLContextPrivate()) { Q_D(QGuiGLContext); - QPlatformGLContext *share = shareContext ? shareContext->handle() : 0; + d->screen = QGuiApplication::primaryScreen(); +} + +/*! + Sets the format the GL context should be compatible with. You need to call create() before it takes effect. +*/ +void QGuiGLContext::setFormat(const QSurfaceFormat &format) +{ + Q_D(QGuiGLContext); + d->requestedFormat = format; +} + +/*! + Sets the context to share textures, shaders, and other GL resources with. You need to call create() before it takes effect. +*/ +void QGuiGLContext::setShareContext(QGuiGLContext *shareContext) +{ + Q_D(QGuiGLContext); d->shareContext = shareContext; - d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformGLContext(format, share); } /*! - If this is the current context for the thread, doneCurrent is called + Sets the screen the GL context should be valid for. You need to call create() before it takes effect. */ -QGuiGLContext::~QGuiGLContext() +void QGuiGLContext::setScreen(QScreen *screen) +{ + Q_D(QGuiGLContext); + d->screen = screen; + if (!d->screen) + d->screen = QGuiApplication::primaryScreen(); +} + +/*! + Attempts to create the GL context with the desired parameters. + + Returns true if the native context was successfully created and is ready to be used.d +*/ +bool QGuiGLContext::create() +{ + destroy(); + + Q_D(QGuiGLContext); + d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformGLContext(this); + return d->platformGLContext; +} + +void QGuiGLContext::destroy() { Q_D(QGuiGLContext); if (QGuiGLContext::currentContext() == this) doneCurrent(); delete d->platformGLContext; + d->platformGLContext = 0; +} + +/*! + If this is the current context for the thread, doneCurrent is called +*/ +QGuiGLContext::~QGuiGLContext() +{ + destroy(); } +/*! + Returns if this context is valid, i.e. has been successfully created. +*/ bool QGuiGLContext::isValid() const { Q_D(const QGuiGLContext); @@ -210,18 +273,22 @@ QSurfaceFormat QGuiGLContext::format() const { Q_D(const QGuiGLContext); if (!d->platformGLContext) - return QSurfaceFormat(); + return d->requestedFormat; return d->platformGLContext->format(); } QGuiGLContext *QGuiGLContext::shareContext() const { Q_D(const QGuiGLContext); - if (!d->platformGLContext) - return 0; return d->shareContext; } +QScreen *QGuiGLContext::screen() const +{ + Q_D(const QGuiGLContext); + return d->screen; +} + /* internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant have any type information. diff --git a/src/gui/kernel/qguiglcontext_qpa.h b/src/gui/kernel/qguiglcontext_qpa.h index 9e62905b68..db3d6f29e6 100644 --- a/src/gui/kernel/qguiglcontext_qpa.h +++ b/src/gui/kernel/qguiglcontext_qpa.h @@ -61,24 +61,30 @@ class Q_GUI_EXPORT QGuiGLContext { Q_DECLARE_PRIVATE(QGuiGLContext); public: - QGuiGLContext(const QSurfaceFormat &format = QSurfaceFormat(), QGuiGLContext *shareContext = 0); + QGuiGLContext(); ~QGuiGLContext(); + void setFormat(const QSurfaceFormat &format); + void setShareContext(QGuiGLContext *shareContext); + void setScreen(QScreen *screen); + + bool create(); bool isValid() const; + QSurfaceFormat format() const; + QGuiGLContext *shareContext() const; + QScreen *screen() const; + bool makeCurrent(QSurface *surface); void doneCurrent(); void swapBuffers(QSurface *surface); void (*getProcAddress(const QByteArray &procName)) (); - QSurfaceFormat format() const; - - QGuiGLContext *shareContext() const; - static QGuiGLContext *currentContext(); QPlatformGLContext *handle() const; + QPlatformGLContext *shareHandle() const; private: QScopedPointer d_ptr; @@ -91,6 +97,8 @@ private: void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)); void deleteQGLContext(); + void destroy(); + Q_DISABLE_COPY(QGuiGLContext); }; diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp index ab0d5100c3..c190c4f481 100644 --- a/src/gui/kernel/qplatformintegration_qpa.cpp +++ b/src/gui/kernel/qplatformintegration_qpa.cpp @@ -44,21 +44,12 @@ #include #include #include +#include +#include #include QT_BEGIN_NAMESPACE -QPixmap QPlatformIntegration::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(); -} - - /*! Accessor for the platform integrations fontdatabase. @@ -177,12 +168,6 @@ QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const */ -QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(const QSurfaceFormat &, QPlatformGLContext *) const -{ - qWarning("This plugin does not support createPlatformGLContext!"); - return 0; -} - /*! \fn void QPlatformIntegration::moveToScreen(QWindow *window, int screen) @@ -211,15 +196,6 @@ QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(const QSurface Default implementation returns false. */ -/*! - \fn QPixmap QPlatformIntegration::grabWindow(WId window, int x, int y, int width, int height) const - - This function is called when Qt needs to be able to grab the content of a window. - - Returnes the content of the window specified with the WId handle within the boundaries of - QRect(x,y,width,height). -*/ - /*! \fn QAbstractEventDispatcher *createEventDispatcher() const @@ -234,6 +210,17 @@ bool QPlatformIntegration::hasCapability(Capability cap) const return false; } +QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const +{ + return new QRasterPlatformPixmap(type); +} + +QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(QGuiGLContext *context) const +{ + qWarning("This plugin does not support createPlatformGLContext!"); + return 0; +} + /*! Returns the platform's printing support. @@ -261,4 +248,24 @@ QPlatformInputContext *QPlatformIntegration::inputContext() const return 0; } +/*! + Should be called by the implementation whenever a new screen is added. + + The first screen added will be the primary screen, used for default-created + windows, GL contexts, and other resources unless otherwise specified. + + This adds the screen to QGuiApplication::screens(), and emits the + QGuiApplication::screenAdded() signal. + + The screen is automatically removed when the QPlatformScreen is destroyed. +*/ +void QPlatformIntegration::screenAdded(QPlatformScreen *ps) +{ + QScreen *screen = ps ? ps->screen() : 0; + if (screen && !QGuiApplicationPrivate::screen_list.contains(screen)) { + QGuiApplicationPrivate::screen_list << screen; + emit qGuiApp->screenAdded(screen); + } +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h index 092186c160..35dfe07140 100644 --- a/src/gui/kernel/qplatformintegration_qpa.h +++ b/src/gui/kernel/qplatformintegration_qpa.h @@ -43,7 +43,6 @@ #define QPLATFORMINTEGRATION_H #include -#include #include #include @@ -78,17 +77,10 @@ public: virtual bool hasCapability(Capability cap) const; -// GraphicsSystem functions - virtual QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const = 0; + virtual QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0; virtual QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const = 0; - virtual QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &format, QPlatformGLContext *share) const; - -// Window System functions - virtual QList screens() const = 0; - virtual void moveToScreen(QWindow *window, int screen) {Q_UNUSED(window); Q_UNUSED(screen);} - virtual bool isVirtualDesktop() { return false; } - virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const; + virtual QPlatformGLContext *createPlatformGLContext(QGuiGLContext *context) const; // Event dispatcher: virtual QAbstractEventDispatcher *createEventDispatcher() const = 0; @@ -107,6 +99,9 @@ public: virtual QPlatformNativeInterface *nativeInterface() const; virtual QPlatformPrinterSupport *printerSupport() const; + +protected: + void screenAdded(QPlatformScreen *screen); }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformscreen_qpa.cpp b/src/gui/kernel/qplatformscreen_qpa.cpp index 16b2557a15..ae1c6dcf06 100644 --- a/src/gui/kernel/qplatformscreen_qpa.cpp +++ b/src/gui/kernel/qplatformscreen_qpa.cpp @@ -43,8 +43,47 @@ #include #include #include +#include #include +struct QPlatformScreenPrivate +{ + QScreen *screen; +}; + +QPlatformScreen::QPlatformScreen() + : d_ptr(new QPlatformScreenPrivate) +{ + Q_D(QPlatformScreen); + d->screen = new QScreen(this); +} + +QPlatformScreen::~QPlatformScreen() +{ + Q_D(QPlatformScreen); + + QGuiApplicationPrivate::screen_list.removeOne(d->screen); + delete d->screen; +} + +/*! + \fn QPixmap QPlatformScreen::grabWindow(WId window, int x, int y, int width, int height) const + + This function is called when Qt needs to be able to grab the content of a window. + + Returnes the content of the window specified with the WId handle within the boundaries of + QRect(x,y,width,height). +*/ +QPixmap QPlatformScreen::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(); +} + /*! Return the given top level window for a given position. @@ -63,6 +102,26 @@ QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const return 0; } +/*! + Returns a list of all the platform screens that are part of the same + virtual desktop. + + Screens part of the same virtual desktop share a common coordinate system, + and windows can be freely moved between them. +*/ +QList QPlatformScreen::virtualSiblings() const +{ + QList list; + list << const_cast(this); + return list; +} + +QScreen *QPlatformScreen::screen() const +{ + Q_D(const QPlatformScreen); + return d->screen; +} + /*! Reimplement this function in subclass to return the physical size of the screen. This function is used by QFont to convert point sizes to pixel @@ -81,9 +140,9 @@ QSize QPlatformScreen::physicalSize() const return QSize(width,height); } -QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *) +QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window) { - return QGuiApplicationPrivate::platformIntegration()->screens().at(0); + return window->screen()->handle(); } /*! diff --git a/src/gui/kernel/qplatformscreen_qpa.h b/src/gui/kernel/qplatformscreen_qpa.h index 16e62dd6c6..8d3dd4cc71 100644 --- a/src/gui/kernel/qplatformscreen_qpa.h +++ b/src/gui/kernel/qplatformscreen_qpa.h @@ -52,6 +52,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -59,24 +60,46 @@ QT_BEGIN_NAMESPACE QT_MODULE(Gui) -class Q_GUI_EXPORT QPlatformScreen : public QObject +class QPlatformBackingStore; +class QPlatformGLContext; +class QPlatformScreenPrivate; +class QPlatformWindow; +class QScreen; +class QSurfaceFormat; + +class Q_GUI_EXPORT QPlatformScreen { - Q_OBJECT + Q_DECLARE_PRIVATE(QPlatformScreen) + public: - virtual ~QPlatformScreen() { } + QPlatformScreen(); + virtual ~QPlatformScreen(); + + virtual QPixmap grabWindow(WId window, int x, int y, int width, int height) const; virtual QRect geometry() const = 0; virtual QRect availableGeometry() const {return geometry();} + virtual int depth() const = 0; virtual QImage::Format format() const = 0; virtual QSize physicalSize() const; - //jl: should setDirty be removed. - virtual void setDirty(const QRect &) {} + virtual QWindow *topLevelAt(const QPoint &point) const; + virtual QList virtualSiblings() const; + + QScreen *screen() const; //jl: should this function be in QPlatformIntegration //jl: maybe screenForWindow is a better name? static QPlatformScreen *platformScreenForWindow(const QWindow *window); + + virtual QString name() const { return QString(); } + +protected: + QScopedPointer d_ptr; + +private: + Q_DISABLE_COPY(QPlatformScreen) }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h new file mode 100644 index 0000000000..f96056e45a --- /dev/null +++ b/src/gui/kernel/qscreen.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCREEN_H +#define QSCREEN_H + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +#include + +class QPlatformScreen; +class QScreenPrivate; +class QWindow; + +class Q_GUI_EXPORT QScreen : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QScreen) + +public: + QPlatformScreen *handle() const; + + QString name() const; + + int depth() const; + + QSize size() const; + QRect geometry() const; + + QSize availableSize() const; + QRect availableGeometry() const; + + QList virtualSiblings() const; + + QSize virtualSize() const; + QRect virtualGeometry() const; + + QSize availableVirtualSize() const; + QRect availableVirtualGeometry() const; + +private: + QScreen(QPlatformScreen *screen); + + Q_DISABLE_COPY(QScreen) + friend class QPlatformScreen; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSCREEN_H + diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 7fa9316878..018474aba7 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -45,6 +45,7 @@ #include "qsurfaceformat.h" #include "qplatformglcontext_qpa.h" #include "qguiglcontext_qpa.h" +#include "qscreen.h" #include "qwindow_p.h" #include "qguiapplication_p.h" @@ -55,12 +56,27 @@ QT_BEGIN_NAMESPACE +QWindow::QWindow(QScreen *targetScreen) + : QObject(*new QWindowPrivate(), 0) + , QSurface(QSurface::Window) +{ + Q_D(QWindow); + d->screen = targetScreen; + if (!d->screen) + d->screen = QGuiApplication::primaryScreen(); + QGuiApplicationPrivate::window_list.prepend(this); +} + QWindow::QWindow(QWindow *parent) : QObject(*new QWindowPrivate(), parent) , QSurface(QSurface::Window) { Q_D(QWindow); d->parentWindow = parent; + if (parent) + d->screen = parent->screen(); + if (!d->screen) + d->screen = QGuiApplication::primaryScreen(); QGuiApplicationPrivate::window_list.prepend(this); } @@ -439,6 +455,23 @@ bool QWindow::setMouseGrabEnabled(bool grab) return false; } +QScreen *QWindow::screen() const +{ + Q_D(const QWindow); + return d->screen; +} + +void QWindow::setScreen(QScreen *newScreen) +{ + Q_D(QWindow); + bool wasCreated = d->platformWindow != 0; + if (wasCreated) + destroy(); + d->screen = newScreen ? newScreen : QGuiApplication::primaryScreen(); + if (wasCreated) + create(); +} + void QWindow::showMinimized() { qDebug() << "unimplemented:" << __FILE__ << __LINE__; @@ -486,7 +519,6 @@ void QWindow::hideEvent(QHideEvent *) bool QWindow::event(QEvent *event) { - Q_D(QWindow); switch (event->type()) { case QEvent::MouseMove: mouseMoveEvent(static_cast(event)); diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h index 67330e5291..adf948b65e 100644 --- a/src/gui/kernel/qwindow.h +++ b/src/gui/kernel/qwindow.h @@ -71,6 +71,7 @@ class QWheelEvent; class QPlatformSurface; class QPlatformWindow; class QBackingStore; +class QScreen; class Q_GUI_EXPORT QSurface { @@ -102,7 +103,8 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface public: enum SurfaceType { RasterSurface, OpenGLSurface }; - QWindow(QWindow *parent = 0); + QWindow(QScreen *screen = 0); + QWindow(QWindow *parent); virtual ~QWindow(); void setSurfaceType(SurfaceType surfaceType); @@ -166,6 +168,9 @@ public: bool setKeyboardGrabEnabled(bool grab); bool setMouseGrabEnabled(bool grab); + QScreen *screen() const; + void setScreen(QScreen *screen); + public Q_SLOTS: inline void show() { setVisible(true); } inline void hide() { setVisible(false); } diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index cca20bc30a..2016c42d7e 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -68,6 +68,7 @@ public: , maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX) , modality(Qt::NonModal) , transientParent(0) + , screen(0) { isWindow = true; } @@ -93,6 +94,7 @@ public: Qt::WindowModality modality; QPointer transientParent; + QScreen *screen; }; diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index 68dbb7d109..f69a2e4ff6 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include diff --git a/src/gui/painting/qcolormap_qpa.cpp b/src/gui/painting/qcolormap_qpa.cpp index 31fc41b94d..282841aa76 100644 --- a/src/gui/painting/qcolormap_qpa.cpp +++ b/src/gui/painting/qcolormap_qpa.cpp @@ -42,7 +42,7 @@ #include "qcolormap.h" #include "qcolor.h" #include "qpaintdevice.h" -#include "private/qguiapplication_p.h" +#include "qscreen.h" QT_BEGIN_NAMESPACE @@ -66,10 +66,7 @@ void QColormap::initialize() { screenMap = new QColormapPrivate; - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - QList screens = pi->screens(); - - screenMap->depth = screens.at(0)->depth(); + screenMap->depth = QGuiApplication::primaryScreen()->depth(); if (screenMap->depth < 8) { screenMap->mode = QColormap::Indexed; screenMap->numcolors = 256; diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index b85c045064..e8308dba06 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -50,6 +50,7 @@ #include "qdatastream.h" #include "qguiapplication.h" #include "qstringlist.h" +#include "qscreen.h" #include "qthread.h" #include "qthreadstorage.h" @@ -167,11 +168,10 @@ Q_GUI_EXPORT int qt_defaultDpiX() extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp dpi = qt_mac_defaultDpi_x(); #elif defined(Q_WS_QPA) - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - if (pi) { - QPlatformScreen *screen = pi->screens().at(0); + QScreen *screen = QGuiApplication::primaryScreen(); + if (screen) { const QSize screenSize = screen->geometry().size(); - const QSize physicalSize = screen->physicalSize(); + const QSize physicalSize = screen->handle()->physicalSize(); dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4))); } else { //PI has not been initialised, or it is being initialised. Give a default dpi @@ -198,11 +198,10 @@ Q_GUI_EXPORT int qt_defaultDpiY() extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp dpi = qt_mac_defaultDpi_y(); #elif defined(Q_WS_QPA) - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - if (pi) { - QPlatformScreen *screen = pi->screens().at(0); + QScreen *screen = QGuiApplication::primaryScreen(); + if (screen) { const QSize screenSize = screen->geometry().size(); - const QSize physicalSize = screen->physicalSize(); + const QSize physicalSize = screen->handle()->physicalSize(); dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4))); } else { //PI has not been initialised, or it is being initialised. Give a default dpi diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp index cfd651e39d..e6c135bb7f 100644 --- a/src/opengl/qgl_qpa.cpp +++ b/src/opengl/qgl_qpa.cpp @@ -150,13 +150,15 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) delete d->guiGlContext; QGuiGLContext *shareGlContext = shareContext ? shareContext->d_func()->guiGlContext : 0; - d->guiGlContext = new QGuiGLContext(winFormat, shareGlContext); + d->guiGlContext = new QGuiGLContext; + d->guiGlContext->setFormat(winFormat); + d->guiGlContext->setShareContext(shareGlContext); + d->valid = d->guiGlContext->create(); - d->glFormat = QGLFormat::fromSurfaceFormat(d->guiGlContext->format()); - d->valid = d->guiGlContext->isValid(); - if (d->valid) { + if (d->valid) d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext); - } + + d->glFormat = QGLFormat::fromSurfaceFormat(d->guiGlContext->format()); d->setupSharing(); } @@ -300,6 +302,7 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) d->window->create(); d->context = new QGuiGLContext; + d->context->create(); d->context->makeCurrent(d->window); } diff --git a/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp b/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp index bfadd8b654..d39aae7e1f 100644 --- a/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp +++ b/src/platformsupport/eventdispatchers/qeventdispatcher_qpa.cpp @@ -67,8 +67,6 @@ QEventDispatcherQPA::~QEventDispatcherQPA() bool QEventDispatcherQPA::processEvents(QEventLoop::ProcessEventsFlags flags) { - Q_D(QEventDispatcherQPA); - bool didSendEvents = QWindowSystemInterface::sendWindowSystemEvents(this, flags); if (QEventDispatcherUNIX::processEvents(flags)) { diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index a3895d0073..5a30de697e 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -76,19 +76,15 @@ public: ~QCocoaIntegration(); bool hasCapability(QPlatformIntegration::Capability cap) const; - QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; - QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const; + QPlatformGLContext *createPlatformGLContext(QGuiGLContext *context) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const; QAbstractEventDispatcher *createEventDispatcher() const; - QList screens() const { return mScreens; } - QPlatformFontDatabase *fontDatabase() const; QPlatformNativeInterface *nativeInterface() const; private: - QList mScreens; QPlatformFontDatabase *mFontDb; QCocoaAutoReleasePool *mPool; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 95794cf452..23110583c1 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -47,7 +47,6 @@ #include "qcocoaeventdispatcher.h" #include -#include QT_BEGIN_NAMESPACE @@ -83,7 +82,7 @@ QCocoaIntegration::QCocoaIntegration() NSArray *screens = [NSScreen screens]; for (uint i = 0; i < [screens count]; i++) { QCocoaScreen *screen = new QCocoaScreen(i); - mScreens.append(screen); + screenAdded(screen); } } @@ -103,19 +102,14 @@ bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) cons -QPlatformPixmap *QCocoaIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const -{ - return new QRasterPlatformPixmap(type); -} - QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWindow *window) const { return new QCocoaWindow(window); } -QPlatformGLContext *QCocoaIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const +QPlatformGLContext *QCocoaIntegration::createPlatformGLContext(QGuiGLContext *context) const { - return new QCocoaGLContext(glFormat, share); + return new QCocoaGLContext(context->format(), context->shareHandle()); } QPlatformBackingStore *QCocoaIntegration::createPlatformBackingStore(QWindow *window) const diff --git a/src/plugins/platforms/minimal/qminimalbackingstore.cpp b/src/plugins/platforms/minimal/qminimalbackingstore.cpp index bd4f04dfcd..08281405a4 100644 --- a/src/plugins/platforms/minimal/qminimalbackingstore.cpp +++ b/src/plugins/platforms/minimal/qminimalbackingstore.cpp @@ -41,6 +41,7 @@ #include "qminimalbackingstore.h" +#include "qscreen.h" #include #include @@ -77,7 +78,7 @@ void QMinimalBackingStore::flush(QWindow *window, const QRegion ®ion, const Q void QMinimalBackingStore::resize(const QSize &size, const QRegion &) { //qDebug() << "QMinimalBackingStore::setGeometry:" << (long)this << rect; - QImage::Format format = QGuiApplicationPrivate::platformIntegration()->screens().first()->format(); + QImage::Format format = QGuiApplication::primaryScreen()->handle()->format(); if (mImage.size() != size) mImage = QImage(size, format); } diff --git a/src/plugins/platforms/minimal/qminimalintegration.cpp b/src/plugins/platforms/minimal/qminimalintegration.cpp index 71bdda73aa..8d8e5e7f06 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.cpp +++ b/src/plugins/platforms/minimal/qminimalintegration.cpp @@ -58,7 +58,7 @@ QMinimalIntegration::QMinimalIntegration() mPrimaryScreen->mDepth = 32; mPrimaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; - mScreens.append(mPrimaryScreen); + screenAdded(mPrimaryScreen); } bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const @@ -69,11 +69,6 @@ bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) co } } -QPlatformPixmap *QMinimalIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const -{ - return new QRasterPlatformPixmap(type); -} - QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) const { Q_UNUSED(window); diff --git a/src/plugins/platforms/minimal/qminimalintegration.h b/src/plugins/platforms/minimal/qminimalintegration.h index 52e4c0a6f3..d64932c5e6 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.h +++ b/src/plugins/platforms/minimal/qminimalintegration.h @@ -71,15 +71,10 @@ public: bool hasCapability(QPlatformIntegration::Capability cap) const; - QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; - QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; - QAbstractEventDispatcher *createEventDispatcher() const; - - QList screens() const { return mScreens; } + QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; -private: - QList mScreens; + QAbstractEventDispatcher *createEventDispatcher() const; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/qwaylandintegration.cpp b/src/plugins/platforms/wayland/qwaylandintegration.cpp index 800f1fc99c..5405a8524e 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.cpp +++ b/src/plugins/platforms/wayland/qwaylandintegration.cpp @@ -54,8 +54,6 @@ #include #include -#include - #ifdef QT_WAYLAND_GL_SUPPORT #include "gl_integration/qwaylandglintegration.h" #endif @@ -92,11 +90,6 @@ bool QWaylandIntegration::hasCapability(QPlatformIntegration::Capability cap) co } } -QPlatformPixmap *QWaylandIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const -{ - return new QRasterPlatformPixmap(type); -} - QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const { #ifdef QT_WAYLAND_GL_SUPPORT diff --git a/src/plugins/platforms/wayland/qwaylandintegration.h b/src/plugins/platforms/wayland/qwaylandintegration.h index b9a01dab8d..0dc3b61009 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.h +++ b/src/plugins/platforms/wayland/qwaylandintegration.h @@ -56,7 +56,6 @@ public: QWaylandIntegration(); bool hasCapability(QPlatformIntegration::Capability cap) const; - QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; diff --git a/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp b/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp index f6028f69b2..3158c73605 100644 --- a/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp +++ b/src/plugins/platforms/wayland/qwaylandnativeinterface.cpp @@ -44,6 +44,7 @@ #include "qwaylanddisplay.h" #include "qwaylandwindow.h" #include +#include void *QWaylandNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) { @@ -64,9 +65,9 @@ QWaylandScreen * QWaylandNativeInterface::qPlatformScreenForWindow(QWindow *wind QWaylandScreen *screen; if (window) { - screen = static_cast(QPlatformScreen::platformScreenForWindow(window)); + screen = static_cast(window->screen()->handle()); } else { - screen = static_cast(QGuiApplicationPrivate::platformIntegration()->screens()[0]); + screen = static_cast(QGuiApplication::primaryScreen()->handle()); } return screen; } diff --git a/src/plugins/platforms/wayland/qwaylandscreen.cpp b/src/plugins/platforms/wayland/qwaylandscreen.cpp index 3a63e78207..7b064bac40 100644 --- a/src/plugins/platforms/wayland/qwaylandscreen.cpp +++ b/src/plugins/platforms/wayland/qwaylandscreen.cpp @@ -53,7 +53,6 @@ QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, struct wl_output , mFormat(QImage::Format_ARGB32_Premultiplied) , mWaylandCursor(new QWaylandCursor(this)) { - moveToThread(waylandDisplay->thread()); } QWaylandScreen::~QWaylandScreen() diff --git a/src/plugins/platforms/xcb/main.cpp b/src/plugins/platforms/xcb/main.cpp index 7fee7455be..c544f7073d 100644 --- a/src/plugins/platforms/xcb/main.cpp +++ b/src/plugins/platforms/xcb/main.cpp @@ -58,11 +58,10 @@ QStringList QXcbIntegrationPlugin::keys() const return list; } -QPlatformIntegration* QXcbIntegrationPlugin::create(const QString& system, const QStringList& paramList) +QPlatformIntegration* QXcbIntegrationPlugin::create(const QString& system, const QStringList& parameters) { - Q_UNUSED(paramList); if (system.toLower() == "xcb") - return new QXcbIntegration; + return new QXcbIntegration(parameters); return 0; } diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index 50407f7c9b..fadcb4d5b8 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -56,6 +56,7 @@ #include #include +#include class QXcbShmImage : public QXcbObject { @@ -213,7 +214,7 @@ QXcbBackingStore::QXcbBackingStore(QWindow *window) , m_image(0) , m_syncingResize(false) { - QXcbScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window)); + QXcbScreen *screen = static_cast(window->screen()->handle()); setConnection(screen->connection()); } @@ -280,7 +281,7 @@ void QXcbBackingStore::resize(const QSize &size, const QRegion &) Q_XCB_NOOP(connection()); - QXcbScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window())); + QXcbScreen *screen = static_cast(window()->screen()->handle()); QXcbWindow* win = static_cast(window()->handle()); delete m_image; diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 1e18077ea2..7803b3afe9 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -109,8 +109,11 @@ QXcbConnection::QXcbConnection(const char *displayName) #endif //XCB_USE_EGL #else m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreen); - #endif //XCB_USE_XLIB + + if (m_connection) + printf("Successfully connected to display %s\n", m_displayName.constData()); + xcb_prefetch_extension_data (m_connection, &xcb_xfixes_id); m_setup = xcb_get_setup(xcb_connection()); diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 924077f00d..313a773c78 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -47,14 +47,11 @@ #include "qxcbnativeinterface.h" #include "qxcbclipboard.h" #include "qxcbdrag.h" -#include "qxcbimage.h" #include #include -#include - #include #include @@ -64,6 +61,11 @@ #include #endif +#define XCB_USE_IBUS +#if defined(XCB_USE_IBUS) +#include "QtPlatformSupport/qibusplatforminputcontext.h" +#endif + #if defined(XCB_USE_GLX) #include "qglxintegration.h" #elif defined(XCB_USE_EGL) @@ -71,16 +73,23 @@ #include #endif -#define XCB_USE_IBUS -#if defined(XCB_USE_IBUS) -#include "QtPlatformSupport/qibusplatforminputcontext.h" -#endif +#include +#include -QXcbIntegration::QXcbIntegration() - : m_connection(new QXcbConnection), m_printerSupport(new QGenericUnixPrinterSupport) +QXcbIntegration::QXcbIntegration(const QStringList ¶meters) + : m_printerSupport(new QGenericUnixPrinterSupport) { - foreach (QXcbScreen *screen, m_connection->screens()) - m_screens << screen; + m_connections << new QXcbConnection; + + for (int i = 0; i < parameters.size() - 1; i += 2) { + qDebug() << parameters.at(i) << parameters.at(i+1); + QString display = parameters.at(i) + ':' + parameters.at(i+1); + m_connections << new QXcbConnection(display.toAscii().constData()); + } + + foreach (QXcbConnection *connection, m_connections) + foreach (QXcbScreen *screen, connection->screens()) + screenAdded(screen); m_fontDatabase = new QGenericUnixFontDatabase(); m_nativeInterface = new QXcbNativeInterface; @@ -90,21 +99,7 @@ QXcbIntegration::QXcbIntegration() 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); - } -} - -QPlatformPixmap *QXcbIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const -{ - return new QRasterPlatformPixmap(type); + qDeleteAll(m_connections); } QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const @@ -128,14 +123,15 @@ public: }; #endif -QPlatformGLContext *QXcbIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const +QPlatformGLContext *QXcbIntegration::createPlatformGLContext(QGuiGLContext *context) const { + QXcbScreen *screen = static_cast(context->screen()->handle()); #if defined(XCB_USE_GLX) - return new QGLXContext(static_cast(m_screens.at(0)), glFormat, share); + return new QGLXContext(screen, context->format(), context->shareHandle()); #elif defined(XCB_USE_EGL) - return new QEGLXcbPlatformContext(glFormat, share, m_connection->egl_display()); + return new QEGLXcbPlatformContext(context->format(), context->shareHandle(), screen->connection()->egl_display()); #elif defined(XCB_USE_DRI2) - return new QDri2Context(glFormat, share); + return new QDri2Context(context->format(), context->shareHandle()); #endif } @@ -144,10 +140,21 @@ QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *wind return new QXcbBackingStore(window); } +bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const +{ + switch (cap) { + case ThreadedPixmaps: return true; + case OpenGL: return true; + default: return QPlatformIntegration::hasCapability(cap); + } +} + QAbstractEventDispatcher *QXcbIntegration::createEventDispatcher() const { QAbstractEventDispatcher *eventDispatcher = createUnixEventDispatcher(); - m_connection->setEventDispatcher(eventDispatcher); + + foreach (QXcbConnection *connection, m_connections) + connection->setEventDispatcher(eventDispatcher); #ifdef XCB_USE_IBUS // A bit hacky to do this here, but we need an eventloop before we can instantiate // the input context. @@ -156,161 +163,17 @@ QAbstractEventDispatcher *QXcbIntegration::createEventDispatcher() const return eventDispatcher; } -QList QXcbIntegration::screens() const -{ - return m_screens; -} - void QXcbIntegration::moveToScreen(QWindow *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 -{ - if (width == 0 || height == 0) - return QPixmap(); - - xcb_connection_t *connection = m_connection->xcb_connection(); - - xcb_get_geometry_cookie_t geometry_cookie = xcb_get_geometry(connection, window); - - xcb_generic_error_t *error; - xcb_get_geometry_reply_t *reply = - xcb_get_geometry_reply(connection, geometry_cookie, &error); - - if (!reply) { - if (error) { - m_connection->handleXcbError(error); - free(error); - } - return QPixmap(); - } - - if (width < 0) - width = reply->width - x; - if (height < 0) - height = reply->height - y; - - // TODO: handle multiple screens - QXcbScreen *screen = m_connection->screens().at(0); - xcb_window_t root = screen->root(); - geometry_cookie = xcb_get_geometry(connection, root); - xcb_get_geometry_reply_t *root_reply = - xcb_get_geometry_reply(connection, geometry_cookie, &error); - - if (!root_reply) { - if (error) { - m_connection->handleXcbError(error); - free(error); - } - free(reply); - return QPixmap(); - } - - if (reply->depth == root_reply->depth) { - // if the depth of the specified window and the root window are the - // same, grab pixels from the root window (so that we get the any - // overlapping windows and window manager frames) - - // map x and y to the root window - xcb_translate_coordinates_cookie_t translate_cookie = - xcb_translate_coordinates(connection, window, root, x, y); - - xcb_translate_coordinates_reply_t *translate_reply = - xcb_translate_coordinates_reply(connection, translate_cookie, &error); - - if (!translate_reply) { - if (error) { - m_connection->handleXcbError(error); - free(error); - } - free(reply); - free(root_reply); - return QPixmap(); - } - - x = translate_reply->dst_x; - y = translate_reply->dst_y; - - window = root; - - free(translate_reply); - free(reply); - reply = root_reply; - } else { - free(root_reply); - root_reply = 0; - } - - xcb_get_window_attributes_reply_t *attributes_reply = - xcb_get_window_attributes_reply(connection, xcb_get_window_attributes(connection, window), &error); - - if (!attributes_reply) { - if (error) { - m_connection->handleXcbError(error); - free(error); - } - free(reply); - return QPixmap(); - } - - const xcb_visualtype_t *visual = screen->visualForId(attributes_reply->visual); - free(attributes_reply); - - xcb_pixmap_t pixmap = xcb_generate_id(connection); - error = xcb_request_check(connection, xcb_create_pixmap_checked(connection, reply->depth, pixmap, window, width, height)); - if (error) { - m_connection->handleXcbError(error); - free(error); - } - - uint32_t gc_value_mask = XCB_GC_SUBWINDOW_MODE; - uint32_t gc_value_list[] = { XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS }; - - xcb_gcontext_t gc = xcb_generate_id(connection); - xcb_create_gc(connection, gc, pixmap, gc_value_mask, gc_value_list); - - error = xcb_request_check(connection, xcb_copy_area_checked(connection, window, pixmap, gc, x, y, 0, 0, width, height)); - if (error) { - m_connection->handleXcbError(error); - free(error); - } - - QPixmap result = qt_xcb_pixmapFromXPixmap(m_connection, pixmap, width, height, reply->depth, visual); - - free(reply); - xcb_free_gc(connection, gc); - xcb_free_pixmap(connection, pixmap); - - return result; -} - -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; @@ -323,12 +186,12 @@ QPlatformPrinterSupport *QXcbIntegration::printerSupport() const QPlatformClipboard *QXcbIntegration::clipboard() const { - return m_connection->clipboard(); + return m_connections.at(0)->clipboard(); } QPlatformDrag *QXcbIntegration::drag() const { - return m_connection->drag(); + return m_connections.at(0)->drag(); } QPlatformInputContext *QXcbIntegration::inputContext() const diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h index 725db7a53d..d62878c7af 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.h +++ b/src/plugins/platforms/xcb/qxcbintegration.h @@ -53,20 +53,17 @@ class QAbstractEventDispatcher; class QXcbIntegration : public QPlatformIntegration { public: - QXcbIntegration(); + QXcbIntegration(const QStringList ¶meters); ~QXcbIntegration(); - bool hasCapability(Capability cap) const; - QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; - QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const; + QPlatformGLContext *createPlatformGLContext(QGuiGLContext *context) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; + + bool hasCapability(Capability cap) const; QAbstractEventDispatcher *createEventDispatcher() const; - QList screens() const; void moveToScreen(QWindow *window, int screen); - bool isVirtualDesktop(); - QPixmap grabWindow(WId window, int x, int y, int width, int height) const; QPlatformFontDatabase *fontDatabase() const; @@ -79,9 +76,7 @@ public: QPlatformInputContext *inputContext() const; private: - bool hasOpenGL() const; - QList m_screens; - QXcbConnection *m_connection; + QList m_connections; QPlatformFontDatabase *m_fontDatabase; QPlatformNativeInterface *m_nativeInterface; diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index 28b62b3aec..217dae6bc1 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -49,6 +49,7 @@ #include #include +#include #if defined(XCB_USE_EGL) #include "QtPlatformSupport/private/qeglplatformcontext_p.h" @@ -119,9 +120,9 @@ QXcbScreen *QXcbNativeInterface::qPlatformScreenForWindow(QWindow *window) { QXcbScreen *screen; if (window) { - screen = static_cast(QPlatformScreen::platformScreenForWindow(window)); - }else { - screen = static_cast(QGuiApplicationPrivate::platformIntegration()->screens()[0]); + screen = static_cast(window->screen()->handle()); + } else { + screen = static_cast(QGuiApplication::primaryScreen()->handle()); } return screen; } diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 6c3d1813b0..42259feda8 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -42,6 +42,7 @@ #include "qxcbscreen.h" #include "qxcbwindow.h" #include "qxcbcursor.h" +#include "qxcbimage.h" #include @@ -150,6 +151,7 @@ QXcbScreen::~QXcbScreen() delete m_cursor; } + QWindow *QXcbScreen::topLevelAt(const QPoint &p) const { xcb_window_t root = m_screen->root; @@ -227,3 +229,126 @@ int QXcbScreen::screenNumber() const { return m_number; } + +QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) const +{ + if (width == 0 || height == 0) + return QPixmap(); + + xcb_get_geometry_cookie_t geometry_cookie = xcb_get_geometry(xcb_connection(), window); + + xcb_generic_error_t *error; + xcb_get_geometry_reply_t *reply = + xcb_get_geometry_reply(xcb_connection(), geometry_cookie, &error); + + if (!reply) { + if (error) { + connection()->handleXcbError(error); + free(error); + } + return QPixmap(); + } + + if (width < 0) + width = reply->width - x; + if (height < 0) + height = reply->height - y; + + // TODO: handle multiple screens + QXcbScreen *screen = const_cast(this); + xcb_window_t root = screen->root(); + geometry_cookie = xcb_get_geometry(xcb_connection(), root); + xcb_get_geometry_reply_t *root_reply = + xcb_get_geometry_reply(xcb_connection(), geometry_cookie, &error); + + if (!root_reply) { + if (error) { + connection()->handleXcbError(error); + free(error); + } + free(reply); + return QPixmap(); + } + + if (reply->depth == root_reply->depth) { + // if the depth of the specified window and the root window are the + // same, grab pixels from the root window (so that we get the any + // overlapping windows and window manager frames) + + // map x and y to the root window + xcb_translate_coordinates_cookie_t translate_cookie = + xcb_translate_coordinates(xcb_connection(), window, root, x, y); + + xcb_translate_coordinates_reply_t *translate_reply = + xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, &error); + + if (!translate_reply) { + if (error) { + connection()->handleXcbError(error); + free(error); + } + free(reply); + free(root_reply); + return QPixmap(); + } + + x = translate_reply->dst_x; + y = translate_reply->dst_y; + + window = root; + + free(translate_reply); + free(reply); + reply = root_reply; + } else { + free(root_reply); + root_reply = 0; + } + + xcb_get_window_attributes_reply_t *attributes_reply = + xcb_get_window_attributes_reply(xcb_connection(), xcb_get_window_attributes(xcb_connection(), window), &error); + + if (!attributes_reply) { + if (error) { + connection()->handleXcbError(error); + free(error); + } + free(reply); + return QPixmap(); + } + + const xcb_visualtype_t *visual = screen->visualForId(attributes_reply->visual); + free(attributes_reply); + + xcb_pixmap_t pixmap = xcb_generate_id(xcb_connection()); + error = xcb_request_check(xcb_connection(), xcb_create_pixmap_checked(xcb_connection(), reply->depth, pixmap, window, width, height)); + if (error) { + connection()->handleXcbError(error); + free(error); + } + + uint32_t gc_value_mask = XCB_GC_SUBWINDOW_MODE; + uint32_t gc_value_list[] = { XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS }; + + xcb_gcontext_t gc = xcb_generate_id(xcb_connection()); + xcb_create_gc(xcb_connection(), gc, pixmap, gc_value_mask, gc_value_list); + + error = xcb_request_check(xcb_connection(), xcb_copy_area_checked(xcb_connection(), window, pixmap, gc, x, y, 0, 0, width, height)); + if (error) { + connection()->handleXcbError(error); + free(error); + } + + QPixmap result = qt_xcb_pixmapFromXPixmap(connection(), pixmap, width, height, reply->depth, visual); + + free(reply); + xcb_free_gc(xcb_connection(), gc); + xcb_free_pixmap(xcb_connection(), pixmap); + + return result; +} + +QString QXcbScreen::name() const +{ + return connection()->displayName() + QLatin1String(".") + QString::number(screenNumber()); +} diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index 5b8492faa5..07d855b398 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -58,6 +58,8 @@ public: QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int number); ~QXcbScreen(); + QPixmap grabWindow(WId window, int x, int y, int width, int height) const; + QWindow *topLevelAt(const QPoint &point) const; QRect geometry() const; @@ -77,6 +79,8 @@ public: const xcb_visualtype_t *visualForId(xcb_visualid_t) const; + QString name() const; + private: xcb_screen_t *m_screen; int m_number; diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index f63cbe25e6..14ac0e6640 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -42,6 +42,7 @@ #include "qxcbwindow.h" #include +#include #include "qxcbconnection.h" #include "qxcbscreen.h" @@ -102,7 +103,7 @@ QXcbWindow::QXcbWindow(QWindow *window) , m_eglSurface(0) #endif { - m_screen = static_cast(QGuiApplicationPrivate::platformIntegration()->screens().at(0)); + m_screen = static_cast(window->screen()->handle()); setConnection(m_screen->connection()); diff --git a/src/widgets/kernel/qapplication_qpa.cpp b/src/widgets/kernel/qapplication_qpa.cpp index 1b37ddf2e0..3c0575b656 100644 --- a/src/widgets/kernel/qapplication_qpa.cpp +++ b/src/widgets/kernel/qapplication_qpa.cpp @@ -45,6 +45,7 @@ #ifndef QT_NO_CURSOR #include "private/qcursor_p.h" #endif +#include "qscreen.h" #include "private/qwidget_p.h" #include "private/qevent_p.h" @@ -384,21 +385,13 @@ bool QApplication::isEffectEnabled(Qt::UIEffect effect) QWidget *QApplication::topLevelAt(const QPoint &pos) { - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - - QList screens = pi->screens(); - QList::const_iterator screen = screens.constBegin(); - QList::const_iterator end = screens.constEnd(); - - // The first screen in a virtual environment should know about all top levels - if (pi->isVirtualDesktop()) { - QWidgetWindow *w = qobject_cast((*screen)->topLevelAt(pos)); - return w ? w->widget() : 0; - } + QList screens = QGuiApplication::screens(); + QList::const_iterator screen = screens.constBegin(); + QList::const_iterator end = screens.constEnd(); while (screen != end) { if ((*screen)->geometry().contains(pos)) { - QWidgetWindow *w = qobject_cast((*screen)->topLevelAt(pos)); + QWidgetWindow *w = qobject_cast((*screen)->handle()->topLevelAt(pos)); return w ? w->widget() : 0; } ++screen; diff --git a/src/widgets/kernel/qdesktopwidget_qpa.cpp b/src/widgets/kernel/qdesktopwidget_qpa.cpp index 5e4dffb15d..380daee8c0 100644 --- a/src/widgets/kernel/qdesktopwidget_qpa.cpp +++ b/src/widgets/kernel/qdesktopwidget_qpa.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qdesktopwidget.h" +#include "qscreen.h" #include "private/qapplication_p.h" #include #include "private/qwidget_p.h" @@ -51,7 +52,7 @@ QT_USE_NAMESPACE void QDesktopWidgetPrivate::updateScreenList() { Q_Q(QDesktopWidget); - QList screenList = QGuiApplicationPrivate::platformIntegration()->screens(); + QList screenList = QGuiApplication::screens(); int targetLength = screenList.length(); int currentLength = screens.length(); @@ -97,7 +98,7 @@ QDesktopWidget::~QDesktopWidget() bool QDesktopWidget::isVirtualDesktop() const { - return QGuiApplicationPrivate::platformIntegration()->isVirtualDesktop(); + return QGuiApplication::primaryScreen()->virtualSiblings().size() > 1; } int QDesktopWidget::primaryScreen() const @@ -107,8 +108,7 @@ int QDesktopWidget::primaryScreen() const int QDesktopWidget::numScreens() const { - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - return qMax(pi->screens().size(), 1); + return qMax(QGuiApplication::screens().size(), 1); } QWidget *QDesktopWidget::screen(int screen) @@ -121,26 +121,24 @@ QWidget *QDesktopWidget::screen(int screen) const QRect QDesktopWidget::availableGeometry(int screenNo) const { - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - QList screens = pi->screens(); + QList screens = QGuiApplication::screens(); if (screenNo == -1) screenNo = 0; if (screenNo < 0 || screenNo >= screens.size()) return QRect(); else - return screens[screenNo]->availableGeometry(); + return screens.at(screenNo)->availableGeometry(); } const QRect QDesktopWidget::screenGeometry(int screenNo) const { - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - QList screens = pi->screens(); + QList screens = QGuiApplication::screens(); if (screenNo == -1) screenNo = 0; if (screenNo < 0 || screenNo >= screens.size()) return QRect(); else - return screens[screenNo]->geometry(); + return screens.at(screenNo)->geometry(); } int QDesktopWidget::screenNumber(const QWidget *w) const @@ -157,11 +155,10 @@ int QDesktopWidget::screenNumber(const QWidget *w) const int QDesktopWidget::screenNumber(const QPoint &p) const { - QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); - QList screens = pi->screens(); + QList screens = QGuiApplication::screens(); for (int i = 0; i < screens.size(); ++i) - if (screens[i]->geometry().contains(p)) + if (screens.at(i)->geometry().contains(p)) return i; return primaryScreen(); //even better would be closest screen diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index a29a265e5a..76218a9eb3 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1266,8 +1266,7 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) #elif defined(Q_WS_QPA) if (desktopWidget) { int screen = desktopWidget->d_func()->topData()->screenIndex; - QPlatformIntegration *platform = QGuiApplicationPrivate::platformIntegration(); - platform->moveToScreen(q->windowHandle(), screen); + q->windowHandle()->setScreen(QGuiApplication::screens().value(screen, 0)); } #else Q_UNUSED(desktopWidget); diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index 5051b38185..b8f1f4ebc7 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -104,6 +104,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO win->setWindowFlags(data.window_flags); win->setGeometry(q->geometry()); + win->setScreen(QGuiApplication::screens().value(topData()->screenIndex, 0)); if (q->testAttribute(Qt::WA_TranslucentBackground)) { QSurfaceFormat format; @@ -141,7 +142,6 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO // first check children. and create them if necessary // q_createNativeChildrenAndSetParent(q->windowHandle(),q); - QGuiApplicationPrivate::platformIntegration()->moveToScreen(win, topData()->screenIndex); // qDebug() << "create_sys" << q << q->internalWinId(); } @@ -261,8 +261,7 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) maybeTopData()->screenIndex = targetScreen; // only if it is already created if (q->testAttribute(Qt::WA_WState_Created)) { - QPlatformIntegration *platform = QGuiApplicationPrivate::platformIntegration(); - platform->moveToScreen(q->windowHandle(), targetScreen); + q->windowHandle()->setScreen(QGuiApplication::screens().value(targetScreen, 0)); } } } -- cgit v1.2.3