diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qnswindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnswindow.mm | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index cb13b7d184..1b9dd95cbc 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -38,7 +38,6 @@ ****************************************************************************/ #include "qnswindow.h" -#include "qnswindowdelegate.h" #include "qcocoawindow.h" #include "qcocoahelpers.h" #include "qcocoaeventdispatcher.h" @@ -46,18 +45,18 @@ #include <qpa/qwindowsysteminterface.h> #include <qoperatingsystemversion.h> -Q_LOGGING_CATEGORY(lcCocoaEvents, "qt.qpa.cocoa.events"); +Q_LOGGING_CATEGORY(lcQpaEvents, "qt.qpa.events"); static bool isMouseEvent(NSEvent *ev) { switch ([ev type]) { - case NSLeftMouseDown: - case NSLeftMouseUp: - case NSRightMouseDown: - case NSRightMouseUp: - case NSMouseMoved: - case NSLeftMouseDragged: - case NSRightMouseDragged: + case NSEventTypeLeftMouseDown: + case NSEventTypeLeftMouseUp: + case NSEventTypeRightMouseDown: + case NSEventTypeRightMouseUp: + case NSEventTypeMouseMoved: + case NSEventTypeLeftMouseDragged: + case NSEventTypeRightMouseDragged: return true; default: return false; @@ -72,7 +71,7 @@ static bool isMouseEvent(NSEvent *ev) [center addObserverForName:NSWindowDidEnterFullScreenNotification object:nil queue:nil usingBlock:^(NSNotification *notification) { objc_setAssociatedObject(notification.object, @selector(qt_fullScreen), - [NSNumber numberWithBool:YES], OBJC_ASSOCIATION_RETAIN); + @(YES), OBJC_ASSOCIATION_RETAIN); } ]; [center addObserverForName:NSWindowDidExitFullScreenNotification object:nil queue:nil @@ -187,22 +186,22 @@ static bool isMouseEvent(NSEvent *ev) /*! Borderless windows need a transparent background - Technically windows with NSTexturedBackgroundWindowMask (such - as windows with unified toolbars) need to draw the textured + Technically windows with NSWindowStyleMaskTexturedBackground + (such as windows with unified toolbars) need to draw the textured background of the NSWindow, and can't have a transparent - background, but as NSBorderlessWindowMask is 0, you can't - have a window with NSTexturedBackgroundWindowMask that is + background, but as NSWindowStyleMaskBorderless is 0, you can't + have a window with NSWindowStyleMaskTexturedBackground that is also borderless. */ - (NSColor *)backgroundColor { - return self.styleMask == NSBorderlessWindowMask + return self.styleMask == NSWindowStyleMaskBorderless ? [NSColor clearColor] : qt_objcDynamicSuper(); } - (void)sendEvent:(NSEvent*)theEvent { - qCDebug(lcCocoaEvents) << "Sending" << theEvent << "to" << self; + qCDebug(lcQpaEvents) << "Sending" << theEvent << "to" << self; // We might get events for a NSWindow after the corresponding platform // window has been deleted, as the NSWindow can outlive the QCocoaWindow @@ -239,7 +238,7 @@ static bool isMouseEvent(NSEvent *ev) - (void)closeAndRelease { - qCDebug(lcQpaCocoaWindow) << "closeAndRelease" << self; + qCDebug(lcQpaWindow) << "closeAndRelease" << self; [self.delegate release]; self.delegate = nil; @@ -252,7 +251,7 @@ static bool isMouseEvent(NSEvent *ev) #pragma clang diagnostic ignored "-Wobjc-missing-super-calls" - (void)dealloc { - qCDebug(lcQpaCocoaWindow) << "dealloc" << self; + qCDebug(lcQpaWindow) << "dealloc" << self; qt_objcDynamicSuper(); } #pragma clang diagnostic pop @@ -263,29 +262,20 @@ static bool isMouseEvent(NSEvent *ev) NSEnumerator<NSWindow*> *windowEnumerator = nullptr; NSApplication *application = [NSApplication sharedApplication]; -#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_12) - if (__builtin_available(macOS 10.12, *)) { - // Unfortunately there's no NSWindowListOrderedBackToFront, - // so we have to manually reverse the order using an array. - NSMutableArray *windows = [[[NSMutableArray alloc] init] autorelease]; - [application enumerateWindowsWithOptions:NSWindowListOrderedFrontToBack - usingBlock:^(NSWindow *window, BOOL *) { - // For some reason AppKit will give us nil-windows, skip those - if (!window) - return; - - [(NSMutableArray*)windows addObject:window]; - } - ]; - - windowEnumerator = windows.reverseObjectEnumerator; - } else -#endif - { - // No way to get ordered list of windows, so fall back to unordered, - // list, which typically corresponds to window creation order. - windowEnumerator = application.windows.objectEnumerator; - } + // Unfortunately there's no NSWindowListOrderedBackToFront, + // so we have to manually reverse the order using an array. + NSMutableArray<NSWindow *> *windows = [NSMutableArray<NSWindow *> new]; + [application enumerateWindowsWithOptions:NSWindowListOrderedFrontToBack + usingBlock:^(NSWindow *window, BOOL *) { + // For some reason AppKit will give us nil-windows, skip those + if (!window) + return; + + [windows addObject:window]; + } + ]; + + windowEnumerator = windows.reverseObjectEnumerator; for (NSWindow *window in windowEnumerator) { // We're meddling with normal and floating windows, so leave others alone |