From 81e9d6ca1f7c5367752a81e39d30908a3e8e65cf Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 26 Feb 2024 23:22:06 +0000 Subject: [PATCH] run-{shell-,}command: expand `{app_id}` inside the template string --- include/helper.h | 5 ++++- source/helper.c | 11 ++++++++--- source/modes/drun.c | 6 +++--- source/modes/filebrowser.c | 2 +- source/modes/recursivebrowser.c | 2 +- source/modes/run.c | 2 +- source/modes/window.c | 2 +- source/view.c | 4 ++-- 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/helper.h b/include/helper.h index 06e9ef85..b6de10de 100644 --- a/include/helper.h +++ b/include/helper.h @@ -322,7 +322,9 @@ gboolean helper_execute(const char *wd, char **args, const char *error_precmd, * @param wd The work directory (optional) * @param cmd The cmd to execute * @param run_in_term Indicate if command should be run in a terminal - * @param context The startup notification context, if any + * @param startup_notify True if the command is expected to notify on startup + * @param context Additional information about the application, such as its + * app_id. May be NULL. * * Execute command. * If needed members of context are NULL, they will be filled. @@ -331,6 +333,7 @@ gboolean helper_execute(const char *wd, char **args, const char *error_precmd, */ gboolean helper_execute_command(const char *wd, const char *cmd, gboolean run_in_term, + gboolean startup_notify, RofiHelperExecuteContext *context); /** diff --git a/source/helper.c b/source/helper.c index 6265f6b6..6edc0e51 100644 --- a/source/helper.c +++ b/source/helper.c @@ -1071,15 +1071,20 @@ gboolean helper_execute(const char *wd, char **args, const char *error_precmd, gboolean helper_execute_command(const char *wd, const char *cmd, gboolean run_in_term, + gboolean startup_notify, RofiHelperExecuteContext *context) { char **args = NULL; int argc = 0; if (run_in_term) { - helper_parse_setup(config.run_shell_command, &args, &argc, "{cmd}", cmd, + helper_parse_setup(config.run_shell_command, &args, &argc, + "{cmd}", cmd, + "{app_id}", context ? context->app_id : "", (char *)0); } else { - helper_parse_setup(config.run_command, &args, &argc, "{cmd}", cmd, + helper_parse_setup(config.run_command, &args, &argc, + "{cmd}", cmd, + "{app_id}", context ? context->app_id : "", (char *)0); } @@ -1106,7 +1111,7 @@ gboolean helper_execute_command(const char *wd, const char *cmd, } } - return helper_execute(wd, args, "", cmd, context); + return helper_execute(wd, args, "", cmd, startup_notify ? context : NULL); } static char *helper_get_theme_path_check_file(const char *filename, diff --git a/source/modes/drun.c b/source/modes/drun.c index c4e4fdc9..59853b9b 100644 --- a/source/modes/drun.c +++ b/source/modes/drun.c @@ -330,7 +330,7 @@ static void launch_link_entry(DRunModeEntry *e) { g_free(url); g_debug("Link launch command: |%s|", command); - if (helper_execute_command(NULL, command, FALSE, NULL)) { + if (helper_execute_command(NULL, command, FALSE, FALSE, NULL)) { char *path = g_build_filename(cache_dir, DRUN_CACHE_FILE, NULL); // Store it based on the unique identifiers (desktop_id). history_set(path, e->desktop_id); @@ -509,7 +509,7 @@ static void exec_cmd_entry(DRunModePrivateData *pd, DRunModeEntry *e, // terminal. gboolean terminal = g_key_file_get_boolean(e->key_file, e->action, "Terminal", NULL); - if (helper_execute_command(exec_path, fp, terminal, sn ? &context : NULL)) { + if (helper_execute_command(exec_path, fp, terminal, sn, &context)) { char *drun_cach_path = g_build_filename(cache_dir, DRUN_CACHE_FILE, NULL); // Store it based on the unique identifiers (desktop_id). history_set(drun_cach_path, e->desktop_id); @@ -1421,7 +1421,7 @@ static ModeMode drun_mode_result(Mode *sw, int mretv, char **input, gboolean run_in_term = ((mretv & MENU_CUSTOM_ACTION) == MENU_CUSTOM_ACTION); // FIXME: We assume startup notification in terminals, not in others if (!helper_execute_command(NULL, *input, run_in_term, - run_in_term ? &context : NULL)) { + run_in_term, &context)) { retv = RELOAD_DIALOG; } } else if ((mretv & MENU_ENTRY_DELETE) && diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index c0168f72..5054d014 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -498,7 +498,7 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, char *cmd = g_strdup_printf("%s %s", pd->command, d_esc); g_free(d_esc); char *cdir = g_file_get_path(pd->current_dir); - helper_execute_command(cdir, cmd, FALSE, NULL); + helper_execute_command(cdir, cmd, FALSE, FALSE, NULL); g_free(cdir); g_free(cmd); return MODE_EXIT; diff --git a/source/modes/recursivebrowser.c b/source/modes/recursivebrowser.c index d108bd17..83789920 100644 --- a/source/modes/recursivebrowser.c +++ b/source/modes/recursivebrowser.c @@ -420,7 +420,7 @@ static ModeMode recursive_browser_mode_result(Mode *sw, int mretv, char *cmd = g_strdup_printf("%s %s", pd->command, d_esc); g_free(d_esc); char *cdir = g_file_get_path(pd->current_dir); - helper_execute_command(cdir, cmd, FALSE, NULL); + helper_execute_command(cdir, cmd, FALSE, FALSE, NULL); g_free(cdir); g_free(cmd); return MODE_EXIT; diff --git a/source/modes/run.c b/source/modes/run.c index 8144eade..df049921 100644 --- a/source/modes/run.c +++ b/source/modes/run.c @@ -120,7 +120,7 @@ static gboolean exec_cmd(const char *cmd, int run_in_term, const char *orig) { char *hist = g_strdup_printf("%s\x1f%s", orig, cmd); // FIXME: assume startup notification support for terminals if (helper_execute_command(NULL, lf_cmd, run_in_term, - run_in_term ? &context : NULL)) { + run_in_term, &context)) { /** * This happens in non-critical time (After launching app) * It is allowed to be a bit slower. diff --git a/source/modes/window.c b/source/modes/window.c index 6b6d504c..75250d7e 100644 --- a/source/modes/window.c +++ b/source/modes/window.c @@ -852,7 +852,7 @@ static ModeMode window_mode_result(Mode *sw, int mretv, RofiHelperExecuteContext context = {.name = NULL}; if (!helper_execute_command(NULL, lf_cmd, run_in_term, - run_in_term ? &context : NULL)) { + run_in_term, &context)) { retv = RELOAD_DIALOG; } g_free(lf_cmd); diff --git a/source/view.c b/source/view.c index 28d6fb03..d4595e84 100644 --- a/source/view.c +++ b/source/view.c @@ -1482,13 +1482,13 @@ static void rofi_quit_user_callback(RofiViewState *state) { } else if (state->retv & MENU_CANCEL) { if (config.on_menu_canceled == NULL) return; - helper_execute_command(NULL, config.on_menu_canceled, FALSE, NULL); + helper_execute_command(NULL, config.on_menu_canceled, FALSE, FALSE, NULL); } else if (state->retv & MENU_NEXT || state->retv & MENU_PREVIOUS || state->retv & MENU_QUICK_SWITCH || state->retv & MENU_COMPLETE) { if (config.on_mode_changed == NULL) return; // TODO: pass mode name to custom command - helper_execute_command(NULL, config.on_mode_changed, FALSE, NULL); + helper_execute_command(NULL, config.on_mode_changed, FALSE, FALSE, NULL); } }