From 008f0d55c3646597a5f33eec5f5f2db41917f801 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 19 Mar 2021 22:05:00 +0000 Subject: [PATCH] Add an interceptor for GTK error messages to hide them wxWidgets seems to cause GTK to spam messages to the terminal, and we have no control over that. So lets hide the messages so no one complains about them. If people really want to see them, they can add the KICAD_SHOW_GTK_MESSAGES build flag to CMake and they can watch them scroll past. --- libs/kiplatform/CMakeLists.txt | 19 +++++++++++++++++++ libs/kiplatform/gtk/app.cpp | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/libs/kiplatform/CMakeLists.txt b/libs/kiplatform/CMakeLists.txt index 3a19621b1e..791f965fee 100644 --- a/libs/kiplatform/CMakeLists.txt +++ b/libs/kiplatform/CMakeLists.txt @@ -1,3 +1,11 @@ +option( KICAD_SHOW_GTK_MESSAGES + "Show all the GTK error messages in the terminal" + OFF ) + +mark_as_advanced( KICAD_SHOW_GTK_MESSAGES ) + +set( PLATFORM_COMPILE_DEFS "" ) + # Add the appropriate source files if( APPLE ) set( PLATFORM_SRCS @@ -40,6 +48,13 @@ elseif( UNIX ) include_directories( SYSTEM ${GTK3_INCLUDE_DIRS} ) link_directories( ${GTK3_LIBRARY_DIRS} ) add_definitions( ${GTK3_CFLAGS_OTHER} ) + + # Add the definition to show the GTK error messages if desired (they are hidden + # by us by default) + if( KICAD_SHOW_GTK_MESSAGES ) + message( STATUS "Configuring KiCad not to hide any GTK error messages" ) + string( APPEND PLATFORM_COMPILE_DEFS "-DKICAD_SHOW_GTK_MESSAGES" ) + endif() endif() @@ -47,6 +62,10 @@ add_library( kiplatform STATIC ${PLATFORM_SRCS} ) +target_compile_definitions( kiplatform PRIVATE + ${PLATFORM_COMPILE_DEFS} + ) + target_include_directories( kiplatform PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) diff --git a/libs/kiplatform/gtk/app.cpp b/libs/kiplatform/gtk/app.cpp index 76302bbcce..b51d88e26b 100644 --- a/libs/kiplatform/gtk/app.cpp +++ b/libs/kiplatform/gtk/app.cpp @@ -20,10 +20,23 @@ #include +#include + #include #include +/* + * Function to attach to the glib logger to eat the output it gives so we don't + * get the message spam on the terminal from wxWidget's abuse of the GTK API. + */ +static GLogWriterOutput nullLogWriter( GLogLevelFlags log_level, const GLogField* fields, + gsize n_fields, gpointer user_data ) +{ + return G_LOG_WRITER_HANDLED; +} + + bool KIPLATFORM::APP::PlatformInit() { // Disable proxy menu in Unity window manager. Only usual menubar works with @@ -47,9 +60,15 @@ bool KIPLATFORM::APP::PlatformInit() // events. wxSetEnv( wxT( "GDK_CORE_DEVICE_EVENTS" ), wxT( "1" ) ); +#if !defined( KICAD_SHOW_GTK_MESSAGES ) + // Attach a logger that will consume the annoying GTK error messages + g_log_set_writer_func( nullLogWriter, NULL, NULL ); +#endif + return true; } + bool KIPLATFORM::APP::RegisterApplicationRestart( const wxString& aCommandLine ) { // Not implemented on this platform