diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index f7b598304b3ab..6a1e4f8c62bd0 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -27,6 +27,7 @@ #include "../audio/SDL_audio_c.h" #include "../camera/SDL_camera_c.h" #include "../timer/SDL_timer_c.h" +#include "../tray/SDL_tray_utils.h" #ifndef SDL_JOYSTICK_DISABLED #include "../joystick/SDL_joystick_c.h" #endif @@ -1399,6 +1400,8 @@ static void SDL_PumpEventsInternal(bool push_sentinel) } #endif + SDL_UpdateTrays(); + SDL_SendPendingSignalEvents(); // in case we had a signal handler fire, etc. if (push_sentinel && SDL_EventEnabled(SDL_EVENT_POLL_SENTINEL)) { diff --git a/src/tray/SDL_tray_utils.h b/src/tray/SDL_tray_utils.h index e9e64fc6862fc..a8854532dbaad 100644 --- a/src/tray/SDL_tray_utils.h +++ b/src/tray/SDL_tray_utils.h @@ -22,5 +22,6 @@ extern void SDL_RegisterTray(SDL_Tray *tray); extern void SDL_UnregisterTray(SDL_Tray *tray); +extern void SDL_UpdateTrays(void); extern void SDL_CleanupTrays(void); extern bool SDL_HasActiveTrays(void); diff --git a/src/tray/cocoa/SDL_tray.m b/src/tray/cocoa/SDL_tray.m index 9d2f55e2db347..ae8d6be835f27 100644 --- a/src/tray/cocoa/SDL_tray.m +++ b/src/tray/cocoa/SDL_tray.m @@ -78,6 +78,10 @@ static void DestroySDLMenu(SDL_TrayMenu *menu) SDL_free(menu); } +void SDL_UpdateTrays(void) +{ +} + SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip) { if (!SDL_IsMainThread()) { diff --git a/src/tray/dummy/SDL_tray.c b/src/tray/dummy/SDL_tray.c index 55a1e645586f4..db76db25269bf 100644 --- a/src/tray/dummy/SDL_tray.c +++ b/src/tray/dummy/SDL_tray.c @@ -25,6 +25,10 @@ #include "../SDL_tray_utils.h" +void SDL_UpdateTrays(void) +{ +} + SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip) { SDL_Unsupported(); diff --git a/src/tray/unix/SDL_tray.c b/src/tray/unix/SDL_tray.c index 0176c917e9359..2a1cdacc886c4 100644 --- a/src/tray/unix/SDL_tray.c +++ b/src/tray/unix/SDL_tray.c @@ -78,24 +78,23 @@ typedef struct _GtkMenuShell GtkMenuShell; typedef struct _GtkWidget GtkWidget; typedef struct _GtkCheckMenuItem GtkCheckMenuItem; -gboolean (*gtk_init_check)(int *argc, char ***argv); -void (*gtk_main)(void); -void (*gtk_main_quit)(void); -GtkWidget* (*gtk_menu_new)(void); -GtkWidget* (*gtk_separator_menu_item_new)(void); -GtkWidget* (*gtk_menu_item_new_with_label)(const gchar *label); -void (*gtk_menu_item_set_submenu)(GtkMenuItem *menu_item, GtkWidget *submenu); -GtkWidget* (*gtk_check_menu_item_new_with_label)(const gchar *label); -void (*gtk_check_menu_item_set_active)(GtkCheckMenuItem *check_menu_item, gboolean is_active); -void (*gtk_widget_set_sensitive)(GtkWidget *widget, gboolean sensitive); -void (*gtk_widget_show)(GtkWidget *widget); -void (*gtk_menu_shell_append)(GtkMenuShell *menu_shell, GtkWidget *child); -void (*gtk_menu_shell_insert)(GtkMenuShell *menu_shell, GtkWidget *child, gint position); -void (*gtk_widget_destroy)(GtkWidget *widget); -const gchar *(*gtk_menu_item_get_label)(GtkMenuItem *menu_item); -void (*gtk_menu_item_set_label)(GtkMenuItem *menu_item, const gchar *label); -gboolean (*gtk_check_menu_item_get_active)(GtkCheckMenuItem *check_menu_item); -gboolean (*gtk_widget_get_sensitive)(GtkWidget *widget); +static gboolean (*gtk_init_check)(int *argc, char ***argv); +static gboolean (*gtk_main_iteration_do)(gboolean blocking); +static GtkWidget* (*gtk_menu_new)(void); +static GtkWidget* (*gtk_separator_menu_item_new)(void); +static GtkWidget* (*gtk_menu_item_new_with_label)(const gchar *label); +static void (*gtk_menu_item_set_submenu)(GtkMenuItem *menu_item, GtkWidget *submenu); +static GtkWidget* (*gtk_check_menu_item_new_with_label)(const gchar *label); +static void (*gtk_check_menu_item_set_active)(GtkCheckMenuItem *check_menu_item, gboolean is_active); +static void (*gtk_widget_set_sensitive)(GtkWidget *widget, gboolean sensitive); +static void (*gtk_widget_show)(GtkWidget *widget); +static void (*gtk_menu_shell_append)(GtkMenuShell *menu_shell, GtkWidget *child); +static void (*gtk_menu_shell_insert)(GtkMenuShell *menu_shell, GtkWidget *child, gint position); +static void (*gtk_widget_destroy)(GtkWidget *widget); +static const gchar *(*gtk_menu_item_get_label)(GtkMenuItem *menu_item); +static void (*gtk_menu_item_set_label)(GtkMenuItem *menu_item, const gchar *label); +static gboolean (*gtk_check_menu_item_get_active)(GtkCheckMenuItem *check_menu_item); +static gboolean (*gtk_widget_get_sensitive)(GtkWidget *widget); #define GTK_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_MENU_ITEM, GtkMenuItem)) #define GTK_WIDGET(widget) (G_TYPE_CHECK_INSTANCE_CAST ((widget), GTK_TYPE_WIDGET, GtkWidget)) @@ -128,14 +127,6 @@ void (*app_indicator_set_menu)(AppIndicator *self, GtkMenu *menu); /* ------------------------------------------------------------------------- */ #endif -static int main_gtk_thread(void *data) -{ - gtk_main(); - return 0; -} - -static bool gtk_thread_active = false; - #ifdef APPINDICATOR_HEADER static void quit_gtk(void) @@ -232,8 +223,7 @@ static bool init_gtk(void) } gtk_init_check = dlsym(libgtk, "gtk_init_check"); - gtk_main = dlsym(libgtk, "gtk_main"); - gtk_main_quit = dlsym(libgtk, "gtk_main_quit"); + gtk_main_iteration_do = dlsym(libgtk, "gtk_main_iteration_do"); gtk_menu_new = dlsym(libgtk, "gtk_menu_new"); gtk_separator_menu_item_new = dlsym(libgtk, "gtk_separator_menu_item_new"); gtk_menu_item_new_with_label = dlsym(libgtk, "gtk_menu_item_new_with_label"); @@ -262,8 +252,7 @@ static bool init_gtk(void) app_indicator_set_menu = dlsym(libappindicator, "app_indicator_set_menu"); if (!gtk_init_check || - !gtk_main || - !gtk_main_quit || + !gtk_main_iteration_do || !gtk_menu_new || !gtk_separator_menu_item_new || !gtk_menu_item_new_with_label || @@ -396,6 +385,13 @@ static void DestroySDLMenu(SDL_TrayMenu *menu) SDL_free(menu); } +void SDL_UpdateTrays(void) +{ + if (SDL_HasActiveTrays()) { + gtk_main_iteration_do(FALSE); + } +} + SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip) { if (!SDL_IsMainThread()) { @@ -407,11 +403,6 @@ SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip) return NULL; } - if (!gtk_thread_active) { - SDL_DetachThread(SDL_CreateThread(main_gtk_thread, "tray gtk", NULL)); - gtk_thread_active = true; - } - SDL_Tray *tray = (SDL_Tray *)SDL_calloc(1, sizeof(*tray)); if (!tray) { return NULL; @@ -799,9 +790,4 @@ void SDL_DestroyTray(SDL_Tray *tray) } SDL_free(tray); - - if (!SDL_HasActiveTrays()) { - gtk_main_quit(); - gtk_thread_active = false; - } } diff --git a/src/tray/windows/SDL_tray.c b/src/tray/windows/SDL_tray.c index 0afd62768f0e3..a7e27c069914d 100644 --- a/src/tray/windows/SDL_tray.c +++ b/src/tray/windows/SDL_tray.c @@ -209,6 +209,10 @@ static HICON load_default_icon() return LoadIcon(NULL, IDI_APPLICATION); } +void SDL_UpdateTrays(void) +{ +} + SDL_Tray *SDL_CreateTray(SDL_Surface *icon, const char *tooltip) { if (!SDL_IsMainThread()) {