From c8f4d5e6692c843f55ac9de65ea0b8d161310b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Thu, 18 Jun 2020 10:58:50 +0200 Subject: [PATCH] Fix MacReopenApp() in presence of hidden windows wxOSX's wxApp::MacReopenApp() previously contained logic to unhide hidden windows, but this code was commended out since 2013 as problematic - it was showing windows like closed, but not yet destroyed, non-modal dialogs. Unfortunately while this part was commented out, the rest of the code that handled existence of hidden windows was not, resulting in a bug where nothing happened after clicking app icon in the Dock if the application didn't have any visible window at the moment, but had a "technical" hidden one, e.g. after opening and closing wxPreferencesEditor. Fixed by simplyfing and removing all (functionally commented-out) code related to hidden windows. Instead, the logic is now: 1. do nothing if some window is already visible 2. restore an iconized window if there's one 3. call MacNewFile() if neither happened --- src/osx/carbon/app.cpp | 65 ++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index 52be0397ec..72dfd06312 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -157,50 +157,39 @@ void wxApp::MacReopenApp() // if there is no open window -> create a new one // if all windows are hidden -> show the first // if some windows are not hidden -> do nothing + // + // Showing hidden windows is not really always a good solution, also non-modal dialogs when closed end up + // as hidden TLWs, so do preferences and some classes like wxTaskBarIconWindow use placeholder TLWs. + // We don't want to reshow those, so let's just reopen the minimized a.k.a. iconized TLWs. + wxTopLevelWindow* firstIconized = NULL; wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); - if ( !node ) - { - MacNewFile() ; - } - else - { - wxTopLevelWindow* firstIconized = NULL ; - wxTopLevelWindow* firstHidden = NULL ; - while (node) - { - wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData(); - if ( !win->IsShown() ) - { - // make sure we don't show 'virtual toplevel windows' like wxTaskBarIconWindow - if ( firstHidden == NULL && ( wxDynamicCast( win, wxFrame ) || wxDynamicCast( win, wxDialog ) ) ) - firstHidden = win ; - } - else if ( win->IsIconized() ) - { - if ( firstIconized == NULL ) - firstIconized = win ; - } - else - { - // we do have a visible, non-iconized toplevelwindow -> do nothing - return; - } - node = node->GetNext(); + while (node) + { + wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData(); + if ( win->IsShown() ) + { + // we do have a visible, non-iconized toplevelwindow -> do nothing + return; + } + else if ( win->IsIconized() ) + { + if ( firstIconized == NULL ) + firstIconized = win; } - if ( firstIconized ) - firstIconized->Iconize( false ) ; - - // showing hidden windows is not really always a good solution, also non-modal dialogs when closed end up - // as hidden tlws, we don't want to reshow those, so let's just reopen the minimized a.k.a. iconized tlws - // unless we find a regression ... -#if 0 - else if ( firstHidden ) - firstHidden->Show( true ); -#endif + node = node->GetNext(); } + + if ( firstIconized ) + { + firstIconized->Iconize(false); + return; + } + + // no window was shown, we need to create a new one + MacNewFile(); } #if wxOSX_USE_COCOA_OR_IPHONE