From d9c149dbc2021ed1e82cd34ae30dfd39f7d82a8d Mon Sep 17 00:00:00 2001 From: Jens Trillmann Date: Mon, 12 Mar 2018 12:06:05 +0100 Subject: [PATCH] Fix reopening on macOS When a user reopens an application while the application is already running, then macOS does not run the application a second time but sends kAEReopenApplication to inform the running instance. Qt ignores this event and the application does not open. To handle this event a new event handler is registered. The application state is set to Qt::ApplicationActive when the handler is called. An application that wants to react to reopening has to react to QEvent::ApplicationActivate in the running QApplication. Change-Id: Ic3adeb6b334c85f36671c254657170c71a2dfb59 --- src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git x/qtbase/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm y/qtbase/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index a94e0dc517..ccf16addea 100644 --- x/qtbase/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ y/qtbase/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -259,6 +259,10 @@ - (void) applicationWillFinishLaunching:(NSNotification *)notification andSelector:@selector(appleEventQuit:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; + [eventManager setEventHandler:self + andSelector:@selector(appleEventReopen:withReplyEvent:) + forEventClass:kCoreEventClass + andEventID:kAEReopenApplication]; [eventManager setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass @@ -438,4 +442,11 @@ - (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEv [NSApp terminate:self]; } +- (void)appleEventReopen:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent +{ + Q_UNUSED(event); + Q_UNUSED(replyEvent); + QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive, true); +} + @end -- 2.14.3 (Apple Git-98)