Restore X error handler just like qgtk3

This commit is contained in:
Ilya Fedin 2020-06-03 07:49:46 +04:00 committed by John Preston
parent 5c6b4d95b0
commit d92b5eebcc
1 changed files with 10 additions and 0 deletions

View File

@ -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 <X11/Xlib.h>
}
#include <QtGui/QGuiApplication>
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);