1
0
Fork 0

Add —disable-gui option

Prevents showing a GUI message box if the user wants to run from the
console.

As requested here:
   https://sourceforge.net/p/flightgear/codetickets/2306/
This commit is contained in:
James Turner 2020-07-14 12:05:53 +01:00
parent f9e9dbf309
commit 54264e6591
6 changed files with 41 additions and 8 deletions

View file

@ -43,6 +43,8 @@ using namespace simgear::strutils;
namespace { namespace {
static bool static_isHeadless = false;
bool isCanvasImplementationRegistered() bool isCanvasImplementationRegistered()
{ {
if (!globals) { if (!globals) {
@ -107,12 +109,22 @@ win32MessageBox(const std::string& caption,
namespace flightgear namespace flightgear
{ {
void setHeadlessMode(bool headless)
{
static_isHeadless = headless;
}
bool isHeadlessMode()
{
return static_isHeadless;
}
MessageBoxResult modalMessageBox(const std::string& caption, MessageBoxResult modalMessageBox(const std::string& caption,
const std::string& msg, const std::string& msg,
const std::string& moreText) const std::string& moreText)
{ {
// Headless mode. // Headless mode.
if (globals->is_headless()) { if (static_isHeadless) {
SG_LOG(SG_HEADLESS, SG_ALERT, "ModalMessageBox Caption: \"" << caption << "\""); SG_LOG(SG_HEADLESS, SG_ALERT, "ModalMessageBox Caption: \"" << caption << "\"");
SG_LOG(SG_HEADLESS, SG_ALERT, "ModalMessageBox Message: \"" << msg << "\""); SG_LOG(SG_HEADLESS, SG_ALERT, "ModalMessageBox Message: \"" << msg << "\"");
if (!moreText.empty()) if (!moreText.empty())
@ -161,6 +173,15 @@ MessageBoxResult fatalMessageBoxWithoutExit(const std::string& caption,
const std::string& msg, const std::string& msg,
const std::string& moreText) const std::string& moreText)
{ {
// Headless mode.
if (static_isHeadless) {
SG_LOG(SG_HEADLESS, SG_ALERT, "Fatal Error: \"" << caption << "\"");
SG_LOG(SG_HEADLESS, SG_ALERT, "Error Message: \"" << msg << "\"");
if (!moreText.empty())
SG_LOG(SG_HEADLESS, SG_ALERT, "\tMore text: \"" << moreText << "\"");
return MSG_BOX_OK;
}
#if defined(SG_WINDOWS) #if defined(SG_WINDOWS)
return win32MessageBox(caption, msg, moreText); return win32MessageBox(caption, msg, moreText);
#elif defined(SG_MAC) #elif defined(SG_MAC)

View file

@ -7,6 +7,10 @@
namespace flightgear namespace flightgear
{ {
// set a global value indicating we're in headless mode.
void setHeadlessMode(bool headless);
bool isHeadlessMode();
// special exception class used to signal an exit. Must not inherit // special exception class used to signal an exit. Must not inherit
// std::exception or similar, since we want to handle it specially // std::exception or similar, since we want to handle it specially
class FatalErrorException class FatalErrorException

View file

@ -233,6 +233,12 @@ int _bootstrap_OSInit;
// Main entry point; catch any exceptions that have made it this far. // Main entry point; catch any exceptions that have made it this far.
int main ( int argc, char **argv ) int main ( int argc, char **argv )
{ {
// we don't want to accidently show a GUI box and block startup in
// non_GUI setups, so check this value early here, before options are
// processed
const bool headless = flightgear::Options::checkForArg(argc, argv, "disable-gui");
flightgear::setHeadlessMode(headless);
#ifdef ENABLE_SIMD #ifdef ENABLE_SIMD
if (!detectSIMD()) { if (!detectSIMD()) {
flightgear::fatalMessageBoxThenExit( flightgear::fatalMessageBoxThenExit(

View file

@ -165,8 +165,7 @@ FGGlobals::FGGlobals() :
channel_options_list( NULL ), channel_options_list( NULL ),
initial_waypoints( NULL ), initial_waypoints( NULL ),
channellist( NULL ), channellist( NULL ),
haveUserSettings(false), haveUserSettings(false)
_headless(false)
{ {
SGPropertyNode* root = new SGPropertyNode; SGPropertyNode* root = new SGPropertyNode;
props = SGPropertyNode_ptr(root); props = SGPropertyNode_ptr(root);
@ -951,12 +950,12 @@ void FGGlobals::setPackageRoot(const SGSharedPtr<simgear::pkg::Root>& p)
bool FGGlobals::is_headless() bool FGGlobals::is_headless()
{ {
return _headless; return flightgear::isHeadlessMode();
} }
void FGGlobals::set_headless(bool mode) void FGGlobals::set_headless(bool mode)
{ {
_headless = mode; flightgear::setHeadlessMode(mode);
} }
// end of globals.cxx // end of globals.cxx

View file

@ -159,8 +159,6 @@ private:
SGSharedPtr<simgear::pkg::Root> _packageRoot; SGSharedPtr<simgear::pkg::Root> _packageRoot;
bool _headless;
public: public:
FGGlobals(); FGGlobals();

View file

@ -1600,7 +1600,11 @@ fgOptLoadTape(const char* arg)
return FG_OPTIONS_OK; return FG_OPTIONS_OK;
} }
static int fgOptDisableGUI(const char*)
{
globals->set_headless(true);
return FG_OPTIONS_OK;
}
/* /*
option has_param type property b_param s_param func option has_param type property b_param s_param func
@ -1865,6 +1869,7 @@ struct OptionDesc {
{"load-tape", true, OPTION_FUNC, "", false, "", fgOptLoadTape }, {"load-tape", true, OPTION_FUNC, "", false, "", fgOptLoadTape },
{"developer", true, OPTION_IGNORE | OPTION_BOOL, "", false, "", nullptr }, {"developer", true, OPTION_IGNORE | OPTION_BOOL, "", false, "", nullptr },
{"jsbsim-output-directive-file", true, OPTION_STRING, "/sim/jsbsim/output-directive-file", false, "", nullptr }, {"jsbsim-output-directive-file", true, OPTION_STRING, "/sim/jsbsim/output-directive-file", false, "", nullptr },
{"disable-gui", false, OPTION_FUNC, "", false, "", fgOptDisableGUI },
{nullptr, false, 0, nullptr, false, nullptr, nullptr} {nullptr, false, 0, nullptr, false, nullptr, nullptr}
}; };