summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qnsview.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview.mm')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 0b9683a3ef..24a9f6fff0 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -42,6 +42,7 @@
#include <QtCore/qglobal.h>
#include <Carbon/Carbon.h>
+#include <dlfcn.h>
#include "qnsview.h"
#include "qcocoawindow.h"
@@ -65,6 +66,9 @@
static QTouchDevice *touchDevice = 0;
+// ### HACK Remove once 10.8 is unsupported
+static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
+
@interface NSEvent (Qt_Compile_Leopard_DeviceDelta)
- (CGFloat)deviceDeltaX;
- (CGFloat)deviceDeltaY;
@@ -73,6 +77,13 @@ static QTouchDevice *touchDevice = 0;
@implementation QNSView
++ (void)initialize
+{
+ NSString **notificationNameVar = (NSString **)dlsym(RTLD_NEXT, "NSWindowDidChangeOcclusionStateNotification");
+ if (notificationNameVar)
+ _q_NSWindowDidChangeOcclusionStateNotification = *notificationNameVar;
+}
+
- (id) init
{
self = [super initWithFrame : NSMakeRect(0,0, 300,300)];
@@ -192,6 +203,19 @@ static QTouchDevice *touchDevice = 0;
}
}
+- (void)viewDidMoveToWindow
+{
+ if (self.window) {
+ // This is the case of QWidgetAction's generated QWidget inserted in an NSMenu.
+ // 10.9 and newer get the NSWindowDidChangeOcclusionStateNotification
+ if (!_q_NSWindowDidChangeOcclusionStateNotification
+ && [self.window.className isEqualToString:@"NSCarbonMenuWindow"])
+ m_platformWindow->exposeWindow();
+ } else {
+ m_platformWindow->obscureWindow();
+ }
+}
+
- (void)viewWillMoveToWindow:(NSWindow *)newWindow
{
// ### Merge "normal" window code path with this one for 5.1.
@@ -325,6 +349,23 @@ static QTouchDevice *touchDevice = 0;
m_platformWindow->obscureWindow();
} else if ([notificationName isEqualToString: @"NSWindowDidOrderOnScreenAndFinishAnimatingNotification"]) {
m_platformWindow->exposeWindow();
+ } else if (_q_NSWindowDidChangeOcclusionStateNotification
+ && [notificationName isEqualToString:_q_NSWindowDidChangeOcclusionStateNotification]) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
+// ### HACK Remove the enum declaration, the warning disabling and the cast further down once 10.8 is unsupported
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-method-access"
+ enum { NSWindowOcclusionStateVisible = 1UL << 1 };
+#endif
+ // Older versions managed in -[QNSView viewDidMoveToWindow].
+ // Support QWidgetAction in NSMenu. Mavericks only sends this notification.
+ // Ideally we should support this in Qt as well, in order to disable animations
+ // when the window is occluded.
+ if ((NSUInteger)[self.window occlusionState] & NSWindowOcclusionStateVisible)
+ m_platformWindow->exposeWindow();
+#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
+#pragma clang diagnostic pop
+#endif
} else if (notificationName == NSWindowDidChangeScreenNotification) {
if (m_window) {
NSUInteger screenIndex = [[NSScreen screens] indexOfObject:self.window.screen];
@@ -637,10 +678,14 @@ static QTouchDevice *touchDevice = 0;
return [super mouseDown:theEvent];
m_sendUpAsRightButton = false;
if (m_platformWindow->m_activePopupWindow) {
+ Qt::WindowType type = m_platformWindow->m_activePopupWindow->type();
QWindowSystemInterface::handleCloseEvent(m_platformWindow->m_activePopupWindow);
QWindowSystemInterface::flushWindowSystemEvents();
m_platformWindow->m_activePopupWindow = 0;
- return;
+ // Consume the mouse event when closing the popup, except for tool tips
+ // were it's expected that the event is processed normally.
+ if (type != Qt::ToolTip)
+ return;
}
if ([self hasMarkedText]) {
NSInputManager* inputManager = [NSInputManager currentInputManager];