From df3495a160878fd28e3642b47087024429bd512f Mon Sep 17 00:00:00 2001 From: Phil Jones Date: Wed, 27 Jul 2022 15:00:05 +0100 Subject: Fix window workspaces in drun mode. Previously, tofi-drun would print the filename of the selected .desktop file to stdout. This could then be passed to `xargs swaymsg exec gio launch` to be executed. The problem is that this ends up defeating the purpose of passing the command to swaymsg exec, and the workspace the command was selected on may not be the one that it starts up on, if for example it takes a long time and the user switches workspaces in the meantime. The solution is to instead print the Exec= line from the .desktop file, and pass that directly to `xargs swaymsg exec --` for execution. To avoid too much breaking of configs for the few people who use tofi currently, this commit adds a new option, --drun-print-exec, to enable the fixed behaviour. A future release will change this to be the default, however. --- src/main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 03dc31e..0587304 100644 --- a/src/main.c +++ b/src/main.c @@ -707,6 +707,8 @@ static void usage() " --horizontal List results horizontally.\n" " --history Sort results by number of usages.\n" " --drun-launch Launch apps directly in drun mode.\n" +" --drun-print-exec Print a command line in drun mode.\n" +" This will become the default in future.\n" " --hint-font Perform font hinting.\n" " --late-keyboard-init (EXPERIMENTAL) Delay keyboard\n" " initialisation until after the first\n" @@ -748,6 +750,7 @@ const struct option long_options[] = { {"hide-cursor", required_argument, NULL, 0}, {"history", required_argument, NULL, 0}, {"drun-launch", required_argument, NULL, 0}, + {"drun-print-exec", required_argument, NULL, 0}, {"hint-font", required_argument, NULL, 0}, {"output", required_argument, NULL, 'o'}, {"late-keyboard-init", no_argument, NULL, 'k'}, @@ -1257,12 +1260,23 @@ int main(int argc, char *argv[]) struct desktop_entry *app = desktop_vec_find(&tofi.window.entry.apps, res); if (app == NULL) { log_error("Couldn't find application file! This shouldn't happen.\n"); + break; } else { res = app->path; } - }; - if (tofi.window.entry.drun && tofi.drun_launch) { - drun_launch(res); + if (tofi.drun_launch) { + drun_launch(res); + } else if (tofi.drun_print_exec) { + drun_print(res); + } else { + log_warning("Using drun mode without --drun-print-exec=true is deprecated.\n" + " In the next version of tofi, this will become the default behaviour,\n" + " so fix your compositor configs now e.g. by replacing\n" + " tofi-drun | xargs swaymsg exec gio launch\n" + " with\n" + " tofi-drun --drun-print-exec=true | xargs swaymsg exec --\n"); + printf("%s\n", res); + } } else { printf("%s\n", res); } -- cgit v1.2.3