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
#include <QGuiApplication>
+#include <QScreen>
#include "window.h"
Window child(&b);
child.setVisible(true);
+ // create one window on each additional screen as well
+
+ QList<QScreen *> 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();
}
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));
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)
m_lastPos = event->pos();
}
- render();
+ scheduleRender();
}
void Window::mouseReleaseEvent(QMouseEvent *event)
m_lastPos = QPoint(-1, -1);
}
- render();
+ scheduleRender();
}
void Window::exposeEvent(QExposeEvent *)
{
- render();
+ scheduleRender();
}
void Window::resizeEvent(QResizeEvent *)
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()
{
public:
Window(QWindow *parent = 0);
+ Window(QScreen *screen);
protected:
void mousePressEvent(QMouseEvent *);
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;
};
#include "qbitmap.h"
#include "qplatformpixmap_qpa.h"
#include "qimage.h"
+#include "qscreen.h"
#include "qvariant.h"
#include <qpainter.h>
#include <private/qguiapplication_p.h>
#include <qdebug.h>
#include "qnativeimage_p.h"
#include "qcolormap.h"
+#include "qscreen.h"
#include "private/qpaintengine_raster_p.h"
QImage::Format QNativeImage::systemFormat()
{
- return QGuiApplicationPrivate::platformIntegration()->screens().at(0)->format();
+ return QGuiApplication::primaryScreen()->handle()->format();
}
#endif // platforms
#include <qpainter.h>
#include <qimage.h>
+#include <qscreen.h>
#include <private/qguiapplication_p.h>
#include <private/qblittable_p.h>
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;
****************************************************************************/
#include <qpixmap.h>
+#include <qscreen.h>
#include <private/qguiapplication_p.h>
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);
}
kernel/qpalette.h \
kernel/qsessionmanager.h \
kernel/qwindowdefs.h \
+ kernel/qscreen.h
SOURCES += \
kernel/qclipboard.cpp \
kernel/qmime.cpp \
kernel/qpalette.cpp \
kernel/qguivariant.cpp \
+ kernel/qscreen.cpp
qpa {
HEADERS += \
QPixmap pixmap;
public:
QShapedPixmapWindow() :
- QWindow(0)
+ QWindow()
{
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
// ### Should we set the surface type to raster?
#include <QtCore/qmutex.h>
#include <QtDebug>
#include <qpalette.h>
+#include <qscreen.h>
#include <QtGui/QPlatformIntegration>
#include <QtGui/QGenericPluginFactory>
QClipboard *QGuiApplicationPrivate::qt_clipboard = 0;
#endif
+QList<QScreen *> QGuiApplicationPrivate::screen_list;
+
QWindowList QGuiApplicationPrivate::window_list;
QWindow *QGuiApplicationPrivate::active_window = 0;
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<QPlatformScreen *> screens = pi->screens();
- QList<QPlatformScreen *>::const_iterator screen = screens.constBegin();
- QList<QPlatformScreen *>::const_iterator end = screens.constEnd();
+QList<QScreen *> 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<QScreen *> screens = QGuiApplication::screens();
+ QList<QScreen *>::const_iterator screen = screens.constBegin();
+ QList<QScreen *>::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;
class QGuiApplicationPrivate;
class QPlatformNativeInterface;
class QPalette;
+class QScreen;
#if defined(qApp)
#undef qApp
static QWindow *topLevelAt(const QPoint &pos);
static QWindow *activeWindow();
+ static QScreen *primaryScreen();
+ static QList<QScreen *> screens();
#ifndef QT_NO_CURSOR
static QCursor *overrideCursor();
Q_SIGNALS:
void fontDatabaseChanged();
+ void screenAdded(QScreen *screen);
protected:
bool event(QEvent *);
friend class QGestureManager;
#endif
friend class QFontDatabasePrivate;
+ friend class QPlatformIntegration;
};
QT_END_NAMESPACE
#ifndef QT_NO_CURSOR
QList<QCursor> cursor_list;
#endif
+ static QList<QScreen *> screen_list;
static QFont *app_font;
private:
#include <QtCore/QThread>
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/QScreen>
#include <QDebug>
: qGLContextHandle(0)
, platformGLContext(0)
, shareContext(0)
+ , screen(0)
{
}
}
void *qGLContextHandle;
void (*qGLContextDeleteFunction)(void *handle);
+
+ QSurfaceFormat requestedFormat;
QPlatformGLContext *platformGLContext;
QGuiGLContext *shareContext;
+ QScreen *screen;
static void setCurrentContext(QGuiGLContext *context);
};
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);
{
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.
{
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<QGuiGLContextPrivate> d_ptr;
void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *));
void deleteQGLContext();
+ void destroy();
+
Q_DISABLE_COPY(QGuiGLContext);
};
#include <QtGui/QPlatformFontDatabase>
#include <QtGui/QPlatformClipboard>
#include <QtGui/QPlatformPrinterSupport>
+#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/private/qpixmap_raster_p.h>
#include <private/qdnd_p.h>
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.
*/
-QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(const QSurfaceFormat &, QPlatformGLContext *) const
-{
- qWarning("This plugin does not support createPlatformGLContext!");
- return 0;
-}
-
/*!
\fn void QPlatformIntegration::moveToScreen(QWindow *window, int screen)
*/
/*!
- \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
Factory function for the event dispatcher. The platform plugin
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.
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
#define QPLATFORMINTEGRATION_H
#include <QtGui/qwindowdefs.h>
-#include <QtGui/qplatformpixmap_qpa.h>
#include <QtGui/qplatformscreen_qpa.h>
#include <QtGui/qsurfaceformat.h>
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<QPlatformScreen *> 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;
virtual QPlatformNativeInterface *nativeInterface() const;
virtual QPlatformPrinterSupport *printerSupport() const;
+
+protected:
+ void screenAdded(QPlatformScreen *screen);
};
QT_END_NAMESPACE
#include <QtGui/qguiapplication.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qplatformintegration_qpa.h>
+#include <QtGui/qscreen.h>
#include <QtGui/qwindow.h>
+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.
}
/*!
+ 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 *> QPlatformScreen::virtualSiblings() const
+{
+ QList<QPlatformScreen *> list;
+ list << const_cast<QPlatformScreen *>(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
sizes.
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();
}
/*!
#include <QtGui/qcursor.h>
#include <QtGui/qimage.h>
#include <QtGui/qwindowdefs.h>
+#include <QtGui/qplatformpixmap_qpa.h>
QT_BEGIN_HEADER
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<QPlatformScreen *> 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<QPlatformScreenPrivate> d_ptr;
+
+private:
+ Q_DISABLE_COPY(QPlatformScreen)
};
QT_END_NAMESPACE
--- /dev/null
+/****************************************************************************
+**
+** 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 <QList>
+
+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<QScreen *> 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
+
#include "qsurfaceformat.h"
#include "qplatformglcontext_qpa.h"
#include "qguiglcontext_qpa.h"
+#include "qscreen.h"
#include "qwindow_p.h"
#include "qguiapplication_p.h"
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);
}
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__;
bool QWindow::event(QEvent *event)
{
- Q_D(QWindow);
switch (event->type()) {
case QEvent::MouseMove:
mouseMoveEvent(static_cast<QMouseEvent*>(event));
class QPlatformSurface;
class QPlatformWindow;
class QBackingStore;
+class QScreen;
class Q_GUI_EXPORT QSurface
{
public:
enum SurfaceType { RasterSurface, OpenGLSurface };
- QWindow(QWindow *parent = 0);
+ QWindow(QScreen *screen = 0);
+ QWindow(QWindow *parent);
virtual ~QWindow();
void setSurfaceType(SurfaceType surfaceType);
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); }
, maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)
, modality(Qt::NonModal)
, transientParent(0)
+ , screen(0)
{
isWindow = true;
}
Qt::WindowModality modality;
QPointer<QWindow> transientParent;
+ QScreen *screen;
};
#include <qwindow.h>
#include <qpixmap.h>
#include <qplatformbackingstore_qpa.h>
+#include <qscreen.h>
#include <private/qguiapplication_p.h>
#include <private/qwindow_p.h>
#include "qcolormap.h"
#include "qcolor.h"
#include "qpaintdevice.h"
-#include "private/qguiapplication_p.h"
+#include "qscreen.h"
QT_BEGIN_NAMESPACE
{
screenMap = new QColormapPrivate;
- QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
- QList<QPlatformScreen*> 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;
#include "qdatastream.h"
#include "qguiapplication.h"
#include "qstringlist.h"
+#include "qscreen.h"
#include "qthread.h"
#include "qthreadstorage.h"
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
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
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();
}
d->window->create();
d->context = new QGuiGLContext;
+ d->context->create();
d->context->makeCurrent(d->window);
}
bool QEventDispatcherQPA::processEvents(QEventLoop::ProcessEventsFlags flags)
{
- Q_D(QEventDispatcherQPA);
-
bool didSendEvents = QWindowSystemInterface::sendWindowSystemEvents(this, flags);
if (QEventDispatcherUNIX::processEvents(flags)) {
~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<QPlatformScreen *> screens() const { return mScreens; }
-
QPlatformFontDatabase *fontDatabase() const;
QPlatformNativeInterface *nativeInterface() const;
private:
- QList<QPlatformScreen *> mScreens;
QPlatformFontDatabase *mFontDb;
QCocoaAutoReleasePool *mPool;
#include "qcocoaeventdispatcher.h"
#include <QtPlatformSupport/private/qbasicunixfontdatabase_p.h>
-#include <private/qpixmap_raster_p.h>
QT_BEGIN_NAMESPACE
NSArray *screens = [NSScreen screens];
for (uint i = 0; i < [screens count]; i++) {
QCocoaScreen *screen = new QCocoaScreen(i);
- mScreens.append(screen);
+ screenAdded(screen);
}
}
-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
#include "qminimalbackingstore.h"
+#include "qscreen.h"
#include <QtCore/qdebug.h>
#include <private/qguiapplication_p.h>
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);
}
mPrimaryScreen->mDepth = 32;
mPrimaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied;
- mScreens.append(mPrimaryScreen);
+ screenAdded(mPrimaryScreen);
}
bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const
}
}
-QPlatformPixmap *QMinimalIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
-{
- return new QRasterPlatformPixmap(type);
-}
-
QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) const
{
Q_UNUSED(window);
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<QPlatformScreen *> screens() const { return mScreens; }
+ QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
-private:
- QList<QPlatformScreen *> mScreens;
+ QAbstractEventDispatcher *createEventDispatcher() const;
};
QT_END_NAMESPACE
#include <QtGui/QPlatformCursor>
#include <QtGui/QSurfaceFormat>
-#include <QtGui/private/qpixmap_raster_p.h>
-
#ifdef QT_WAYLAND_GL_SUPPORT
#include "gl_integration/qwaylandglintegration.h"
#endif
}
}
-QPlatformPixmap *QWaylandIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
-{
- return new QRasterPlatformPixmap(type);
-}
-
QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const
{
#ifdef QT_WAYLAND_GL_SUPPORT
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;
#include "qwaylanddisplay.h"
#include "qwaylandwindow.h"
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/QScreen>
void *QWaylandNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
{
QWaylandScreen *screen;
if (window) {
- screen = static_cast<QWaylandScreen *>(QPlatformScreen::platformScreenForWindow(window));
+ screen = static_cast<QWaylandScreen *>(window->screen()->handle());
} else {
- screen = static_cast<QWaylandScreen *>(QGuiApplicationPrivate::platformIntegration()->screens()[0]);
+ screen = static_cast<QWaylandScreen *>(QGuiApplication::primaryScreen()->handle());
}
return screen;
}
, mFormat(QImage::Format_ARGB32_Premultiplied)
, mWaylandCursor(new QWaylandCursor(this))
{
- moveToThread(waylandDisplay->thread());
}
QWaylandScreen::~QWaylandScreen()
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;
}
#include <qdebug.h>
#include <qpainter.h>
+#include <qscreen.h>
class QXcbShmImage : public QXcbObject
{
, m_image(0)
, m_syncingResize(false)
{
- QXcbScreen *screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWindow(window));
+ QXcbScreen *screen = static_cast<QXcbScreen *>(window->screen()->handle());
setConnection(screen->connection());
}
Q_XCB_NOOP(connection());
- QXcbScreen *screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWindow(window()));
+ QXcbScreen *screen = static_cast<QXcbScreen *>(window()->screen()->handle());
QXcbWindow* win = static_cast<QXcbWindow *>(window()->handle());
delete m_image;
#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());
#include "qxcbnativeinterface.h"
#include "qxcbclipboard.h"
#include "qxcbdrag.h"
-#include "qxcbimage.h"
#include <QtPlatformSupport/private/qgenericunixprintersupport_p.h>
#include <xcb/xcb.h>
-#include <private/qpixmap_raster_p.h>
-
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
#include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
#include <EGL/egl.h>
#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)
#include <QtPlatformSupport/private/qeglplatformcontext_p.h>
#endif
-#define XCB_USE_IBUS
-#if defined(XCB_USE_IBUS)
-#include "QtPlatformSupport/qibusplatforminputcontext.h"
-#endif
+#include <QtGui/QGuiGLContext>
+#include <QtGui/QScreen>
-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;
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
};
#endif
-QPlatformGLContext *QXcbIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
+QPlatformGLContext *QXcbIntegration::createPlatformGLContext(QGuiGLContext *context) const
{
+ QXcbScreen *screen = static_cast<QXcbScreen *>(context->screen()->handle());
#if defined(XCB_USE_GLX)
- return new QGLXContext(static_cast<QXcbScreen *>(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
}
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.
return eventDispatcher;
}
-QList<QPlatformScreen *> 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;
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
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<QPlatformScreen *> 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;
QPlatformInputContext *inputContext() const;
private:
- bool hasOpenGL() const;
- QList<QPlatformScreen *> m_screens;
- QXcbConnection *m_connection;
+ QList<QXcbConnection *> m_connections;
QPlatformFontDatabase *m_fontDatabase;
QPlatformNativeInterface *m_nativeInterface;
#include <QtCore/QDebug>
#include <QtGui/qguiglcontext_qpa.h>
+#include <QtGui/qscreen.h>
#if defined(XCB_USE_EGL)
#include "QtPlatformSupport/private/qeglplatformcontext_p.h"
{
QXcbScreen *screen;
if (window) {
- screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWindow(window));
- }else {
- screen = static_cast<QXcbScreen *>(QGuiApplicationPrivate::platformIntegration()->screens()[0]);
+ screen = static_cast<QXcbScreen *>(window->screen()->handle());
+ } else {
+ screen = static_cast<QXcbScreen *>(QGuiApplication::primaryScreen()->handle());
}
return screen;
}
#include "qxcbscreen.h"
#include "qxcbwindow.h"
#include "qxcbcursor.h"
+#include "qxcbimage.h"
#include <stdio.h>
delete m_cursor;
}
+
QWindow *QXcbScreen::topLevelAt(const QPoint &p) const
{
xcb_window_t root = m_screen->root;
{
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<QXcbScreen *>(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());
+}
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;
const xcb_visualtype_t *visualForId(xcb_visualid_t) const;
+ QString name() const;
+
private:
xcb_screen_t *m_screen;
int m_number;
#include "qxcbwindow.h"
#include <QtDebug>
+#include <QScreen>
#include "qxcbconnection.h"
#include "qxcbscreen.h"
, m_eglSurface(0)
#endif
{
- m_screen = static_cast<QXcbScreen *>(QGuiApplicationPrivate::platformIntegration()->screens().at(0));
+ m_screen = static_cast<QXcbScreen *>(window->screen()->handle());
setConnection(m_screen->connection());
#ifndef QT_NO_CURSOR
#include "private/qcursor_p.h"
#endif
+#include "qscreen.h"
#include "private/qwidget_p.h"
#include "private/qevent_p.h"
QWidget *QApplication::topLevelAt(const QPoint &pos)
{
- QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
-
- QList<QPlatformScreen *> screens = pi->screens();
- QList<QPlatformScreen *>::const_iterator screen = screens.constBegin();
- QList<QPlatformScreen *>::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<QWidgetWindow *>((*screen)->topLevelAt(pos));
- return w ? w->widget() : 0;
- }
+ QList<QScreen *> screens = QGuiApplication::screens();
+ QList<QScreen *>::const_iterator screen = screens.constBegin();
+ QList<QScreen *>::const_iterator end = screens.constEnd();
while (screen != end) {
if ((*screen)->geometry().contains(pos)) {
- QWidgetWindow *w = qobject_cast<QWidgetWindow *>((*screen)->topLevelAt(pos));
+ QWidgetWindow *w = qobject_cast<QWidgetWindow *>((*screen)->handle()->topLevelAt(pos));
return w ? w->widget() : 0;
}
++screen;
****************************************************************************/
#include "qdesktopwidget.h"
+#include "qscreen.h"
#include "private/qapplication_p.h"
#include <QWidget>
#include "private/qwidget_p.h"
void QDesktopWidgetPrivate::updateScreenList()
{
Q_Q(QDesktopWidget);
- QList<QPlatformScreen *> screenList = QGuiApplicationPrivate::platformIntegration()->screens();
+ QList<QScreen *> screenList = QGuiApplication::screens();
int targetLength = screenList.length();
int currentLength = screens.length();
bool QDesktopWidget::isVirtualDesktop() const
{
- return QGuiApplicationPrivate::platformIntegration()->isVirtualDesktop();
+ return QGuiApplication::primaryScreen()->virtualSiblings().size() > 1;
}
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)
const QRect QDesktopWidget::availableGeometry(int screenNo) const
{
- QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
- QList<QPlatformScreen *> screens = pi->screens();
+ QList<QScreen *> 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<QPlatformScreen *> screens = pi->screens();
+ QList<QScreen *> 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
int QDesktopWidget::screenNumber(const QPoint &p) const
{
- QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
- QList<QPlatformScreen *> screens = pi->screens();
+ QList<QScreen *> 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
#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);
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;
// 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();
}
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));
}
}
}