summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-01-30 14:57:29 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-02-22 07:58:07 +0000
commitc585802e946d97e7d177ea334a162dc7bc286b84 (patch)
tree27fd7832b2c5956845b4593686be3d616aa20b2e /src/plugins/platforms/windows
parent5426e689f9d7d5e5e6e1a877578f17c96d248fdd (diff)
QWindow: Remove "_q_foreignWinId" dynamic property
The platform plugins reading this out of the QWindow was a layering violation, and propagates the notion that a window can shape shift into representing a new native handle, while none of the platform plugins support this. A foreign QWindow is created via the factory function fromWinId(), at which point we can pass the WId all the way to the platform plugin as function arguments, where the platform will create a corresponding platform-window. The platform window can then answer the question of whether or not it's representing a foreign window, which determines a few behavioral changes here and there, as well as supplying the native window handle back for QWindow::winId(); [ChangeLog][QtGui][QWindow] The "_q_foreignWinId" dynamic property is no longer set nor read. [ChangeLog][QtGui][QPA] The function createForeignWindow() has been added to QPlatormIntegration and is now responsible for creating foreign windows. The function isForeignWindow() in QPlatformWindow has been added, and platforms should implement this to return true for windows created by createForeignWindow(). Task-number: QTBUG-58383 Change-Id: If84142f95172f62b9377eb5d2a4d792cad36010b Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows')
-rw-r--r--src/plugins/platforms/windows/qwindowsintegration.cpp37
-rw-r--r--src/plugins/platforms/windows/qwindowsintegration.h1
-rw-r--r--src/plugins/platforms/windows/qwindowswindow.h1
3 files changed, 21 insertions, 18 deletions
diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp
index 5a3020387a..316f93e3ac 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.cpp
+++ b/src/plugins/platforms/windows/qwindowsintegration.cpp
@@ -304,24 +304,6 @@ QPlatformWindow *QWindowsIntegration::createPlatformWindow(QWindow *window) cons
return result;
}
- if (window->type() == Qt::ForeignWindow) {
- const HWND hwnd = reinterpret_cast<HWND>(window->winId());
- if (!IsWindow(hwnd)) {
- qWarning("Windows QPA: Invalid foreign window ID %p.", hwnd);
- return nullptr;
- }
- QWindowsForeignWindow *result = new QWindowsForeignWindow(window, hwnd);
- const QRect obtainedGeometry = result->geometry();
- QScreen *screen = Q_NULLPTR;
- if (const QPlatformScreen *pScreen = result->screenForGeometry(obtainedGeometry))
- screen = pScreen->screen();
- if (screen && screen != window->screen())
- window->setScreen(screen);
- qCDebug(lcQpaWindows) << "Foreign window:" << window << showbase << hex
- << result->winId() << noshowbase << dec << obtainedGeometry << screen;
- return result;
- }
-
QWindowsWindowData requested;
requested.flags = window->flags();
requested.geometry = QHighDpi::toNativePixels(window->geometry(), window);
@@ -365,6 +347,25 @@ QPlatformWindow *QWindowsIntegration::createPlatformWindow(QWindow *window) cons
return result;
}
+QPlatformWindow *QWindowsIntegration::createForeignWindow(QWindow *window, WId nativeHandle) const
+{
+ const HWND hwnd = reinterpret_cast<HWND>(nativeHandle);
+ if (!IsWindow(hwnd)) {
+ qWarning("Windows QPA: Invalid foreign window ID %p.", hwnd);
+ return nullptr;
+ }
+ QWindowsForeignWindow *result = new QWindowsForeignWindow(window, hwnd);
+ const QRect obtainedGeometry = result->geometry();
+ QScreen *screen = Q_NULLPTR;
+ if (const QPlatformScreen *pScreen = result->screenForGeometry(obtainedGeometry))
+ screen = pScreen->screen();
+ if (screen && screen != window->screen())
+ window->setScreen(screen);
+ qCDebug(lcQpaWindows) << "Foreign window:" << window << showbase << hex
+ << result->winId() << noshowbase << dec << obtainedGeometry << screen;
+ return result;
+}
+
// Overridden to return a QWindowsDirect2DWindow in Direct2D plugin.
QWindowsWindow *QWindowsIntegration::createPlatformWindowHelper(QWindow *window, const QWindowsWindowData &data) const
{
diff --git a/src/plugins/platforms/windows/qwindowsintegration.h b/src/plugins/platforms/windows/qwindowsintegration.h
index 7647b0f4a6..607203829f 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.h
+++ b/src/plugins/platforms/windows/qwindowsintegration.h
@@ -73,6 +73,7 @@ public:
bool hasCapability(QPlatformIntegration::Capability cap) const override;
QPlatformWindow *createPlatformWindow(QWindow *window) const override;
+ QPlatformWindow *createForeignWindow(QWindow *window, WId nativeHandle) const override;
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override;
QOpenGLContext::OpenGLModuleType openGLModuleType() override;
diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h
index 10cfc18dff..e541b110a6 100644
--- a/src/plugins/platforms/windows/qwindowswindow.h
+++ b/src/plugins/platforms/windows/qwindowswindow.h
@@ -171,6 +171,7 @@ public:
void raise() override { raise_sys(); }
void lower() override { lower_sys(); }
void setWindowTitle(const QString &title) override { setWindowTitle_sys(title); }
+ bool isForeignWindow() const override { return true; }
protected:
HWND handle() const override { return m_hwnd; }