Catch SIGINT, to clean up on Ctrl-C

master
Yevgen Muntyan 2006-06-18 18:31:23 -05:00
parent f684470876
commit 24c8377489
2 changed files with 38 additions and 2 deletions

View File

@ -16,6 +16,10 @@ AC_DEFUN([MOO_AC_FUNCS],[
#for mooappabout.h
AC_CHECK_HEADERS(sys/utsname.h)
#for mooapp.c
AC_CHECK_HEADERS(signal.h)
AC_TYPE_SIGNAL
################################################################################
# Terminal stuff
AC_CHECK_HEADERS([poll.h errno.h io.h fcntl.h sys/types.h sys/wait.h signal.h])

View File

@ -37,6 +37,9 @@
#include <string.h>
#include <stdio.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef VERSION
#define APP_VERSION VERSION
@ -76,6 +79,7 @@ struct _MooAppPrivate {
gboolean use_terminal;
char *tmpdir;
guint sigintr : 1;
};
@ -189,11 +193,24 @@ enum {
static guint signals[LAST_SIGNAL];
#if defined(HAVE_SIGNAL)
static RETSIGTYPE
sigint_handler (G_GNUC_UNUSED int sig)
{
if (moo_app_instance && moo_app_instance->priv)
moo_app_instance->priv->sigintr = TRUE;
}
#endif
static void
moo_app_class_init (MooAppClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
#if defined(HAVE_SIGNAL) && defined(SIGINT)
signal (SIGINT, sigint_handler);
#endif
moo_create_stock_items ();
moo_app_parent_class = g_type_class_peek_parent (klass);
@ -956,7 +973,8 @@ moo_app_send_files (MooApp *app,
}
static gboolean on_gtk_main_quit (MooApp *app)
static gboolean
on_gtk_main_quit (MooApp *app)
{
app->priv->quit_handler_id = 0;
@ -967,6 +985,18 @@ static gboolean on_gtk_main_quit (MooApp *app)
}
static gboolean
check_signal (void)
{
if (moo_app_instance && moo_app_instance->priv->sigintr)
{
moo_app_instance->priv->sigintr = FALSE;
MOO_APP_GET_CLASS(moo_app_instance)->quit (moo_app_instance);
}
return TRUE;
}
static int
moo_app_run_real (MooApp *app)
{
@ -976,6 +1006,8 @@ moo_app_run_real (MooApp *app)
app->priv->quit_handler_id =
gtk_quit_add (0, (GtkFunction) on_gtk_main_quit, app);
g_timeout_add (100, (GSourceFunc) check_signal, NULL);
gtk_main ();
return app->priv->exit_code;
@ -1054,7 +1086,7 @@ moo_app_quit_real (MooApp *app)
app->priv->term_window = NULL;
#ifdef MOO_BUILD_EDIT
moo_editor_close_all (app->priv->editor, TRUE);
moo_editor_close_all (app->priv->editor, FALSE);
moo_plugin_shutdown ();