3434#include " custom_metatypes.h"
3535#include " absl/debugging/failure_signal_handler.h"
3636#include " absl/debugging/symbolize.h"
37+ #include " absl/flags/flag.h"
38+ #include " absl/flags/parse.h"
39+ #include " absl/flags/usage.h"
40+ #include " absl/flags/usage_config.h"
3741#include " dive/os/terminal.h"
3842#ifdef __linux__
3943# include < dlfcn.h>
4852constexpr int kSplashScreenDuration = 2000 ; // 2s
4953constexpr int kStartDelay = 500 ; // 0.5s
5054
55+ ABSL_FLAG (bool , test_exit_after_load, false , " Test file loading" );
56+ ABSL_FLAG (bool , native_style, false , " Use system provided style" );
57+
58+ // QApplication flags:
59+ ABSL_RETIRED_FLAG (std::string, style, " " , " Set the application GUI style" );
60+ ABSL_RETIRED_FLAG (std::string, stylesheet, " " , " Set the application stylesheet" );
61+ ABSL_RETIRED_FLAG (bool , widgetcount, false , " Qt flag widgetcount" );
62+ ABSL_RETIRED_FLAG (bool , reverse, false , " Qt flag reverse" );
63+ ABSL_RETIRED_FLAG (std::string, qmljsdebugger, " " , " Qt flag qmljsdebugger" );
64+
5165// --------------------------------------------------------------------------------------------------
5266class CrashHandler
5367{
@@ -208,9 +222,22 @@ void SetDarkMode(QApplication &app)
208222 QApplication::setPalette (darkPalette);
209223}
210224
225+ // --------------------------------------------------------------------------------------------------
226+ auto SetupFlags (int argc, char **argv)
227+ {
228+ absl::FlagsUsageConfig flags_usage_config;
229+ flags_usage_config.version_string = Dive::GetCompleteVersionString;
230+ absl::SetFlagsUsageConfig (flags_usage_config);
231+ absl::SetProgramUsageMessage (" Dive GPU Profiler GUI" );
232+ return absl::ParseCommandLine (argc, argv);
233+ }
234+
211235// --------------------------------------------------------------------------------------------------
212236int main (int argc, char *argv[])
213237{
238+ Dive::AttachToTerminalOutputIfAvailable ();
239+ std::vector<char *> positional_args = SetupFlags (argc, argv);
240+
214241 absl::InitializeSymbolizer (argv[0 ]);
215242
216243 CrashHandler::Initialize (argv[0 ]);
@@ -219,41 +246,23 @@ int main(int argc, char *argv[])
219246 options.writerfn = CrashHandler::Writer;
220247 absl::InstallFailureSignalHandler (options);
221248
222- // Check number of arguments
223- bool exit_after_load = false ;
224- if (argc > 1 && strcmp (argv[1 ], " --exit-after-load" ) == 0 )
249+ const bool native_style = absl::GetFlag (FLAGS_native_style);
250+ if (!native_style)
225251 {
226- exit_after_load = true ;
227- argc--;
228- argv++;
229- }
230- if (argc != 1 && argc != 2 )
231- return 0 ;
252+ // Optional command arg loading method for fast iteration
253+ // Note: Set the style *before* QApplication constructor. This allows commandline
254+ // "-style <style>" style override to still work properly.
232255
233- Dive::AttachToTerminalOutputIfAvailable ();
234-
235- // Print version info if asked to on the command line.
236- // This will only work on linux as we are a UI app on Windows.
237- // On Windows, users can right-click the .exe and look at Properties/Details.
238- if (argc > 1 && strcasecmp (argv[1 ], " --version" ) == 0 )
239- {
240- std::cout << Dive::GetDiveDescription () << std::endl;
241- return 0 ;
242- }
243-
244- // Optional command arg loading method for fast iteration
245- // Note: Set the style *before* QApplication constructor. This allows commandline
246- // "-style <style>" style override to still work properly.
247-
248- // Try setting "Fusion" style. If not found, set "Windows".
249- // And if that's not found, default to whatever style the factory provides.
250- if (!SetApplicationStyle (" Fusion" ))
251- {
252- if (!SetApplicationStyle (" Windows" ))
256+ // Try setting "Fusion" style. If not found, set "Windows".
257+ // And if that's not found, default to whatever style the factory provides.
258+ if (!SetApplicationStyle (" Fusion" ))
253259 {
254- if (!QStyleFactory::keys (). empty ( ))
260+ if (!SetApplicationStyle ( " Windows " ))
255261 {
256- SetApplicationStyle (QStyleFactory::keys ()[0 ]);
262+ if (!QStyleFactory::keys ().empty ())
263+ {
264+ SetApplicationStyle (QStyleFactory::keys ()[0 ]);
265+ }
257266 }
258267 }
259268 }
@@ -263,13 +272,17 @@ int main(int argc, char *argv[])
263272 QApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
264273 QApplication app (argc, argv);
265274 app.setWindowIcon (QIcon (" :/images/dive.ico" ));
266- SetDarkMode (app);
267275
268- // Load and apply the style sheet
269- QFile style_sheet (" :/stylesheet.qss" );
270- style_sheet.open (QFile::ReadOnly);
271- QString style (style_sheet.readAll ());
272- app.setStyleSheet (style);
276+ if (!native_style)
277+ {
278+ SetDarkMode (app);
279+
280+ // Load and apply the style sheet
281+ QFile style_sheet (" :/stylesheet.qss" );
282+ style_sheet.open (QFile::ReadOnly);
283+ QString style (style_sheet.readAll ());
284+ app.setStyleSheet (style);
285+ }
273286
274287 // Display splash screen
275288 QSplashScreen *splash_screen = new QSplashScreen ();
@@ -281,7 +294,7 @@ int main(int argc, char *argv[])
281294
282295 ApplicationController controller;
283296 MainWindow *main_window = new MainWindow (controller);
284- if (exit_after_load )
297+ if (absl::GetFlag (FLAGS_test_exit_after_load) )
285298 {
286299 QObject::connect (main_window, &MainWindow::FileLoaded, main_window, &MainWindow::close);
287300 }
@@ -292,10 +305,10 @@ int main(int argc, char *argv[])
292305 << " Application: Plugin initialization failed. Application may proceed without plugins." ;
293306 }
294307
295- if (argc == 2 )
308+ if (positional_args. size () == 2 )
296309 {
297310 // This is executed async.
298- main_window->LoadFile (argv[ 1 ] , false , true );
311+ main_window->LoadFile (positional_args. back () , false , true );
299312 }
300313
301314 QTimer::singleShot (kSplashScreenDuration , splash_screen, SLOT (close ()));
0 commit comments