From 49154acde3c2c5f45a50dfd5d011c47db8b761f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 11 Sep 2017 14:04:51 +0200 Subject: macOS: Deliver NSWindow notifications to all windows, not just top level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Child QWindows (or in the case of QWindows embedded in native applications: top level QWindows where the corresponding NSView is a child of another view, so not being the contentView of its window), still need some of the NSWindow notifications to e.g. update their exposed state when the window becomes visible. We make sure to send the notification to all QCococaWindow children of the relevant NSWindow, and let each callback decide if it should only apply to content views. This fixes an issue where a QWindow would never be exposed if the window was a child NSView and added to a NSWindow that was yet to be shown. Change-Id: I7f7df8bc5f4ca3ac553a2c146f8c3229b197c059 Reviewed-by: Morten Johan Sørvig --- tests/manual/cocoa/qt_on_cocoa/main.mm | 13 ++++++++----- tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'tests/manual') diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm index 5e3b8fcd39..805ef0d7c2 100644 --- a/tests/manual/cocoa/qt_on_cocoa/main.mm +++ b/tests/manual/cocoa/qt_on_cocoa/main.mm @@ -87,8 +87,6 @@ options:NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | NSTrackingCursorUpdate owner:contentView userInfo:nil]]; - window.contentView = contentView; - // Create the QWindow, add its NSView to the content view m_window = new RasterWindow; m_window->setObjectName("RasterWindow"); @@ -104,10 +102,15 @@ NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 80, 25)]; [(NSView*)childWindow->winId() addSubview:textField]; - [window.contentView addSubview:reinterpret_cast(m_window->winId())]; + [contentView addSubview:reinterpret_cast(m_window->winId())]; + + window.contentView = contentView; - // Show the NSWindow - [window makeKeyAndOrderFront:NSApp]; + // Show the NSWindow delayed, so that we can verify that Qt picks up the right + // notifications to expose the window when it does become visible. + dispatch_async(dispatch_get_main_queue(), ^{ + [window makeKeyAndOrderFront:NSApp]; + }); } - (void)applicationWillTerminate:(NSNotification *)notification diff --git a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp index dca39839dd..6d7cb3e305 100644 --- a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp +++ b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp @@ -148,6 +148,11 @@ bool RasterWindow::event(QEvent *e) void RasterWindow::render() { + if (!isExposed()) { + qDebug() << "Skipping render, not exposed"; + return; + } + QRect rect(QPoint(), geometry().size()); m_backingStore->resize(rect.size()); -- cgit v1.2.3