From 5fdfe369a62eb8027ffd50962c3dc0a01b25c92a Mon Sep 17 00:00:00 2001 From: Ben Burrill Date: Mon, 28 May 2018 21:16:05 +0200 Subject: [PATCH] Add --start-hidden command-line option (bug 14343) When --start-hidden is used, the primary interface is not shown. If the "Hide into the notification area" option is enabled, the notification icon will shown. Otherwise, the task manager will immediately quit (running completely in the background would be pointless). --- src/main.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 3960f6d..664e784 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,12 @@ static GtkWidget *window; static GtkStatusIcon *status_icon; static XtmTaskManager *task_manager; static gboolean timeout = FALSE; +static gboolean start_hidden = FALSE; + +static GOptionEntry main_entries[] = { + { "start-hidden", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &start_hidden, "Don't open a task manager window" }, + { NULL } +}; static void status_icon_activated (void) @@ -175,6 +181,7 @@ int main (int argc, char *argv[]) #if GLIB_CHECK_VERSION(2, 28, 0) GApplication *app; GError *error = NULL; + GOptionContext *opt_context; #endif #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); @@ -186,6 +193,15 @@ int main (int argc, char *argv[]) g_set_application_name (_("Task Manager")); #if GLIB_CHECK_VERSION(2, 28, 0) + opt_context = g_option_context_new (""); + g_option_context_add_main_entries (opt_context, main_entries, NULL); + g_option_context_add_group (opt_context, gtk_get_option_group (TRUE)); + if (!g_option_context_parse (opt_context, &argc, &argv, &error)) + { + g_print ("Unable to parse arguments: %s\n", error->message); + exit (1); + } + app = g_application_new ("xfce.taskmanager", 0); g_application_register (G_APPLICATION (app), NULL, &error); if (error != NULL) @@ -211,7 +227,10 @@ int main (int argc, char *argv[]) g_signal_connect (status_icon, "popup-menu", G_CALLBACK (status_icon_popup_menu), NULL); window = xtm_process_window_new (); - gtk_widget_show (window); + + if (!start_hidden) + gtk_widget_show (window); + #if GLIB_CHECK_VERSION(2, 28, 0) g_signal_connect_swapped (app, "activate", G_CALLBACK (xtm_process_window_show), window); #endif @@ -229,7 +248,8 @@ int main (int argc, char *argv[]) g_signal_connect (window, "destroy", G_CALLBACK (destroy_window), NULL); g_signal_connect (window, "delete-event", G_CALLBACK (delete_window), NULL); - gtk_main (); + if (gtk_widget_get_visible (window) || gtk_status_icon_get_visible (status_icon)) + gtk_main (); if (timeout > 0) g_source_remove (timeout);