diff --git a/mousepad/main.c b/mousepad/main.c index 97ff07f..c99766d 100644 --- a/mousepad/main.c +++ b/mousepad/main.c @@ -26,10 +26,13 @@ #include +/* enable forking */ +#include /* globals */ static gchar **filenames = NULL; static gboolean opt_version = FALSE; +static gboolean opt_detach_from_terminal = FALSE; #ifdef HAVE_DBUS static gboolean opt_disable_server = FALSE; static gboolean opt_quit = FALSE; @@ -44,20 +47,19 @@ static const GOptionEntry option_entries[] = { "disable-server", '\0', 0, G_OPTION_ARG_NONE, &opt_disable_server, N_("Do not register with the D-BUS session message bus"), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &opt_quit, N_("Quit a running Mousepad instance"), NULL }, #endif + { "detach" , 'd', 0, G_OPTION_ARG_NONE , &opt_detach_from_terminal , N_("Detach mousepad from terminal. Mousepad will not close if terminal gets closed."), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, &opt_version, N_("Print version information and exit"), NULL }, { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, NULL }, { NULL } }; - - gint main (gint argc, gchar **argv) -{ +{ MousepadApplication *application; GError *error = NULL; gchar *working_directory; - + /* bind the text domain to the locale directory */ bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); @@ -98,6 +100,14 @@ main (gint argc, gchar **argv) return EXIT_FAILURE; } + if(TRUE == opt_detach_from_terminal){ + g_print("-----try to fork-----\n"); + if(fork() > 0) { + // fork successful. So terminate parent. + exit(0); + } + } + /* check if we should print version information */ if (G_UNLIKELY (opt_version)) {