From f1d8abcc68e8db72d2222e032d34d81922f23142 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Fri, 22 Apr 2022 23:17:27 +0200 Subject: [PATCH] Use gtk_show_uri_on_window() in utils_open_browser() by default Instead of requiring the user to specify a browser just try to use the system default browser through gtk_show_uri_on_window(). This is done when tool_prefs.browser_cmd is empty which is also the new default. This aligns with windows where we do this already. Though we're bypassing tool_prefs.browser_cmd there entirely, while on non-Windows we still honor tool_prefs.browser_cmd when it's set. This is primarily useful for flatpak support where we cannot just execute arbitrary commands on the host (unless using flatpak-spawn). Also, firefox is arguably a bad default these days, given the declined market share. --- data/geany.glade | 1 + src/keyfile.c | 3 ++- src/utils.c | 27 ++++++++++++++++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/data/geany.glade b/data/geany.glade index 5a6439de67..ddab320979 100644 --- a/data/geany.glade +++ b/data/geany.glade @@ -4842,6 +4842,7 @@ Path (and possibly additional arguments) to your favorite browser False False + System default 1 diff --git a/src/keyfile.c b/src/keyfile.c index f4254f42c3..976d225872 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -91,7 +91,8 @@ #define GEANY_DEFAULT_FONT_MSG_WINDOW "Menlo Medium 12" #define GEANY_DEFAULT_FONT_EDITOR "Menlo Medium 12" #else -#define GEANY_DEFAULT_TOOLS_BROWSER "firefox" +/* Browser chosen by GTK */ +#define GEANY_DEFAULT_TOOLS_BROWSER "" #define GEANY_DEFAULT_FONT_SYMBOL_LIST "Sans 9" #define GEANY_DEFAULT_FONT_MSG_WINDOW "Monospace 9" #define GEANY_DEFAULT_FONT_EDITOR "Monospace 10" diff --git a/src/utils.c b/src/utils.c index 2a8cccddb5..04eee046ba 100644 --- a/src/utils.c +++ b/src/utils.c @@ -64,8 +64,10 @@ /** * Tries to open the given URI in a browser. * On Windows, the system's default browser is opened. - * On non-Windows systems, the browser command set in the preferences dialog is used. In case - * that fails or it is unset, the user is asked to correct or fill it. + * On non-Windows systems, the browser command can be set in the preferences dialog. + * If unset (empty) the system's default browser is used. If set it specifies the + * command to execute. Either way, if it fails the user is prompted to correct the + * pref. * * @param uri The URI to open in the web browser. * @@ -78,15 +80,26 @@ void utils_open_browser(const gchar *uri) g_return_if_fail(uri != NULL); win32_open_browser(uri); #else - gchar *argv[2] = { (gchar *) uri, NULL }; + gchar *new_cmd, *argv[2] = { (gchar *) uri, NULL }; g_return_if_fail(uri != NULL); - while (!spawn_async(NULL, tool_prefs.browser_cmd, argv, NULL, NULL, NULL)) + while (1) { - gchar *new_cmd = dialogs_show_input(_("Select Browser"), GTK_WINDOW(main_widgets.window), - _("Failed to spawn the configured browser command. " - "Please correct it or enter another one."), + /* Uses the user's default browser akin to xdg-open (in flatpak through a portal) */ + if (EMPTY(tool_prefs.browser_cmd)) + { + if (gtk_show_uri_on_window(GTK_WINDOW(main_widgets.window), uri, GDK_CURRENT_TIME, NULL)) + break; + } + else if (spawn_async(NULL, tool_prefs.browser_cmd, argv, NULL, NULL, NULL)) + break; + + /* Allow the user to correct the pref. new_cmd may become empty. */ + new_cmd = dialogs_show_input(_("Select Browser"), GTK_WINDOW(main_widgets.window), + _("Failed to spawn the configured browser command. Please " + "enter a valid command or leave it empty in order " + "to spawn the system default browser."), tool_prefs.browser_cmd); if (new_cmd == NULL) /* user canceled */