Introduce our own shutdown callback mechanism.

Instead of adding stuff to `_shutdown()`, we can now register a shutdown
routine from the respective `init()` function of our modules.

This also has the advantage, that we're sure they're called in reverse
order from how the initialization happened.

I didn't simply use `atexit()` because POSIX says that the number of
possible callbacks is limited (min 32) and I was not sure whether
we will maybe extend this number at one point.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2025-03-07 11:44:31 +01:00
parent 662a0be633
commit c5a131ee46
39 changed files with 321 additions and 327 deletions

View File

@@ -153,9 +153,21 @@ _tray_change_icon(gpointer data)
return TRUE;
}
static void
_tray_shutdown(void)
{
if (gtk_ready && prefs_get_boolean(PREF_TRAY)) {
tray_disable();
}
g_string_free(icon_filename, TRUE);
g_string_free(icon_msg_filename, TRUE);
gtk_main_quit();
}
void
tray_init(void)
{
prof_add_shutdown_routine(_tray_shutdown);
_get_icons();
gtk_ready = gtk_init_check(0, NULL);
log_debug("Env is GTK-ready: %s", gtk_ready ? "true" : "false");
@@ -179,17 +191,6 @@ tray_update(void)
}
}
void
tray_shutdown(void)
{
if (gtk_ready && prefs_get_boolean(PREF_TRAY)) {
tray_disable();
}
g_string_free(icon_filename, TRUE);
g_string_free(icon_msg_filename, TRUE);
gtk_main_quit();
}
void
tray_set_timer(int interval)
{