Move url prefix removal to open_browser

This way, it also applies to middle clicks.
Incidentally, it seems this fixed a crash when opening <a href> urls.
This commit is contained in:
Reto Schnyder 2017-06-29 19:53:10 +02:00
parent e04bfe0a58
commit c8e6f317ab
2 changed files with 11 additions and 19 deletions

View File

@ -94,11 +94,16 @@ char *extract_urls(const char *to_match)
* Open url in browser.
*
*/
void open_browser(const char *url)
{
void open_browser(const char *in) {
// remove prefix and test url
char *url = extract_urls(in);
if (!url)
return;
int browser_pid1 = fork();
if (browser_pid1) {
g_free(url);
int status;
waitpid(browser_pid1, &status, 0);
} else {
@ -164,23 +169,10 @@ void dispatch_menu_result(const char *input)
{
char *in = g_strdup(input);
g_strstrip(in);
switch (in[0]) {
case '#':
if (in[0] == '#') {
invoke_action(in + 1);
break;
case '[': // named url. skip name and continue
in = strchr(in, ']');
if (in == NULL)
break;
default:
{ // test and open url
char *maybe_url = extract_urls(in);
if (maybe_url) {
open_browser(maybe_url);
g_free(maybe_url);
break;
}
}
} else {
open_browser(in);
}
g_free(in);
}

View File

@ -3,7 +3,7 @@
#define DUNST_MENU_H
char *extract_urls(const char *to_match);
void open_browser(const char *url);
void open_browser(const char *in);
void invoke_action(const char *action);
void regex_teardown(void);