Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ int main( int argc, char** argv )
return 0;
}

mainWindow->show();
mainWindow->launch();

app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
Expand Down
38 changes: 19 additions & 19 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down Expand Up @@ -667,6 +667,24 @@ bool MainWindow::parseCmdLineArgs( const QStringList& args, bool from_another_ap
}
}

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
//
// 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();
}

if ( force_background || do_autotest )
showMinimized();
else if ( isMinimized() )
showNormal();
else
show();

// Opening the file?
if ( !filename.isEmpty() )
{
Expand Down Expand Up @@ -704,28 +722,10 @@ 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();
}

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;
}

Expand Down