Windows: Fix embedded application not getting focus after clicking outside

Amend the check introduced by bde6a049494f40cd71004d6926899f115af0c3e6
to not apply to embedded windows and plugin applications.

Fixes: QTBUG-71991
Task-number: QTBUG-7081
Change-Id: I80b3dc0fa20ee3447a4bc4bbb41e66d4d90ab726
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Friedemann Kleint 2018-11-23 13:23:28 +01:00
parent 36f3eeaf3e
commit 70d131af33

View File

@ -6592,20 +6592,25 @@ QWidget *QWidgetPrivate::deepestFocusProxy() const
return focusProxy; return focusProxy;
} }
static inline bool isEmbedded(const QWindow *w)
{
const auto platformWindow = w->handle();
return platformWindow && platformWindow->isEmbedded();
}
void QWidgetPrivate::setFocus_sys() void QWidgetPrivate::setFocus_sys()
{ {
Q_Q(QWidget); Q_Q(QWidget);
// Embedded native widget may have taken the focus; get it back to toplevel // Embedded native widget may have taken the focus; get it back to toplevel
// if that is the case (QTBUG-25852) // if that is the case (QTBUG-25852)
const QWidget *topLevel = q->window(); // Do not activate in case the popup menu opens another application (QTBUG-70810)
// Do not activate in case the popup menu opens another application (QTBUG-70810). // unless the application is embedded (QTBUG-71991).
if (QGuiApplication::applicationState() == Qt::ApplicationActive if (QWindow *nativeWindow = q->testAttribute(Qt::WA_WState_Created) ? q->window()->windowHandle() : nullptr) {
&& topLevel->windowType() != Qt::Popup) { if (nativeWindow->type() != Qt::Popup && nativeWindow != QGuiApplication::focusWindow()
if (QWindow *nativeWindow = q->window()->windowHandle()) { && (QGuiApplication::applicationState() == Qt::ApplicationActive
if (nativeWindow != QGuiApplication::focusWindow() || QCoreApplication::testAttribute(Qt::AA_PluginApplication)
&& q->testAttribute(Qt::WA_WState_Created)) { || isEmbedded(nativeWindow))) {
nativeWindow->requestActivate(); nativeWindow->requestActivate();
}
} }
} }
} }