From 4ffad5074f744bfe38c5c5ed728da591162b90a5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Oct 2023 17:36:54 +0200 Subject: [PATCH] Add WXSUPPRESS_GTK_DIAGNOSTICS environment variable This allows to suppress some or all GTK diagnostics even for the programs not calling GTKSuppressDiagnostics() nor even GTKAllowDiagnosticsControl() themselves. --- docs/doxygen/overviews/envvars.h | 6 ++++++ interface/wx/app.h | 5 +++++ src/gtk/app.cpp | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/docs/doxygen/overviews/envvars.h b/docs/doxygen/overviews/envvars.h index 051f1dfec3..7b6386d8e4 100644 --- a/docs/doxygen/overviews/envvars.h +++ b/docs/doxygen/overviews/envvars.h @@ -45,6 +45,12 @@ wxWidgets programs. This can be helpful when running older programs recompiled with wxWidgets 3.1 or later, as these asserts are mostly harmless and can be safely ignored if the code works as expected.} +@itemdef{WXSUPPRESS_GTK_DIAGNOSTICS, + If set to a non-zero value, wxApp::GTKSuppressDiagnostics() is called + on program startup using the numeric value of this variable or the + default value if it's not a number, so that e.g. setting it to "yes" + suppresses all GTK diagnostics while setting it to 16 only suppresses + GTK warning messages.} */ @see wxSystemOptions diff --git a/interface/wx/app.h b/interface/wx/app.h index da2a863b9b..b27e504fcb 100644 --- a/interface/wx/app.h +++ b/interface/wx/app.h @@ -1042,6 +1042,11 @@ public: This function can be called to suppress GTK diagnostic messages that are output on the standard error stream by default. + If @c WXSUPPRESS_GTK_DIAGNOSTICS environment variable is set to a + non-zero value, wxWidgets automatically calls this function on program + startup with the value of this variable as @a flags if it's a number or + with the default flags value otherwise. + The default value of the argument disables all messages, but you can pass in a mask flag to specifically disable only particular categories of messages. diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 8c092e7bba..8537b4f8cf 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -392,6 +392,19 @@ bool wxApp::OnInitGui() } #endif + // Suppress GTK diagnostics if requested: this is convenient if the program + // doesn't use GTKAllowDiagnosticsControl() itself. + wxString suppress; + if ( wxGetEnv("WXSUPPRESS_GTK_DIAGNOSTICS", &suppress) ) + { + long flags; + if ( !suppress.ToLong(&flags) ) + flags = -1; // Suppress everything by default. + + if ( flags != 0 ) + GTKSuppressDiagnostics(flags); + } + return true; }