From 02bd5879353bcde8f30cc2b57d6421ddf4784b39 Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Wed, 19 Dec 2012 16:38:14 +0100 Subject: [PATCH] allow parameters to dmenu and browser calls --- dunst.c | 12 ++++++++++-- dunstrc | 4 ++-- utils.c | 17 +++++++++++++++++ utils.h | 2 ++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/dunst.c b/dunst.c index 350bcc1..3f5f9a0 100644 --- a/dunst.c +++ b/dunst.c @@ -72,6 +72,8 @@ static int font_h; static bool print_notifications = false; static dimension_t window_dim; static bool pause_display = false; +static char **dmenu_cmd; +static char **browser_cmd; static r_line_cache line_cache; @@ -167,6 +169,9 @@ void context_menu(void) { iter = iter->next; } + if (!dmenu_input) + return; + int child_io[2]; int parent_io[2]; pipe(child_io); @@ -180,7 +185,7 @@ void context_menu(void) { dup(child_io[0]); close(1); dup(parent_io[1]); - execlp(dmenu, dmenu, (char *) NULL); + execvp(dmenu_cmd[0], dmenu_cmd); } else { close(child_io[0]); close(parent_io[1]); @@ -199,7 +204,7 @@ void context_menu(void) { int browser_pid = fork(); if (browser_pid == 0) { - execlp(browser, browser, (char *) NULL); + execvp(browser_cmd[0], browser_cmd); } else { return; } @@ -1562,7 +1567,10 @@ void load_options(char *cmdline_config_path) dmenu = option_get_string("global", "dmenu", "-dmenu", dmenu, "path to dmenu"); + dmenu_cmd = string_to_argv(dmenu); + browser = option_get_string("global", "browser", "-browser", browser, "path to browser"); + browser_cmd = string_to_argv(browser); lowbgcolor = option_get_string("urgency_low", "background", "-lb", lowbgcolor, diff --git a/dunstrc b/dunstrc index 311df0d..e1c5c72 100644 --- a/dunstrc +++ b/dunstrc @@ -95,10 +95,10 @@ startup_notification = false # dmenu path - dmenu = "/usr/bin/dmenu" + dmenu = /usr/bin/dmenu -p dunst: # browser for opening urls in context menu - browser = /usr/bin/firefox + browser = /usr/bin/firefox -new-tab [shortcuts] diff --git a/utils.c b/utils.c index 90f7026..681f199 100644 --- a/utils.c +++ b/utils.c @@ -64,6 +64,23 @@ char *string_append(char *a, const char *b, const char *sep) } +char **string_to_argv(const char *str) +{ + char **argv = NULL; + char *p = strtok (str, " "); + int n_spaces = 0, i; + + while (p) { + argv = realloc (argv, sizeof (char*) * ++n_spaces); + argv[n_spaces-1] = p; + p = strtok (NULL, " "); + } + argv = realloc (argv, sizeof (char*) * (n_spaces+1)); + argv[n_spaces] = NULL; + + return argv; +} + int digit_count(int i) { int len = 0; diff --git a/utils.h b/utils.h index ab1e8d6..72465da 100644 --- a/utils.h +++ b/utils.h @@ -10,6 +10,8 @@ char *string_replace(const char *needle, const char *replacement, char *string_append(char *a, const char *b, const char *sep); +char **string_to_argv(const char *str); + /* exit with an error message */ void die(char *msg, int exit_value);