Skip to content

Commit ea8a0a3

Browse files
committed
Fix opening files, as xdg-open fails for terminal programs.
1 parent ea148cb commit ea8a0a3

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/build*/
22
/.cache/
33
/.vscode/
4+
tags
45

56
# I want to ignore log files
67
*.log

include/helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ typedef struct {
303303
const gchar *command;
304304
} RofiHelperExecuteContext;
305305

306+
void helper_launch_default(const char *filepath);
307+
306308
/**
307309
* @param wd The working directory.
308310
* @param args The arguments of the command to exec.

source/helper.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
#include <sys/types.h>
5555
#include <unistd.h>
5656

57+
#include <glib/gconvert.h>
58+
#include <gio/gdesktopappinfo.h>
59+
5760
const char *const MatchingMethodStr[MM_NUM_MATCHERS] = {
5861
"Normal", "Regex", "Glob", "Fuzzy", "Prefix"};
5962

@@ -1072,6 +1075,16 @@ gboolean helper_execute(const char *wd, char **args, const char *error_precmd,
10721075
return retv;
10731076
}
10741077

1078+
void helper_launch_default(const char *filepath)
1079+
{
1080+
GError *error = NULL;
1081+
char *uri = g_filename_to_uri(filepath, NULL, &error);
1082+
if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) {
1083+
g_printerr("Failed to open directory: %s\n", error->message);
1084+
g_error_free(error);
1085+
}
1086+
}
1087+
10751088
gboolean helper_execute_command(const char *wd, const char *cmd,
10761089
gboolean run_in_term,
10771090
RofiHelperExecuteContext *context) {

source/modes/filebrowser.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,11 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input,
506506
get_file_browser(sw);
507507
return RESET_DIALOG;
508508
}
509-
} else if ((pd->array[selected_line].type == RFILE) ||
510-
(pd->array[selected_line].type == DIRECTORY &&
511-
special_command)) {
509+
} else if (pd->array[selected_line].type == RFILE) {
510+
char *filepath = pd->array[selected_line].path;
511+
helper_launch_default(filepath);
512+
return MODE_EXIT;
513+
} else if (pd->array[selected_line].type == DIRECTORY && special_command) {
512514
char *d_esc = g_shell_quote(pd->array[selected_line].path);
513515
char *cmd = g_strdup_printf("%s %s", pd->command, d_esc);
514516
g_free(d_esc);

0 commit comments

Comments
 (0)