diff --git a/src/SDL.c b/src/SDL.c index a104e955a7..41a8435e6a 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -667,7 +667,7 @@ void SDL_Quit(void) SDL_DBus_Quit(); #endif -#if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID) +#if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID) && !defined(SDL_PLATFORM_EMSCRIPTEN) SDL_Gtk_Quit(); #endif diff --git a/src/tray/unix/SDL_tray.c b/src/tray/unix/SDL_tray.c index d4822e3993..e43c2c245a 100644 --- a/src/tray/unix/SDL_tray.c +++ b/src/tray/unix/SDL_tray.c @@ -67,8 +67,6 @@ static void (*app_indicator_set_menu)(AppIndicator *self, GtkMenu *menu); /* ------------------------------------------------------------------------- */ #endif -#ifndef APPINDICATOR_HEADER - static void *libappindicator = NULL; static void quit_appindicator(void) @@ -130,7 +128,6 @@ static bool init_appindicator(void) return true; } -#endif struct SDL_TrayMenu { GtkMenuShell *menu; @@ -254,7 +251,7 @@ bool SDL_IsTraySupported(void) static bool has_been_detected_once = false; if (!has_been_detected_once) { - has_trays = SDL_Gtk_Init(); + has_trays = init_appindicator() && SDL_Gtk_Init(); has_been_detected_once = true; } @@ -268,12 +265,17 @@ SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip) return NULL; } + if (!init_appindicator()) { + return NULL; + } + + SDL_Tray *tray = NULL; SDL_GtkContext *gtk = SDL_Gtk_EnterContext(); if (!gtk) { goto error; } - SDL_Tray *tray = (SDL_Tray *)SDL_calloc(1, sizeof(*tray)); + tray = (SDL_Tray *)SDL_calloc(1, sizeof(*tray)); if (!tray) { goto error; } @@ -506,12 +508,13 @@ SDL_TrayEntry *SDL_InsertTrayEntryAt(SDL_TrayMenu *menu, int pos, const char *la pos = menu->nEntries; } + SDL_TrayEntry *entry = NULL; SDL_GtkContext *gtk = SDL_Gtk_EnterContext(); if (!gtk) { goto error; } - SDL_TrayEntry *entry = (SDL_TrayEntry *)SDL_calloc(1, sizeof(*entry)); + entry = (SDL_TrayEntry *)SDL_calloc(1, sizeof(*entry)); if (!entry) { goto error; }