run-{shell-,}command: expand {app_id} inside the template string

This commit is contained in:
2024-02-26 23:22:06 +00:00
parent c0c861372e
commit 81e9d6ca1f
8 changed files with 21 additions and 13 deletions

View File

@@ -322,7 +322,9 @@ gboolean helper_execute(const char *wd, char **args, const char *error_precmd,
* @param wd The work directory (optional) * @param wd The work directory (optional)
* @param cmd The cmd to execute * @param cmd The cmd to execute
* @param run_in_term Indicate if command should be run in a terminal * @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. * Execute command.
* If needed members of context are NULL, they will be filled. * 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 helper_execute_command(const char *wd, const char *cmd,
gboolean run_in_term, gboolean run_in_term,
gboolean startup_notify,
RofiHelperExecuteContext *context); RofiHelperExecuteContext *context);
/** /**

View File

@@ -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 helper_execute_command(const char *wd, const char *cmd,
gboolean run_in_term, gboolean run_in_term,
gboolean startup_notify,
RofiHelperExecuteContext *context) { RofiHelperExecuteContext *context) {
char **args = NULL; char **args = NULL;
int argc = 0; int argc = 0;
if (run_in_term) { 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); (char *)0);
} else { } 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); (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, static char *helper_get_theme_path_check_file(const char *filename,

View File

@@ -330,7 +330,7 @@ static void launch_link_entry(DRunModeEntry *e) {
g_free(url); g_free(url);
g_debug("Link launch command: |%s|", command); 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); char *path = g_build_filename(cache_dir, DRUN_CACHE_FILE, NULL);
// Store it based on the unique identifiers (desktop_id). // Store it based on the unique identifiers (desktop_id).
history_set(path, e->desktop_id); history_set(path, e->desktop_id);
@@ -509,7 +509,7 @@ static void exec_cmd_entry(DRunModePrivateData *pd, DRunModeEntry *e,
// terminal. // terminal.
gboolean terminal = gboolean terminal =
g_key_file_get_boolean(e->key_file, e->action, "Terminal", NULL); 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); char *drun_cach_path = g_build_filename(cache_dir, DRUN_CACHE_FILE, NULL);
// Store it based on the unique identifiers (desktop_id). // Store it based on the unique identifiers (desktop_id).
history_set(drun_cach_path, e->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); gboolean run_in_term = ((mretv & MENU_CUSTOM_ACTION) == MENU_CUSTOM_ACTION);
// FIXME: We assume startup notification in terminals, not in others // FIXME: We assume startup notification in terminals, not in others
if (!helper_execute_command(NULL, *input, run_in_term, if (!helper_execute_command(NULL, *input, run_in_term,
run_in_term ? &context : NULL)) { run_in_term, &context)) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
} else if ((mretv & MENU_ENTRY_DELETE) && } else if ((mretv & MENU_ENTRY_DELETE) &&

View File

@@ -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); char *cmd = g_strdup_printf("%s %s", pd->command, d_esc);
g_free(d_esc); g_free(d_esc);
char *cdir = g_file_get_path(pd->current_dir); 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(cdir);
g_free(cmd); g_free(cmd);
return MODE_EXIT; return MODE_EXIT;

View File

@@ -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); char *cmd = g_strdup_printf("%s %s", pd->command, d_esc);
g_free(d_esc); g_free(d_esc);
char *cdir = g_file_get_path(pd->current_dir); 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(cdir);
g_free(cmd); g_free(cmd);
return MODE_EXIT; return MODE_EXIT;

View File

@@ -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); char *hist = g_strdup_printf("%s\x1f%s", orig, cmd);
// FIXME: assume startup notification support for terminals // FIXME: assume startup notification support for terminals
if (helper_execute_command(NULL, lf_cmd, run_in_term, 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) * This happens in non-critical time (After launching app)
* It is allowed to be a bit slower. * It is allowed to be a bit slower.

View File

@@ -852,7 +852,7 @@ static ModeMode window_mode_result(Mode *sw, int mretv,
RofiHelperExecuteContext context = {.name = NULL}; RofiHelperExecuteContext context = {.name = NULL};
if (!helper_execute_command(NULL, lf_cmd, run_in_term, if (!helper_execute_command(NULL, lf_cmd, run_in_term,
run_in_term ? &context : NULL)) { run_in_term, &context)) {
retv = RELOAD_DIALOG; retv = RELOAD_DIALOG;
} }
g_free(lf_cmd); g_free(lf_cmd);

View File

@@ -1482,13 +1482,13 @@ static void rofi_quit_user_callback(RofiViewState *state) {
} else if (state->retv & MENU_CANCEL) { } else if (state->retv & MENU_CANCEL) {
if (config.on_menu_canceled == NULL) if (config.on_menu_canceled == NULL)
return; 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 || } else if (state->retv & MENU_NEXT || state->retv & MENU_PREVIOUS ||
state->retv & MENU_QUICK_SWITCH || state->retv & MENU_COMPLETE) { state->retv & MENU_QUICK_SWITCH || state->retv & MENU_COMPLETE) {
if (config.on_mode_changed == NULL) if (config.on_mode_changed == NULL)
return; return;
// TODO: pass mode name to custom command // 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);
} }
} }