From 7445d41e32e5d241b5c124b7f81c0ae31c36ffc2 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Wed, 21 Mar 2012 08:47:16 +0100 Subject: [PATCH] Cocoa: Improve window activation handling. Make Qt window activation follow the Cocoa key window, with one exception: Popup windows become the key window but not the Qt active window. Change-Id: Ic4d8685737fa3ec5c15a68b81844929370c9cd8e Reviewed-by: Bradley T. Hughes --- src/plugins/platforms/cocoa/qcocoawindow.h | 1 + src/plugins/platforms/cocoa/qcocoawindow.mm | 11 ++++++++++- src/plugins/platforms/cocoa/qnsview.mm | 8 ++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 0920bc7b4b..90c5a050d0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -111,6 +111,7 @@ public: void windowDidMove(); void windowDidResize(); void windowWillClose(); + bool windowIsPopupType() const; void setCurrentContext(QCocoaGLContext *context); QCocoaGLContext *currentContext() const; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index a76830f0b8..b4c4e31753 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -303,6 +303,15 @@ void QCocoaWindow::windowWillClose() QWindowSystemInterface::handleSynchronousCloseEvent(window()); } +bool QCocoaWindow::windowIsPopupType() const +{ + Qt::WindowType type = window()->windowType(); + if (type == Qt::Tool) + return false; // Qt::Tool has the Popup bit set but isn't, at least on Mac. + + return ((type & Qt::Popup) == Qt::Popup); +} + void QCocoaWindow::setCurrentContext(QCocoaGLContext *context) { m_glContext = context; @@ -348,7 +357,7 @@ NSWindow * QCocoaWindow::createNSWindow() // Use NSPanel for popup-type windows. (Popup, Tool, ToolTip, SplashScreen) if ((type & Qt::Popup) == Qt::Popup) { - if (type == Qt::Popup || type == Qt::ToolTip || type == Qt::SplashScreen) { + if (windowIsPopupType()) { styleMask = NSBorderlessWindowMask; } else { styleMask = (NSUtilityWindowMask | NSResizableWindowMask | NSClosableWindowMask | diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index ed67fd50fc..52f40ea01c 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -146,24 +146,24 @@ static QTouchDevice *touchDevice = 0; - (void)windowDidBecomeKey { -// QWindowSystemInterface::handleWindowActivated(m_window); + if (!m_platformWindow->windowIsPopupType()) + QWindowSystemInterface::handleWindowActivated(m_window); } - (void)windowDidResignKey { -// QWindowSystemInterface::handleWindowActivated(0); + if (!m_platformWindow->windowIsPopupType()) + QWindowSystemInterface::handleWindowActivated(0); } - (void)windowDidBecomeMain { // qDebug() << "window did become main" << m_window; - QWindowSystemInterface::handleWindowActivated(m_window); } - (void)windowDidResignMain { // qDebug() << "window did resign main" << m_window; - QWindowSystemInterface::handleWindowActivated(0); }