From eb1fe0a64d6e345ddd22eecf1784634101400f27 Mon Sep 17 00:00:00 2001 From: belstes Date: Fri, 11 Sep 2020 14:48:27 +0200 Subject: [PATCH] Bookmark command line argument --- zathura/commands.c | 2 +- zathura/dbus-interface.c | 2 +- zathura/main.c | 12 ++++++++++-- zathura/zathura.c | 14 +++++++++++++- zathura/zathura.h | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/zathura/commands.c b/zathura/commands.c index f52215b..d14241b 100644 --- a/zathura/commands.c +++ b/zathura/commands.c @@ -253,7 +253,7 @@ cmd_open(girara_session_t* session, girara_list_t* argument_list) document_open_idle(zathura, girara_list_nth(argument_list, 0), (argc == 2) ? girara_list_nth(argument_list, 1) : NULL, - ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL, NULL, NULL); + ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL, NULL, NULL, NULL); } else { girara_notify(session, GIRARA_ERROR, _("No arguments given.")); return false; diff --git a/zathura/dbus-interface.c b/zathura/dbus-interface.c index e7f4c5b..69c7ebd 100644 --- a/zathura/dbus-interface.c +++ b/zathura/dbus-interface.c @@ -222,7 +222,7 @@ handle_open_document(zathura_t* zathura, GVariant* parameters, document_open_idle(zathura, filename, strlen(password) > 0 ? password : NULL, page, - NULL, NULL, NULL); + NULL, NULL, NULL, NULL); g_free(filename); g_free(password); diff --git a/zathura/main.c b/zathura/main.c index 690d88e..5f81e9a 100644 --- a/zathura/main.c +++ b/zathura/main.c @@ -135,6 +135,7 @@ main(int argc, char* argv[]) gchar* synctex_editor = NULL; gchar* synctex_fwd = NULL; gchar* mode = NULL; + gchar* bookmark_name = NULL; gchar* search_string = NULL; bool forkback = false; bool print_version = false; @@ -157,6 +158,7 @@ main(int argc, char* argv[]) { "synctex-forward", '\0', 0, G_OPTION_ARG_STRING, &synctex_fwd, _("Move to given synctex position"), "position" }, { "synctex-pid", '\0', 0, G_OPTION_ARG_INT, &synctex_pid, _("Highlight given position in the given process"), "pid" }, { "mode", '\0', 0, G_OPTION_ARG_STRING, &mode, _("Start in a non-default mode"), "mode" }, + { "bookmark", 'b', 0, G_OPTION_ARG_STRING, &bookmark_name, _("Bookmark to go to"), "bookmark" }, { "find", 'f', 0, G_OPTION_ARG_STRING, &search_string, _("Search for the given phrase and display results"), "string" }, { NULL, '\0', 0, 0, NULL, NULL, NULL } }; @@ -298,8 +300,13 @@ main(int argc, char* argv[]) if (page_number > 0) { --page_number; } - document_open_idle(zathura, argv[file_idx], password, page_number, mode, - synctex_fwd, search_string); + document_open_idle(zathura, argv[file_idx], password, page_number, + mode, synctex_fwd, bookmark_name, search_string); + } else if (bookmark_name != NULL) { + girara_error("Can not use bookmark argument when no file is given"); + ret = -1; + zathura_free(zathura); + goto free_and_ret; } else if (search_string != NULL) { girara_error("Can not use find argument when no file is given"); ret = -1; @@ -323,6 +330,7 @@ free_and_ret: g_free(synctex_editor); g_free(synctex_fwd); g_free(mode); + g_free(bookmark_name); g_free(search_string); return ret; diff --git a/zathura/zathura.c b/zathura/zathura.c index 29ec68b..8f09128 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -57,6 +57,7 @@ typedef struct zathura_document_info_s { int page_number; char* mode; char* synctex; + char* bookmark_name; char* search_string; } zathura_document_info_t; @@ -78,6 +79,7 @@ free_document_info(zathura_document_info_t* document_info) g_free(document_info->password); g_free(document_info->mode); g_free(document_info->synctex); + g_free(document_info->bookmark_name); g_free(document_info->search_string); g_free(document_info); } @@ -883,6 +885,13 @@ document_info_open(gpointer data) } } + if (document_info->bookmark_name != NULL) { + girara_list_t* arg_list = girara_list_new(); + girara_list_append(arg_list, document_info->bookmark_name); + cmd_bookmark_open(document_info->zathura->ui.session, arg_list); + girara_list_free(arg_list); + } + if (document_info->search_string != NULL) { girara_argument_t search_arg; search_arg.n = 1; // Forward search @@ -1309,7 +1318,7 @@ document_open_synctex(zathura_t* zathura, const char* path, const char* uri, void document_open_idle(zathura_t* zathura, const char* path, const char* password, int page_number, const char* mode, const char* synctex, - const char *search_string) + const char* bookmark_name, const char *search_string) { g_return_if_fail(zathura != NULL); g_return_if_fail(path != NULL); @@ -1331,6 +1340,9 @@ document_open_idle(zathura_t* zathura, const char* path, const char* password, if (synctex != NULL) { document_info->synctex = g_strdup(synctex); } + if (bookmark_name != NULL) { + document_info->bookmark_name = g_strdup(bookmark_name); + } if (search_string != NULL) { document_info->search_string = g_strdup(search_string); } diff --git a/zathura/zathura.h b/zathura/zathura.h index 566a77a..c2165a7 100644 --- a/zathura/zathura.h +++ b/zathura/zathura.h @@ -343,7 +343,7 @@ bool document_open_synctex(zathura_t* zathura, const char* path, const char* uri void document_open_idle(zathura_t* zathura, const char* path, const char* password, int page_number, const char* mode, const char* synctex, - const char* search_string); + const char* bookmark_name, const char *search_string); /** * Save a open file