From 5c6b4d95b0adc88e91fb316749eb70951744718e Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 3 Jun 2020 00:35:43 +0400 Subject: [PATCH] Suppress warning about transient parent when opening gtk file dialog --- .../SourceFiles/platform/linux/linux_libs.cpp | 46 +++++++++++++------ .../SourceFiles/platform/linux/linux_libs.h | 6 +++ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_libs.cpp b/Telegram/SourceFiles/platform/linux/linux_libs.cpp index c7098adbbe..ac897ea0d1 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libs.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_libs.cpp @@ -35,20 +35,32 @@ bool loadLibrary(QLibrary &lib, const char *name, int version) { #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION template -T gtkSetting(const gchar *propertyName) -{ - GtkSettings *settings = Libs::gtk_settings_get_default(); - T value; - Libs::g_object_get(settings, propertyName, &value, nullptr); - return value; +T gtkSetting(const gchar *propertyName) { + GtkSettings *settings = gtk_settings_get_default(); + T value; + g_object_get(settings, propertyName, &value, nullptr); + return value; } -QString gtkSetting(const gchar *propertyName) -{ - gchararray value = gtkSetting(propertyName); - QString str = QString::fromUtf8(value); - Libs::g_free(value); - return str; +QString gtkSetting(const gchar *propertyName) { + gchararray value = gtkSetting(propertyName); + QString str = QString::fromUtf8(value); + g_free(value); + return str; +} + +void gtkMessageHandler( + const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer unused_data) { + // Silence false-positive Gtk warnings (we are using Xlib to set + // the WM_TRANSIENT_FOR hint). + if (message != qstr("GtkDialog mapped without a transient parent. " + "This is discouraged.")) { + // For other messages, call the default handler. + g_log_default_handler(log_domain, log_level, message, unused_data); + } } bool setupGtkBase(QLibrary &lib_gtk) { @@ -120,6 +132,9 @@ bool setupGtkBase(QLibrary &lib_gtk) { if (!load(lib_gtk, "g_error_free", g_error_free)) return false; if (!load(lib_gtk, "g_slist_free", g_slist_free)) return false; + if (!load(lib_gtk, "g_log_set_handler", g_log_set_handler)) return false; + if (!load(lib_gtk, "g_log_default_handler", g_log_default_handler)) return false; + if (load(lib_gtk, "gdk_set_allowed_backends", gdk_set_allowed_backends)) { // We work only with X11 GDK backend. // Otherwise we get segfault in Ubuntu 17.04 in gtk_init_check() call. @@ -141,8 +156,11 @@ bool setupGtkBase(QLibrary &lib_gtk) { DEBUG_LOG(("Failed to gtk_init_check(0, 0)!")); return false; } - DEBUG_LOG(("Checked gtk with gtk_init_check!")); + + // Use our custom log handler. + g_log_set_handler("Gtk", G_LOG_LEVEL_MESSAGE, gtkMessageHandler, nullptr); + return true; } #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION @@ -233,6 +251,8 @@ f_g_list_free g_list_free = nullptr; f_g_list_free_full g_list_free_full = nullptr; f_g_error_free g_error_free = nullptr; f_g_slist_free g_slist_free = nullptr; +f_g_log_set_handler g_log_set_handler = nullptr; +f_g_log_default_handler g_log_default_handler = nullptr; #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION void start() { diff --git a/Telegram/SourceFiles/platform/linux/linux_libs.h b/Telegram/SourceFiles/platform/linux/linux_libs.h index 1f871f8b9e..472d2dcbf2 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libs.h +++ b/Telegram/SourceFiles/platform/linux/linux_libs.h @@ -353,6 +353,12 @@ extern f_g_error_free g_error_free; typedef void (*f_g_slist_free)(GSList *list); extern f_g_slist_free g_slist_free; + +typedef guint (*f_g_log_set_handler)(const gchar *log_domain, GLogLevelFlags log_levels, GLogFunc log_func, gpointer user_data); +extern f_g_log_set_handler g_log_set_handler; + +typedef void (*f_g_log_default_handler)(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data); +extern f_g_log_default_handler g_log_default_handler; #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION } // namespace Libs