From 5c017d164644f5b47f1f93fcac8af90e2400ce20 Mon Sep 17 00:00:00 2001 From: Ben Burrill Date: Tue, 17 Apr 2018 18:04:59 -0700 Subject: [PATCH] Add --start-hidden command-line option 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 1244bd6..9556295 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,7 @@ static GtkWidget *window; static GtkStatusIcon *status_icon; static XtmTaskManager *task_manager; static gboolean timeout = 0; +static gboolean start_hidden = FALSE; static void status_icon_activated (void) @@ -170,6 +171,20 @@ refresh_rate_changed (void) init_timeout (); } +static void +parse_args (int argc, char *argv[]) +{ + int n; + + for (n = 0; n < argc; ++n) + { + if (strcmp (argv[n], "--start-hidden") == 0) + { + start_hidden = TRUE; + } + } +} + int main (int argc, char *argv[]) { #if GLIB_CHECK_VERSION(2, 28, 0) @@ -183,6 +198,7 @@ int main (int argc, char *argv[]) #endif gtk_init (&argc, &argv); + parse_args (argc, argv); g_set_application_name (_("Task Manager")); #if GLIB_CHECK_VERSION(2, 28, 0) @@ -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); -- 2.17.0