summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--completions/tofi1
-rw-r--r--doc/config5
-rw-r--r--doc/tofi.5.md10
-rw-r--r--doc/tofi.5.scd9
-rw-r--r--src/config.c2
-rw-r--r--src/drun.c26
-rw-r--r--src/drun.h2
-rw-r--r--src/main.c12
-rw-r--r--src/tofi.h2
9 files changed, 61 insertions, 8 deletions
diff --git a/completions/tofi b/completions/tofi
index b23e4a8..2fdf549 100644
--- a/completions/tofi
+++ b/completions/tofi
@@ -49,6 +49,7 @@ _tofi()
--hide-input
--hidden-character
--drun-launch
+ --terminal
--hint-font
--late-keyboard-init
)
diff --git a/doc/config b/doc/config
index d7ec8b5..530e768 100644
--- a/doc/config
+++ b/doc/config
@@ -158,6 +158,11 @@
# Otherwise, just print the command line to stdout.
drun-launch = false
+ # The terminal to run terminal programs in when in drun mode.
+ # This option has no effect if drun-launch is set to true.
+ # Defaults to the value of the TERMINAL environment variable.
+ # terminal = foot
+
# Delay keyboard initialisation until after the first draw to screen.
# This option is experimental, and will cause tofi to miss keypresses
# for a short time after launch. The only reason to use this option is
diff --git a/doc/tofi.5.md b/doc/tofi.5.md
index 2ddabb4..87e3b64 100644
--- a/doc/tofi.5.md
+++ b/doc/tofi.5.md
@@ -82,13 +82,21 @@ options.
>
> Default: false
+**terminal**=*command*
+
+> The terminal to run terminal programs in when in drun mode. *command*
+> will be prepended to the the application's command line. This option
+> has no effect if **drun-launch** is set to true.
+>
+> Default: the value of the TERMINAL environment variable
+
**drun-print-exec**=*true\|false*
> **WARNING**: In the current version of tofi, this option has changed
> to always be true and has no effect, as it should have been from the
> start. It may be removed in a future version of tofi.
>
-> Default: true.
+> Default: true
**late-keyboard-init**=*true\|false*
diff --git a/doc/tofi.5.scd b/doc/tofi.5.scd
index 7e16ea7..95f87d9 100644
--- a/doc/tofi.5.scd
+++ b/doc/tofi.5.scd
@@ -76,12 +76,19 @@ options.
Default: false
+*terminal*=_command_
+ The terminal to run terminal programs in when in drun mode. _command_
+ will be prepended to the the application's command line.
+ This option has no effect if *drun-launch* is set to true.
+
+ Default: the value of the TERMINAL environment variable
+
*drun-print-exec*=_true|false_
*WARNING*: In the current version of tofi, this option has changed to
always be true and has no effect, as it should have been from the
start. It may be removed in a future version of tofi.
- Default: true.
+ Default: true
*late-keyboard-init*=_true|false_
Delay keyboard initialisation until after the first draw to screen.
diff --git a/src/config.c b/src/config.c
index 915e548..4305c3e 100644
--- a/src/config.c
+++ b/src/config.c
@@ -431,6 +431,8 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const
} else if (strcasecmp(option, "drun-print-exec") == 0) {
log_warning("drun-print-exec is deprecated, as it is now always true.\n"
" This option may be removed in a future version of tofi.\n");
+ } else if (strcasecmp(option, "terminal") == 0) {
+ snprintf(tofi->default_terminal, N_ELEM(tofi->default_terminal), "%s", value);
} else if (strcasecmp(option, "hint-font") == 0) {
tofi->window.entry.harfbuzz.disable_hinting = !parse_bool(filename, lineno, value, &err);
} else if (strcasecmp(option, "late-keyboard-init") == 0) {
diff --git a/src/drun.c b/src/drun.c
index 3ab42d0..9c6ead8 100644
--- a/src/drun.c
+++ b/src/drun.c
@@ -278,7 +278,7 @@ struct desktop_vec drun_generate_cached()
return apps;
}
-void drun_print(const char *filename)
+void drun_print(const char *filename, const char *terminal_command)
{
GKeyFile *file = g_key_file_new();
if (!g_key_file_load_from_file(file, filename, G_KEY_FILE_NONE, NULL)) {
@@ -326,8 +326,18 @@ void drun_print(const char *filename)
}
string_vec_add(&pieces, last);
- /* Build the command line from our vector. */
- for (size_t i = 0; i < pieces.count; i++) {
+ /*
+ * If this is a terminal application, the command line needs to be
+ * preceded by the terminal command.
+ */
+ bool terminal = g_key_file_get_boolean(file, group, "Terminal", NULL);
+ if (terminal) {
+ fputs(terminal_command, stdout);
+ fputc(' ', stdout);
+ }
+
+ /* Build the command line from our vector. */
+ for (size_t i = 0; i < pieces.count; i++) {
fputs(pieces.buf[i].string, stdout);
}
fputc('\n', stdout);
@@ -341,11 +351,19 @@ void drun_launch(const char *filename)
{
GDesktopAppInfo *info = g_desktop_app_info_new_from_filename(filename);
GAppLaunchContext *context = g_app_launch_context_new();
+ GError *err = NULL;
- if (!g_app_info_launch((GAppInfo *)info, NULL, context, NULL)) {
+ if (!g_app_info_launch((GAppInfo *)info, NULL, context, &err)) {
log_error("Failed to launch %s.\n", filename);
+ log_error("%s.\n", err->message);
+ log_error(
+ "If this is a terminal issue, you can use `--drun-launch=false`,\n"
+ " and pass your preferred terminal command to `--terminal`.\n"
+ " For more information, see https://gitlab.gnome.org/GNOME/glib/-/issues/338\n"
+ " and https://github.com/philj56/tofi/issues/46.\n");
}
+ g_clear_error(&err);
g_object_unref(context);
g_object_unref(info);
}
diff --git a/src/drun.h b/src/drun.h
index 207d384..8e65d26 100644
--- a/src/drun.h
+++ b/src/drun.h
@@ -8,7 +8,7 @@
struct desktop_vec drun_generate(void);
struct desktop_vec drun_generate_cached(void);
void drun_history_sort(struct desktop_vec *apps, struct history *history);
-void drun_print(const char *filename);
+void drun_print(const char *filename, const char *terminal_command);
void drun_launch(const char *filename);
#endif /* DRUN_H */
diff --git a/src/main.c b/src/main.c
index 3e84f49..900066b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -678,6 +678,8 @@ static void usage()
" --drun-print-exec <true|false> Print a command line in drun mode.\n"
" This is now always the case,\n"
" and this option is deprecated.\n"
+" --terminal <command> Terminal to use for command line\n"
+" programs in drun mode.\n"
" --hint-font <true|false> Perform font hinting.\n"
" --late-keyboard-init (EXPERIMENTAL) Delay keyboard\n"
" initialisation until after the first\n"
@@ -729,6 +731,7 @@ const struct option long_options[] = {
{"hidden-character", required_argument, NULL, 0},
{"drun-launch", required_argument, NULL, 0},
{"drun-print-exec", required_argument, NULL, 0},
+ {"terminal", required_argument, NULL, 0},
{"hint-font", required_argument, NULL, 0},
{"output", required_argument, NULL, 0},
{"scale", required_argument, NULL, 0},
@@ -835,7 +838,7 @@ static bool do_submit(struct tofi *tofi)
if (tofi->drun_launch) {
drun_launch(res);
} else {
- drun_print(res);
+ drun_print(res, tofi->default_terminal);
}
} else {
printf("%s\n", res);
@@ -894,6 +897,13 @@ int main(int argc, char *argv[])
.use_scale = true,
};
wl_list_init(&tofi.output_list);
+ if (getenv("TERMINAL") != NULL) {
+ snprintf(
+ tofi.default_terminal,
+ N_ELEM(tofi.default_terminal),
+ "%s",
+ getenv("TERMINAL"));
+ }
parse_args(&tofi, argc, argv);
diff --git a/src/tofi.h b/src/tofi.h
index be3e821..994ee0f 100644
--- a/src/tofi.h
+++ b/src/tofi.h
@@ -11,6 +11,7 @@
#include "wlr-layer-shell-unstable-v1.h"
#define MAX_OUTPUT_NAME_LEN 256
+#define MAX_TERMINAL_NAME_LEN 256
struct output_list_element {
struct wl_list link;
@@ -88,6 +89,7 @@ struct tofi {
bool fuzzy_match;
bool require_match;
char target_output_name[MAX_OUTPUT_NAME_LEN];
+ char default_terminal[MAX_TERMINAL_NAME_LEN];
};
#endif /* TOFI_H */