DragController: Work with MFC windows too

A MFC window with an embedded QMainWindow doesn't appear in
topLevelWindows(), so we need an extra check.
This commit is contained in:
Sergio Martins
2019-07-03 15:10:12 +01:00
parent 9fc631a589
commit ca8a72d304

View File

@@ -29,6 +29,7 @@
#include <QMouseEvent>
#include <QApplication>
#include <QCursor>
#include <QWindow>
#if defined(Q_OS_WIN)
# include <Windows.h>
@@ -342,8 +343,20 @@ QWidget *DragController::qtTopLevelUnderCursor() const
return tl;
}
} else {
// Maybe it's embedded in a QWinWidget:
for (auto topLevel : topLevels) {
if (QLatin1String(topLevel->metaObject()->className()) == QLatin1String("QWinWidget")) {
if (hwnd == GetParent((HWND)topLevel->windowHandle()->winId())) {
if (topLevel->geometry().contains(globalPos) && topLevel->objectName() != QStringLiteral("_docks_IndicatorWindow_Overlay")) {
qCDebug(toplevels) << Q_FUNC_INFO << "Found top-level" << topLevel;
return topLevel;
}
}
}
}
// A window belonging to another app is below the cursor
qCDebug(toplevels) << Q_FUNC_INFO << "Window from another app is under cursor";
qCDebug(toplevels) << Q_FUNC_INFO << "Window from another app is under cursor" << hwnd;
return nullptr;
}
}