Windows: Fix embedded application not getting focus after clicking outside

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