From d92b5eebccd0f63083e0cd89431d2d3b6e335074 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 3 Jun 2020 07:49:46 +0400 Subject: [PATCH] Restore X error handler just like qgtk3 --- Telegram/SourceFiles/platform/linux/linux_libs.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Telegram/SourceFiles/platform/linux/linux_libs.cpp b/Telegram/SourceFiles/platform/linux/linux_libs.cpp index ac897ea0d1..21364c92c5 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libs.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_libs.cpp @@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/linux/linux_desktop_environment.h" #include "platform/linux/specific_linux.h" +extern "C" { +#include +} + #include namespace Platform { @@ -150,6 +154,10 @@ bool setupGtkBase(QLibrary &lib_gtk) { } } + // gtk_init will reset the Xlib error handler, and that causes + // Qt applications to quit on X errors. Therefore, we need to manually restore it. + int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(nullptr); + DEBUG_LOG(("Library gtk functions loaded!")); if (!gtk_init_check(0, 0)) { gtk_init_check = nullptr; @@ -158,6 +166,8 @@ bool setupGtkBase(QLibrary &lib_gtk) { } DEBUG_LOG(("Checked gtk with gtk_init_check!")); + XSetErrorHandler(oldErrorHandler); + // Use our custom log handler. g_log_set_handler("Gtk", G_LOG_LEVEL_MESSAGE, gtkMessageHandler, nullptr);