mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-20 05:46:22 +00:00
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:
@@ -89,10 +89,26 @@ static Display* display;
|
||||
|
||||
static void _ui_draw_term_title(void);
|
||||
|
||||
static void
|
||||
_ui_close(void)
|
||||
{
|
||||
g_timer_destroy(ui_idle_time);
|
||||
endwin();
|
||||
notifier_uninit();
|
||||
cons_clear_alerts();
|
||||
wins_destroy();
|
||||
inp_close();
|
||||
status_bar_close();
|
||||
free_title_bar();
|
||||
delwin(main_scr);
|
||||
delscreen(set_term(NULL));
|
||||
}
|
||||
|
||||
void
|
||||
ui_init(void)
|
||||
{
|
||||
log_info("Initialising UI");
|
||||
prof_add_shutdown_routine(_ui_close);
|
||||
main_scr = initscr();
|
||||
nonl();
|
||||
cbreak();
|
||||
@@ -180,21 +196,6 @@ ui_reset_idle_time(void)
|
||||
g_timer_start(ui_idle_time);
|
||||
}
|
||||
|
||||
void
|
||||
ui_close(void)
|
||||
{
|
||||
g_timer_destroy(ui_idle_time);
|
||||
endwin();
|
||||
notifier_uninit();
|
||||
cons_clear_alerts();
|
||||
wins_destroy();
|
||||
inp_close();
|
||||
status_bar_close();
|
||||
free_title_bar();
|
||||
delwin(main_scr);
|
||||
delscreen(set_term(NULL));
|
||||
}
|
||||
|
||||
void
|
||||
ui_resize(void)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#ifdef HAVE_GTK
|
||||
void tray_init(void);
|
||||
void tray_update(void);
|
||||
void tray_shutdown(void);
|
||||
|
||||
void tray_enable(void);
|
||||
void tray_disable(void);
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
void ui_init(void);
|
||||
void ui_load_colours(void);
|
||||
void ui_update(void);
|
||||
void ui_close(void);
|
||||
void ui_redraw(void);
|
||||
void ui_resize(void);
|
||||
void ui_focus_win(ProfWin* window);
|
||||
|
||||
Reference in New Issue
Block a user