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