From 12727744ab31b28eaec2f148f2ed22cdc7338a99 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 18 Apr 2016 00:26:17 +0100 Subject: [PATCH] Load/destroy tray icons on init/shutdown --- src/command/commands.c | 4 ++-- src/profanity.c | 2 +- src/tray.c | 16 ++++++++-------- src/tray.h | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index e1eba540..50877227 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -5546,9 +5546,9 @@ cmd_tray(ProfWin *window, const char *const command, gchar **args) gboolean new = prefs_get_boolean(PREF_TRAY); if (old != new) { if (new) { - create_tray(); + tray_enable(); } else { - destroy_tray(); + tray_disable(); } } return TRUE; diff --git a/src/profanity.c b/src/profanity.c index 3c508dcd..1140594f 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -380,7 +380,7 @@ _shutdown(void) cl_ev_disconnect(); } #ifdef HAVE_GTK - tray_close(); + tray_shutdown(); #endif jabber_shutdown(); plugins_on_shutdown(); diff --git a/src/tray.c b/src/tray.c index 7c731313..3e2c7a68 100644 --- a/src/tray.c +++ b/src/tray.c @@ -145,6 +145,7 @@ _tray_change_icon(gpointer data) void tray_init(void) { + _get_icons(); gtk_ready = gtk_init_check(0, NULL); log_debug("Env is GTK-ready: %s", gtk_ready ? "true" : "false"); if (!gtk_ready) { @@ -155,7 +156,7 @@ tray_init(void) gtk_main_iteration_do(FALSE); if (prefs_get_boolean(PREF_TRAY)) { log_debug("Building GTK icon"); - create_tray(); + tray_enable(); } } @@ -168,24 +169,25 @@ tray_update(void) } void -tray_close(void) +tray_shutdown(void) { if (gtk_ready && prefs_get_boolean(PREF_TRAY)) { - destroy_tray(); + tray_disable(); } + g_string_free(icon_filename, TRUE); + g_string_free(icon_msg_filename, TRUE); } void -create_tray(void) +tray_enable(void) { - _get_icons(); prof_tray = gtk_status_icon_new_from_file(icon_filename->str); shutting_down = FALSE; timer = g_timeout_add(5000, _tray_change_icon, NULL); } void -destroy_tray(void) +tray_disable(void) { shutting_down = TRUE; g_source_remove(timer); @@ -193,8 +195,6 @@ destroy_tray(void) g_clear_object(&prof_tray); prof_tray = NULL; } - g_string_free(icon_filename, TRUE); - g_string_free(icon_msg_filename, TRUE); } /* }}} */ diff --git a/src/tray.h b/src/tray.h index 98cac490..81ddd20f 100644 --- a/src/tray.h +++ b/src/tray.h @@ -37,7 +37,7 @@ void tray_init(void); void tray_update(void); -void tray_close(void); +void tray_shutdown(void); /* * Create tray icon @@ -45,10 +45,10 @@ void tray_close(void); * This will initialize the timer that will be called in order to change the icons * and will search the icons in the defaults paths */ -void create_tray(void); +void tray_enable(void); /* * Destroy tray icon */ -void destroy_tray(void); +void tray_disable(void); #endif