mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Simplify XErrorHandlerRestorer API
This commit is contained in:
parent
3297bdadb5
commit
05147016b0
3 changed files with 13 additions and 17 deletions
|
@ -17,6 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_domain.h"
|
#include "main/main_domain.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
using Platform::internal::XErrorHandlerRestorer;
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace Libs {
|
namespace Libs {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -123,8 +125,7 @@ bool setupGtkBase(QLibrary &lib_gtk) {
|
||||||
|
|
||||||
// gtk_init will reset the Xlib error handler, and that causes
|
// 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.
|
// Qt applications to quit on X errors. Therefore, we need to manually restore it.
|
||||||
internal::XErrorHandlerRestorer handlerRestorer;
|
XErrorHandlerRestorer handlerRestorer;
|
||||||
handlerRestorer.save();
|
|
||||||
|
|
||||||
DEBUG_LOG(("Library gtk functions loaded!"));
|
DEBUG_LOG(("Library gtk functions loaded!"));
|
||||||
gtkTriedToInit = true;
|
gtkTriedToInit = true;
|
||||||
|
@ -135,8 +136,6 @@ bool setupGtkBase(QLibrary &lib_gtk) {
|
||||||
}
|
}
|
||||||
DEBUG_LOG(("Checked gtk with gtk_init_check!"));
|
DEBUG_LOG(("Checked gtk with gtk_init_check!"));
|
||||||
|
|
||||||
handlerRestorer.restore();
|
|
||||||
|
|
||||||
// Use our custom log handler.
|
// Use our custom log handler.
|
||||||
g_log_set_handler("Gtk", G_LOG_LEVEL_MESSAGE, gtkMessageHandler, nullptr);
|
g_log_set_handler("Gtk", G_LOG_LEVEL_MESSAGE, gtkMessageHandler, nullptr);
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,16 @@ namespace internal {
|
||||||
|
|
||||||
class XErrorHandlerRestorer::Private {
|
class XErrorHandlerRestorer::Private {
|
||||||
public:
|
public:
|
||||||
Private() {}
|
Private()
|
||||||
int (*oldErrorHandler)(Display *, XErrorEvent *);
|
: _oldErrorHandler(XSetErrorHandler(nullptr)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
~Private() {
|
||||||
|
XSetErrorHandler(_oldErrorHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int (*_oldErrorHandler)(Display *, XErrorEvent *);
|
||||||
};
|
};
|
||||||
|
|
||||||
XErrorHandlerRestorer::XErrorHandlerRestorer()
|
XErrorHandlerRestorer::XErrorHandlerRestorer()
|
||||||
|
@ -27,14 +35,6 @@ XErrorHandlerRestorer::XErrorHandlerRestorer()
|
||||||
|
|
||||||
XErrorHandlerRestorer::~XErrorHandlerRestorer() = default;
|
XErrorHandlerRestorer::~XErrorHandlerRestorer() = default;
|
||||||
|
|
||||||
void XErrorHandlerRestorer::save() {
|
|
||||||
_private->oldErrorHandler = XSetErrorHandler(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XErrorHandlerRestorer::restore() {
|
|
||||||
XSetErrorHandler(_private->oldErrorHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||||
|
|
|
@ -16,9 +16,6 @@ public:
|
||||||
XErrorHandlerRestorer();
|
XErrorHandlerRestorer();
|
||||||
~XErrorHandlerRestorer();
|
~XErrorHandlerRestorer();
|
||||||
|
|
||||||
void save();
|
|
||||||
void restore();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
const std::unique_ptr<Private> _private;
|
const std::unique_ptr<Private> _private;
|
||||||
|
|
Loading…
Add table
Reference in a new issue