macOS: Deliver focus change events for foreign windows

If a foreign window becomes or loses focus window status, we should
let QGuiApplication know about it.

Task-number: QTBUG-119287
Change-Id: I550d72fa13e1c38c9b89880857db9f9cbd7f6568
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 75a5605151d203fb4c2269001dddfd3db121ea2e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2023-12-07 17:54:27 +01:00 committed by Qt Cherry-pick Bot
parent 3092406d79
commit 122b4c21a0

View File

@ -1246,16 +1246,13 @@ void QCocoaWindow::windowDidEndLiveResize()
void QCocoaWindow::windowDidBecomeKey()
{
if (isForeignWindow())
return;
// The NSWindow we're part of become key. Check if we're the first
// responder, and if so, deliver focus window change to our window.
if (m_view.window.firstResponder != m_view)
return;
qCDebug(lcQpaWindow) << m_view.window << "became key window."
<< "Updating focus window to" << this;
<< "Updating focus window to" << this << "with view" << m_view;
if (windowIsPopupType()) {
qCDebug(lcQpaWindow) << "Window is popup. Skipping focus window change.";
@ -1269,16 +1266,13 @@ void QCocoaWindow::windowDidBecomeKey()
void QCocoaWindow::windowDidResignKey()
{
if (isForeignWindow())
return;
// The NSWindow we're part of lost key. Check if we're the first
// responder, and if so, deliver window deactivation to our window.
if (m_view.window.firstResponder != m_view)
return;
qCDebug(lcQpaWindow) << m_view.window << "resigned key window."
<< "Clearing focus window" << this;
<< "Clearing focus window" << this << "with view" << m_view;
// Make sure popups are closed before we deliver activation changes, which are
// otherwise ignored by QApplication.