From 05147016b072e690359d70dbfa1f98195ad2d8ee Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 10 Dec 2020 06:32:30 +0400 Subject: [PATCH] Simplify XErrorHandlerRestorer API --- .../SourceFiles/platform/linux/linux_libs.cpp | 7 +++---- .../platform/linux/linux_xlib_helper.cpp | 20 +++++++++---------- .../platform/linux/linux_xlib_helper.h | 3 --- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_libs.cpp b/Telegram/SourceFiles/platform/linux/linux_libs.cpp index 86e9719eb7..879db8f759 100644 --- a/Telegram/SourceFiles/platform/linux/linux_libs.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_libs.cpp @@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_domain.h" #include "mainwindow.h" +using Platform::internal::XErrorHandlerRestorer; + namespace Platform { namespace Libs { namespace { @@ -123,8 +125,7 @@ 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. - internal::XErrorHandlerRestorer handlerRestorer; - handlerRestorer.save(); + XErrorHandlerRestorer handlerRestorer; DEBUG_LOG(("Library gtk functions loaded!")); gtkTriedToInit = true; @@ -135,8 +136,6 @@ bool setupGtkBase(QLibrary &lib_gtk) { } DEBUG_LOG(("Checked gtk with gtk_init_check!")); - handlerRestorer.restore(); - // Use our custom log handler. g_log_set_handler("Gtk", G_LOG_LEVEL_MESSAGE, gtkMessageHandler, nullptr); diff --git a/Telegram/SourceFiles/platform/linux/linux_xlib_helper.cpp b/Telegram/SourceFiles/platform/linux/linux_xlib_helper.cpp index 43e87e3855..3396f17636 100644 --- a/Telegram/SourceFiles/platform/linux/linux_xlib_helper.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_xlib_helper.cpp @@ -17,8 +17,16 @@ namespace internal { class XErrorHandlerRestorer::Private { public: - Private() {} - int (*oldErrorHandler)(Display *, XErrorEvent *); + Private() + : _oldErrorHandler(XSetErrorHandler(nullptr)) { + } + + ~Private() { + XSetErrorHandler(_oldErrorHandler); + } + +private: + int (*_oldErrorHandler)(Display *, XErrorEvent *); }; XErrorHandlerRestorer::XErrorHandlerRestorer() @@ -27,14 +35,6 @@ XErrorHandlerRestorer::XErrorHandlerRestorer() XErrorHandlerRestorer::~XErrorHandlerRestorer() = default; -void XErrorHandlerRestorer::save() { - _private->oldErrorHandler = XSetErrorHandler(nullptr); -} - -void XErrorHandlerRestorer::restore() { - XSetErrorHandler(_private->oldErrorHandler); -} - } // namespace internal } // namespace Platform #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION diff --git a/Telegram/SourceFiles/platform/linux/linux_xlib_helper.h b/Telegram/SourceFiles/platform/linux/linux_xlib_helper.h index 65ad563105..def4c9bbaa 100644 --- a/Telegram/SourceFiles/platform/linux/linux_xlib_helper.h +++ b/Telegram/SourceFiles/platform/linux/linux_xlib_helper.h @@ -16,9 +16,6 @@ public: XErrorHandlerRestorer(); ~XErrorHandlerRestorer(); - void save(); - void restore(); - private: class Private; const std::unique_ptr _private;