diff --git a/types.c b/types.c index 11ee0c2..568c867 100644 --- a/types.c +++ b/types.c @@ -27,6 +27,14 @@ zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position, return NULL; } + link->target.value = g_strdup(target.value); + break; + case ZATHURA_LINK_LAUNCH: + if (target.value == NULL) { + g_free(link); + return NULL; + } + link->target.value = g_strdup(target.value); break; default: diff --git a/utils.c b/utils.c index 43da517..3c30ba2 100644 --- a/utils.c +++ b/utils.c @@ -327,6 +327,35 @@ readjust_view_after_zooming(zathura_t *zathura, float old_zoom) { position_set_delayed(zathura, valx, valy); } +static void +link_launch(zathura_t* zathura, zathura_link_t* link) +{ + if (zathura == NULL || link == NULL || zathura->document == NULL) { + return; + } + + /* get file path */ + if (link->target.value == NULL) { + return; + }; + + char* path = NULL; + if (g_path_is_absolute(link->target.value) == TRUE) { + path = g_strdup(link->target.value); + } else { + const char* document = zathura_document_get_path(zathura->document); + char* dir = g_path_get_dirname(document); + path = g_build_filename(dir, link->target.value, NULL); + g_free(dir); + } + + if (girara_xdg_open(path) == false) { + girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open.")); + } + + g_free(path); +} + void zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link) { @@ -346,6 +375,9 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link) girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open.")); } break; + case ZATHURA_LINK_LAUNCH: + link_launch(zathura, link); + break; default: break; }