Skip to content

Commit

Permalink
Remove some duplication in LOAD_GTK_SYMBOL.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Mar 31, 2021
1 parent f8c6602 commit fb2d9d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
25 changes: 14 additions & 11 deletions base/platform/linux/base_linux_gtk_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@

namespace base {
namespace Platform {

using namespace Gtk;

namespace {

bool TriedToInit = false;
bool Loaded = false;
namespace Gtk {

bool LoadLibrary(QLibrary &lib, const char *name, int version) {
#ifdef LINK_TO_GTK
Expand Down Expand Up @@ -57,6 +51,15 @@ bool LoadLibrary(QLibrary &lib, const char *name, int version) {
#endif // !LINK_TO_GTK
}

} // namespace Gtk

namespace {

using namespace Gtk;

bool TriedToInit = false;
bool Loaded = false;

void GtkMessageHandler(
const gchar *log_domain,
GLogLevelFlags log_level,
Expand All @@ -72,9 +75,9 @@ void GtkMessageHandler(
}

bool SetupGtkBase(QLibrary &lib) {
if (!LOAD_GTK_SYMBOL(lib, "gtk_init_check", gtk_init_check)) return false;
if (!LOAD_GTK_SYMBOL(lib, gtk_init_check)) return false;

if (LOAD_GTK_SYMBOL(lib, "gdk_set_allowed_backends", gdk_set_allowed_backends)) {
if (LOAD_GTK_SYMBOL(lib, gdk_set_allowed_backends)) {
// We work only with Wayland and X11 GDK backends.
// Otherwise we get segfault in Ubuntu 17.04 in gtk_init_check() call.
// See https://github.com/telegramdesktop/tdesktop/issues/3176
Expand Down Expand Up @@ -288,8 +291,8 @@ void GtkIntegration::load() {
}

if (Loaded) {
LOAD_GTK_SYMBOL(_lib, "gtk_check_version", gtk_check_version);
LOAD_GTK_SYMBOL(_lib, "gtk_settings_get_default", gtk_settings_get_default);
LOAD_GTK_SYMBOL(_lib, gtk_check_version);
LOAD_GTK_SYMBOL(_lib, gtk_settings_get_default);

SetIconTheme();
SetCursorSize();
Expand Down
6 changes: 4 additions & 2 deletions base/platform/linux/base_linux_gtk_integration_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ extern "C" {
#endif // DESKTOP_APP_USE_PACKAGED && !DESKTOP_APP_USE_PACKAGED_LAZY

#ifdef LINK_TO_GTK
#define LOAD_GTK_SYMBOL(lib, name, func) (func = ::func)
#define LOAD_GTK_SYMBOL(lib, func) (func = ::func)
#else // LINK_TO_GTK
#define LOAD_GTK_SYMBOL base::Platform::Gtk::LoadSymbol
#define LOAD_GTK_SYMBOL(lib, func) base::Platform::Gtk::LoadSymbol(lib, #func, func)
#endif // !LINK_TO_GTK

namespace base {
namespace Platform {
namespace Gtk {

bool LoadLibrary(QLibrary &lib, const char *name, int version);

template <typename Function>
bool LoadSymbol(QLibrary &lib, const char *name, Function &func) {
func = nullptr;
Expand Down

0 comments on commit fb2d9d3

Please sign in to comment.