Don't force-create QWindows until they're explicitly created or shown.
#include "window.h"
-#include <private/qguiapplication_qpa_p.h>
+#include <private/qguiapplication_p.h>
#include <private/qwindowsurface_p.h>
#include <QPainter>
};
Window::Window(QWindow *parent)
- : QWindow(0)
+ : QWindow(parent)
, m_backgroundColorIndex(colorIndexId++)
{
setSurfaceType(RasterSurface);
setWindowTitle(QLatin1String("Window"));
if (parent)
- setGeometry(QRect(10, 10, 40, 40));
+ setGeometry(QRect(160, 120, 320, 240));
else
setGeometry(QRect(10, 10, 640, 480));
- if (parent) {
- setParent(parent);
- setGeometry(QRect(160, 120, 320, 240));
- }
-
create();
QGuiApplicationPrivate::platformIntegration()->createWindowSurface(this, winId());
#include <QtCore/qcoreapplication.h>
#include <QtGui/qwindowdefs.h>
+#include <QtCore/qlocale.h>
#include <QtCore/qpoint.h>
#include <QtCore/qsize.h>
QT_BEGIN_NAMESPACE
QWindow::QWindow(QWindow *parent)
- : QObject(*new QWindowPrivate())
+ : QObject(*new QWindowPrivate(), parent)
{
- if (parent) {
- setParent(parent);
- }
+ Q_D(QWindow);
+ d->parentWindow = parent;
}
QWindow::~QWindow()
d->windowFlags = d->platformWindow->setWindowFlags(d->windowFlags);
if (!d->windowTitle.isNull())
d->platformWindow->setWindowTitle(d->windowTitle);
- }
- Q_ASSERT(d->platformWindow);
-
- QObjectList childObjects = children();
- for (int i = 0; i < childObjects.size(); i ++) {
- QObject *object = childObjects.at(i);
- if(object->isWindowType()) {
- QWindow *window = static_cast<QWindow *>(object);
- window->setParent(this);
+
+ QObjectList childObjects = children();
+ for (int i = 0; i < childObjects.size(); i ++) {
+ QObject *object = childObjects.at(i);
+ if(object->isWindowType()) {
+ QWindow *window = static_cast<QWindow *>(object);
+ if (window->d_func()->platformWindow)
+ window->d_func()->platformWindow->setParent(d->platformWindow);
+ }
}
}
}
{
Q_D(QWindow);
- if (d->parent == parent)
+ if (d->parentWindow == parent)
return;
QObject::setParent(parent);
- if (parent) {
- if (parent->d_func()->platformWindow) {
- if(!d->platformWindow) {
- create();
- }
+ if (d->platformWindow) {
+ if (parent && parent->d_func()->platformWindow) {
d->platformWindow->setParent(parent->d_func()->platformWindow);
- d->parent = parent;
- }
- } else {
- d->parent = 0;
- if (d->parentWindow) {
+ } else if (!parent) {
d->platformWindow->setParent(0);
}
}
+ d->parentWindow = parent;
}
void QWindow::setWindowFormat(const QWindowFormat &format)
: QObjectPrivate()
, windowFlags(Qt::Window)
, surfaceType(QWindow::RasterSurface)
+ , parentWindow(0)
, platformWindow(0)
, visible(false)
, glContext(0)
if (childWidget->testAttribute(Qt::WA_NativeWindow)) {
if (!childWidget->windowHandle())
childWidget->winId();
- }
- if (childWidget->windowHandle()) {
- childWidget->windowHandle()->setParent(parentWindow);
+ if (childWidget->windowHandle())
+ childWidget->windowHandle()->setParent(parentWindow);
} else {
q_createNativeChildrenAndSetParent(parentWindow,childWidget);
}
QWindow *win = topData()->window;
+ if (!q->isWindow()) {
+ if (QWidget *nativeParent = q->nativeParentWidget()) {
+ if (nativeParent->windowHandle())
+ win->setParent(nativeParent->windowHandle());
+ }
+ }
+
win->setWindowFlags(data.window_flags);
win->setGeometry(q->geometry());
win->create();
setWinId(win->winId());
// first check children. and create them if necessary
- q_createNativeChildrenAndSetParent(q->windowHandle(),q);
-
- //if we we have a parent, then set correct parent;
- if (!q->isWindow()) {
- if (QWidget *nativeParent = q->nativeParentWidget()) {
- if (nativeParent->windowHandle()) {
- win->setParent(nativeParent->windowHandle());
- }
- }
- }
+// q_createNativeChildrenAndSetParent(q->windowHandle(),q);
QGuiApplicationPrivate::platformIntegration()->moveToScreen(q, topData()->screenIndex);
// qDebug() << "create_sys" << q << q->internalWinId();
QApplication::postEvent(q, new QUpdateLaterEvent(q->rect()));
+ if (!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow))
+ return;
+
QWindow *window = q->windowHandle();
if (window) {
QRect geomRect = q->geometry();
QMouseEvent translated(event->type(), mapped, event->globalPos(), event->button(), event->buttons(), event->modifiers());
QGuiApplication::sendSpontaneousEvent(widget, &translated);
+
+ if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::RightButton) {
+ QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers());
+ QGuiApplication::sendSpontaneousEvent(widget, &e);
+ }
}
void QWidgetWindow::handleKeyEvent(QKeyEvent *event)
QRect rect = window->geometry();
+ xcb_window_t xcb_parent_id = m_screen->root();
+ if (window->parent() && window->parent()->windowHandle())
+ xcb_parent_id = static_cast<QXcbWindow *>(window->parent()->windowHandle())->xcb_window();
+
#if defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
if (window->surfaceType() == QWindow::OpenGLSurface
&& QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL))
visualInfo = XGetVisualInfo(DISPLAY_FROM_XCB(this), VisualIDMask, &visualInfoTemplate, &matchingCount);
#endif //XCB_USE_GLX
if (visualInfo) {
- Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), m_screen->root(), visualInfo->visual, AllocNone);
+ Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), xcb_parent_id, visualInfo->visual, AllocNone);
XSetWindowAttributes a;
a.colormap = cmap;
- m_window = XCreateWindow(DISPLAY_FROM_XCB(this), m_screen->root(), rect.x(), rect.y(), rect.width(), rect.height(),
+ m_window = XCreateWindow(DISPLAY_FROM_XCB(this), xcb_parent_id, rect.x(), rect.y(), rect.width(), rect.height(),
0, visualInfo->depth, InputOutput, visualInfo->visual,
CWColormap, &a);
Q_XCB_CALL(xcb_create_window(xcb_connection(),
XCB_COPY_FROM_PARENT, // depth -- same as root
m_window, // window id
- m_screen->root(), // parent window id
+ xcb_parent_id, // parent window id
rect.x(),
rect.y(),
rect.width(),