From 3068a7010a31a4fe8503c3f509329c5646b2f907 Mon Sep 17 00:00:00 2001 From: Manuel Bachmann Date: Fri, 23 May 2014 18:10:53 +0200 Subject: tz-launcher: support signal to reload launchers at runtime When sent a SIGUSR1 signal ("$ kill -10 $PID"), tz-launcher will now re-read the content of the files/folders which have been passed to it, and display the corresponding new launchers. Change-Id: I80417c491f364c97e063f45f205fdacbf07bdb2c Signed-off-by: Manuel Bachmann --- tz-launcher/tz-launcher-wl.c | 10 +++++++++- tz-launcher/tz-launcher.c | 47 +++++++++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/tz-launcher/tz-launcher-wl.c b/tz-launcher/tz-launcher-wl.c index c990423..5c32ae5 100644 --- a/tz-launcher/tz-launcher-wl.c +++ b/tz-launcher/tz-launcher-wl.c @@ -32,6 +32,7 @@ struct launcher { gboolean terminal; }; +struct display *display; struct main_window *main_window; @@ -451,10 +452,17 @@ main_window_destroy () free (main_window); } +void +tz_launcher_wl_reload (int desktopfiles, gchar ***desktoptable) +{ + main_window_destroy (); + main_window_create (display, desktopfiles, desktoptable); +} + void tz_launcher_wl_run (int desktopfiles, gchar ***desktoptable) { - struct display *display = NULL; + display = NULL; int retries = 0; while (!display) { diff --git a/tz-launcher/tz-launcher.c b/tz-launcher/tz-launcher.c index f57618b..7a50fc2 100644 --- a/tz-launcher/tz-launcher.c +++ b/tz-launcher/tz-launcher.c @@ -8,6 +8,9 @@ int desktopfiles; gchar **desktoptable[MAX_DESKTOPFILES]; +int global_argc; +char **global_argv; + gboolean file_is_parsable (GFile *file) @@ -200,21 +203,12 @@ tz_launcher_parse_config_file (GFile *file) } -int -main (int argc, char *argv[]) +void +parse_args (int argc, char **argv) { - if (argc < 2) { - g_print ("Usage : tz-launcher .desktop .desktop ...\n" - " or\n" - " tz-launcher -c .conf\n"); - return 0; - } - - desktopfiles = 0; - g_type_init (); - int i; + desktopfiles = 0; GFile *desktopfile; for (i = 1; i < argc ; i++) { @@ -257,7 +251,36 @@ main (int argc, char *argv[]) if (desktopfiles == MAX_DESKTOPFILES) break; } +} + +static void +sigreload_handler (int s) +{ + parse_args (global_argc, global_argv); + + if (desktopfiles > 0) + tz_launcher_wl_reload (desktopfiles, desktoptable); +} + +int +main (int argc, char **argv) +{ + if (argc < 2) { + g_print ("Usage : tz-launcher .desktop .desktop ...\n" + " or\n" + " tz-launcher -c .conf\n"); + return 0; + } + + g_type_init (); + + + signal (SIGUSR1, sigreload_handler); + global_argc = argc; + global_argv = argv; + + parse_args (argc, argv); if (desktopfiles > 0) tz_launcher_wl_run (desktopfiles, desktoptable); -- cgit v1.2.3