diff --git a/callbacks.c b/callbacks.c index bf4377e..5768857 100644 --- a/callbacks.c +++ b/callbacks.c @@ -186,8 +186,15 @@ cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, g_object_unref(model); } -bool -cb_sc_follow(GtkEntry* entry, girara_session_t* session) +typedef enum zathura_link_action_e +{ + ZATHURA_LINK_ACTION_FOLLOW, + ZATHURA_LINK_ACTION_DISPLAY +} zathura_link_action_t; + +static bool +handle_link(GtkEntry* entry, girara_session_t* session, + zathura_link_action_t action) { g_return_val_if_fail(session != NULL, FALSE); g_return_val_if_fail(session->global.data != NULL, FALSE); @@ -226,10 +233,17 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session) zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page_widget), index); if (link != NULL) { - zathura_jumplist_save(zathura); - zathura_link_evaluate(zathura, link); invalid_index = false; - zathura_jumplist_add(zathura); + switch (action) { + case ZATHURA_LINK_ACTION_FOLLOW: + zathura_jumplist_save(zathura); + zathura_link_evaluate(zathura, link); + zathura_jumplist_add(zathura); + break; + case ZATHURA_LINK_ACTION_DISPLAY: + zathura_link_display(zathura, link); + break; + } } } } @@ -243,6 +257,18 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session) return (eval == TRUE) ? TRUE : FALSE; } +bool +cb_sc_follow(GtkEntry* entry, girara_session_t* session) +{ + return handle_link(entry, session, ZATHURA_LINK_ACTION_FOLLOW); +} + +bool +cb_sc_display_link(GtkEntry* entry, girara_session_t* session) +{ + return handle_link(entry, session, ZATHURA_LINK_ACTION_DISPLAY); +} + void cb_file_monitor(GFileMonitor* monitor, GFile* file, GFile* UNUSED(other_file), GFileMonitorEvent event, girara_session_t* session) { diff --git a/callbacks.h b/callbacks.h index 94feaec..4ce2e2e 100644 --- a/callbacks.h +++ b/callbacks.h @@ -80,6 +80,15 @@ void cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, */ bool cb_sc_follow(GtkEntry* entry, girara_session_t* session); +/** + * Called when input has been passed to the sc_display_link dialog + * + * @param entry The dialog inputbar + * @param session The girara session + * @return true if no error occured and the event has been handled + */ +bool cb_sc_display_link(GtkEntry* entry, girara_session_t* session); + /** * Emitted when file has been changed * diff --git a/config.c b/config.c index fa4a734..73327ed 100644 --- a/config.c +++ b/config.c @@ -209,6 +209,8 @@ config_load_default(zathura_t* zathura) girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, NORMAL, ZATHURA_ADJUST_BESTFIT, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_s, NULL, sc_adjust_window, NORMAL, ZATHURA_ADJUST_WIDTH, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_F, NULL, sc_display_link, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); girara_shortcut_add(gsession, 0, GDK_KEY_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); @@ -381,6 +383,7 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "abort", sc_abort); girara_shortcut_mapping_add(gsession, "adjust_window", sc_adjust_window); girara_shortcut_mapping_add(gsession, "change_mode", sc_change_mode); + girara_shortcut_mapping_add(gsession, "display_link", sc_display_link); girara_shortcut_mapping_add(gsession, "jumplist", sc_jumplist); girara_shortcut_mapping_add(gsession, "follow", sc_follow); girara_shortcut_mapping_add(gsession, "goto", sc_goto); diff --git a/links.c b/links.c index 492b3f9..0e2c400 100644 --- a/links.c +++ b/links.c @@ -169,6 +169,28 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link) } } +void +zathura_link_display(zathura_t* zathura, zathura_link_t* link) +{ + zathura_link_type_t type = zathura_link_get_type(link); + zathura_link_target_t target = zathura_link_get_target(link); + switch (type) { + case ZATHURA_LINK_GOTO_DEST: + girara_notify(zathura->ui.session, GIRARA_INFO, _("Link: page %d"), + target.page_number); + break; + case ZATHURA_LINK_GOTO_REMOTE: + case ZATHURA_LINK_URI: + case ZATHURA_LINK_LAUNCH: + case ZATHURA_LINK_NAMED: + girara_notify(zathura->ui.session, GIRARA_INFO, _("Link: %s"), + target.value); + break; + default: + girara_notify(zathura->ui.session, GIRARA_ERROR, _("Link: Invalid")); + } +} + static void link_remote(zathura_t* zathura, const char* file) { diff --git a/links.h b/links.h index 3dbf8df..8d8728e 100644 --- a/links.h +++ b/links.h @@ -56,4 +56,12 @@ zathura_link_target_t zathura_link_get_target(zathura_link_t* link); */ void zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link); +/** + * Display a link using girara_notify + * + * @param zathura Zathura instance + * @param link The link + */ +void zathura_link_display(zathura_t* zathura, zathura_link_t* link); + #endif // LINK_H diff --git a/shortcuts.c b/shortcuts.c index 59370e2..9d70fbc 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -18,6 +18,39 @@ #include "print.h" #include "page-widget.h" +/* Helper function; see sc_display_link and sc_follow. */ +static bool +draw_links(zathura_t* zathura) +{ + /* set pages to draw links */ + bool show_links = false; + unsigned int page_offset = 0; + unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); + for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) { + zathura_page_t* page = zathura_document_get_page(zathura->document, page_id); + if (page == NULL) { + continue; + } + + GtkWidget* page_widget = zathura_page_get_widget(zathura, page); + g_object_set(page_widget, "search-results", NULL, NULL); + if (zathura_page_get_visibility(page) == true) { + g_object_set(page_widget, "draw-links", TRUE, NULL); + + int number_of_links = 0; + g_object_get(page_widget, "number-of-links", &number_of_links, NULL); + if (number_of_links != 0) { + show_links = true; + } + g_object_set(page_widget, "offset-links", page_offset, NULL); + page_offset += number_of_links; + } else { + g_object_set(page_widget, "draw-links", FALSE, NULL); + } + } + return show_links; +} + bool sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) @@ -182,6 +215,30 @@ sc_change_mode(girara_session_t* session, girara_argument_t* argument, return false; } +bool +sc_display_link(girara_session_t* session, girara_argument_t* UNUSED(argument), + girara_event_t* UNUSED(event), unsigned int UNUSED(t)) +{ + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + + if (zathura->document == NULL || zathura->ui.session == NULL) { + return false; + } + + bool show_links = draw_links(zathura); + + /* ask for input */ + if (show_links) { + girara_dialog(zathura->ui.session, "Display link:", FALSE, NULL, + (girara_callback_inputbar_activate_t) cb_sc_display_link, + zathura->ui.session); + } + + return false; +} + bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { @@ -248,32 +305,7 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), return false; } - /* set pages to draw links */ - bool show_links = false; - unsigned int page_offset = 0; - unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); - for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) { - zathura_page_t* page = zathura_document_get_page(zathura->document, page_id); - if (page == NULL) { - continue; - } - - GtkWidget* page_widget = zathura_page_get_widget(zathura, page); - g_object_set(page_widget, "search-results", NULL, NULL); - if (zathura_page_get_visibility(page) == true) { - g_object_set(page_widget, "draw-links", TRUE, NULL); - - int number_of_links = 0; - g_object_get(page_widget, "number-of-links", &number_of_links, NULL); - if (number_of_links != 0) { - show_links = true; - } - g_object_set(page_widget, "offset-links", page_offset, NULL); - page_offset += number_of_links; - } else { - g_object_set(page_widget, "draw-links", FALSE, NULL); - } - } + bool show_links = draw_links(zathura); /* ask for input */ if (show_links == true) { diff --git a/shortcuts.h b/shortcuts.h index d623d3e..3572cf1 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -38,6 +38,17 @@ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, gi */ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); +/** + * Display a link + * + * @param session The used girara session + * @param argument The used argument + * @param event Girara event + * @param t Number of executions + * @return true if no error occured otherwise false + */ +bool sc_display_link(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); + /** * Shortcut function to focus the inputbar *