From 2d6e75fdfc601bff7db6e68a1c8b73cc86cedc77 Mon Sep 17 00:00:00 2001 From: Binhao Qian Date: Wed, 21 Jan 2026 00:14:21 +0800 Subject: [PATCH 1/2] Fix start minimized. --- src/main.cpp | 1 - src/mainwindow.cpp | 31 +++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 639ca746..ae9df79d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -152,7 +152,6 @@ int main( int argc, char** argv ) return 0; } - mainWindow->show(); mainWindow->launch(); app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index db3e39f8..31aa4f6f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -667,6 +667,23 @@ bool MainWindow::parseCmdLineArgs( const QStringList& args, bool from_another_ap } } + if ( force_background ) + showMinimized(); + else + show(); + + if ( from_another_app ) + { + // On Windows it is not possible to activate the window of a non-active process. From MSDN: + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx + // + // An application cannot force a window to the foreground while the user is working with another window. + // Instead, Windows flashes the taskbar button of the window to notify the user. + activateWindow(); + raise(); + show(); + } + // Opening the file? if ( !filename.isEmpty() ) { @@ -712,20 +729,6 @@ bool MainWindow::parseCmdLineArgs( const QStringList& args, bool from_another_ap runAutoTest(); } - if ( force_background ) - showMinimized(); - else if ( from_another_app ) - { - // On Windows it is not possible to activate the window of a non-active process. From MSDN: - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx - // - // An application cannot force a window to the foreground while the user is working with another window. - // Instead, Windows flashes the taskbar button of the window to notify the user. - activateWindow(); - raise(); - show(); - } - return true; } From df1557ac2474d07f5f55ba06d7b18649ef352a4b Mon Sep 17 00:00:00 2001 From: Binhao Qian Date: Sat, 31 Jan 2026 22:14:59 +0800 Subject: [PATCH 2/2] Adjust logic for calling show* functions. --- src/mainwindow.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 31aa4f6f..b0d4a5f1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -197,7 +197,7 @@ bool MainWindow::hasSameTokenInstance() QString token; // argv[0] in Qt is still a program name - for ( int i = 1; i < m_arguments.size(); i++ ) + for ( int i = 1; i < m_arguments.size() - 1; i++ ) { // This is not bulletproof (think -showPage -token) but this is not likely to happen if ( m_arguments[i] == "-token" ) @@ -667,12 +667,7 @@ bool MainWindow::parseCmdLineArgs( const QStringList& args, bool from_another_ap } } - if ( force_background ) - showMinimized(); - else - show(); - - if ( from_another_app ) + if ( from_another_app && !force_background && !do_autotest ) { // On Windows it is not possible to activate the window of a non-active process. From MSDN: // https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx @@ -681,9 +676,15 @@ bool MainWindow::parseCmdLineArgs( const QStringList& args, bool from_another_ap // Instead, Windows flashes the taskbar button of the window to notify the user. activateWindow(); raise(); - show(); } + if ( force_background || do_autotest ) + showMinimized(); + else if ( isMinimized() ) + showNormal(); + else + show(); + // Opening the file? if ( !filename.isEmpty() ) { @@ -721,11 +722,7 @@ bool MainWindow::parseCmdLineArgs( const QStringList& args, bool from_another_ap if ( do_autotest ) { - if ( filename.isEmpty() ) - qFatal( "Could not use Auto Test mode without a chm file!" ); - m_autoteststate = STATE_INITIAL; - showMinimized(); runAutoTest(); }