diff --git a/examples/qpa/windows/window.cpp b/examples/qpa/windows/window.cpp index 0f3355b86b..d08db5714b 100644 --- a/examples/qpa/windows/window.cpp +++ b/examples/qpa/windows/window.cpp @@ -1,6 +1,6 @@ #include "window.h" -#include +#include #include #include @@ -15,22 +15,17 @@ QColor colorTable[] = }; 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()); diff --git a/src/gui/guikernel/qguiapplication.h b/src/gui/guikernel/qguiapplication.h index 16f56d0a51..f1ac01dcfc 100644 --- a/src/gui/guikernel/qguiapplication.h +++ b/src/gui/guikernel/qguiapplication.h @@ -44,6 +44,7 @@ #include #include +#include #include #include diff --git a/src/gui/guikernel/qwindow.cpp b/src/gui/guikernel/qwindow.cpp index 7b57a949f0..60647953f2 100644 --- a/src/gui/guikernel/qwindow.cpp +++ b/src/gui/guikernel/qwindow.cpp @@ -54,11 +54,10 @@ 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() @@ -90,15 +89,15 @@ void QWindow::create() 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(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(object); + if (window->d_func()->platformWindow) + window->d_func()->platformWindow->setParent(d->platformWindow); + } } } } @@ -120,26 +119,20 @@ void QWindow::setParent(QWindow *parent) { 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) diff --git a/src/gui/guikernel/qwindow_p.h b/src/gui/guikernel/qwindow_p.h index 304ab3bc49..6f1038e8c4 100644 --- a/src/gui/guikernel/qwindow_p.h +++ b/src/gui/guikernel/qwindow_p.h @@ -59,6 +59,7 @@ public: : QObjectPrivate() , windowFlags(Qt::Window) , surfaceType(QWindow::RasterSurface) + , parentWindow(0) , platformWindow(0) , visible(false) , glContext(0) diff --git a/src/gui/kernel/qwidget_qpa.cpp b/src/gui/kernel/qwidget_qpa.cpp index 8c55708429..5ef3b8960e 100644 --- a/src/gui/kernel/qwidget_qpa.cpp +++ b/src/gui/kernel/qwidget_qpa.cpp @@ -64,9 +64,8 @@ void q_createNativeChildrenAndSetParent(QWindow *parentWindow, const QWidget *pa 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); } @@ -93,6 +92,13 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO 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(); @@ -111,16 +117,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO 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(); @@ -381,6 +378,9 @@ void QWidgetPrivate::show_sys() 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(); diff --git a/src/gui/kernel/qwidgetwindow_qpa.cpp b/src/gui/kernel/qwidgetwindow_qpa.cpp index a58a03774e..ec60e57b26 100644 --- a/src/gui/kernel/qwidgetwindow_qpa.cpp +++ b/src/gui/kernel/qwidgetwindow_qpa.cpp @@ -108,6 +108,11 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) 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) diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index b0df622b33..84886554b1 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -113,6 +113,10 @@ QXcbWindow::QXcbWindow(QWindow *window) QRect rect = window->geometry(); + xcb_window_t xcb_parent_id = m_screen->root(); + if (window->parent() && window->parent()->windowHandle()) + xcb_parent_id = static_cast(window->parent()->windowHandle())->xcb_window(); + #if defined(XCB_USE_GLX) || defined(XCB_USE_EGL) if (window->surfaceType() == QWindow::OpenGLSurface && QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) @@ -133,11 +137,11 @@ QXcbWindow::QXcbWindow(QWindow *window) 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); @@ -153,7 +157,7 @@ QXcbWindow::QXcbWindow(QWindow *window) 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(),