Merge branch 'issue-38' into 'develop'

Fix clearing of hightlighted links

Closes #38

See merge request pwmt/zathura!73
This commit is contained in:
Sebastian Ramacher 2023-12-04 23:03:09 +01:00
commit 7a8419cc95
3 changed files with 82 additions and 76 deletions

View File

@ -408,49 +408,42 @@ handle_link(GtkEntry* entry, girara_session_t* session,
index = index - 1; index = index - 1;
} }
/* set pages to draw links */ /* find the link*/
bool invalid_index = true; zathura_link_t* link = NULL;
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); 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++) { 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); zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL || zathura_page_get_visibility(page) == false) { if (page == NULL || zathura_page_get_visibility(page) == false || eval == false) {
continue; continue;
} }
GtkWidget* page_widget = zathura_page_get_widget(zathura, page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
g_object_set(G_OBJECT(page_widget), "draw-links", FALSE, NULL); link = zathura_page_widget_link_get(ZATHURA_PAGE(page_widget), index);
if (eval == FALSE) {
/* nothing to evaluate */
continue;
}
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page_widget), index);
if (link != NULL) { if (link != NULL) {
invalid_index = false; break;
switch (action) {
case ZATHURA_LINK_ACTION_FOLLOW:
zathura_link_evaluate(zathura, link);
break;
case ZATHURA_LINK_ACTION_DISPLAY:
zathura_link_display(zathura, link);
break;
case ZATHURA_LINK_ACTION_COPY: {
GdkAtom* selection = get_selection(zathura);
if (selection == NULL) {
break;
}
zathura_link_copy(zathura, link, selection);
g_free(selection);
break;
}
}
} }
} }
if (eval == TRUE && invalid_index == true) { if (eval == TRUE && link == NULL) {
girara_notify(session, GIRARA_WARNING, _("Invalid index '%s' given."), input); girara_notify(session, GIRARA_WARNING, _("Invalid index '%s' given."), input);
} else {
switch (action) {
case ZATHURA_LINK_ACTION_FOLLOW:
zathura_link_evaluate(zathura, link);
break;
case ZATHURA_LINK_ACTION_DISPLAY:
zathura_link_display(zathura, link);
break;
case ZATHURA_LINK_ACTION_COPY: {
GdkAtom* selection = get_selection(zathura);
if (selection == NULL) {
break;
}
zathura_link_copy(zathura, link, selection);
g_free(selection);
break;
}
}
} }
g_free(input); g_free(input);
@ -834,3 +827,24 @@ cb_gesture_zoom_scale_changed(GtkGestureZoom* UNUSED(self), gdouble scale, void*
render_all(zathura); render_all(zathura);
refresh_view(zathura); refresh_view(zathura);
} }
void cb_hide_links(GtkWidget* widget, gpointer data) {
g_return_if_fail(widget != NULL);
g_return_if_fail(data != NULL);
/* disconnect from signal */
gulong handler_id = GPOINTER_TO_UINT(g_object_steal_data(G_OBJECT(widget), "handler_id"));
g_signal_handler_disconnect(G_OBJECT(widget), handler_id);
zathura_t* zathura = data;
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(G_OBJECT(page_widget), "draw-links", FALSE, NULL);
}
}

View File

@ -285,4 +285,12 @@ void cb_gesture_zoom_begin(GtkGesture* self, GdkEventSequence* sequence, void* d
void cb_gesture_zoom_scale_changed(GtkGestureZoom* self, gdouble scale, void* data); void cb_gesture_zoom_scale_changed(GtkGestureZoom* self, gdouble scale, void* data);
/**
* Clears all highlighted links when the inputbar gets closed
*
* @param GtkWidget* Inputbar widget
* @param data The zathura instance
*/
void cb_hide_links(GtkWidget* widget, gpointer data);
#endif // CALLBACKS_H #endif // CALLBACKS_H

View File

@ -21,7 +21,7 @@
#include "adjustment.h" #include "adjustment.h"
#include <math.h> #include <math.h>
/* Helper function; see sc_display_link and sc_follow. */ /* Helper function for highlighting the links */
static bool static bool
draw_links(zathura_t* zathura) draw_links(zathura_t* zathura)
{ {
@ -55,6 +55,30 @@ draw_links(zathura_t* zathura)
return show_links; return show_links;
} }
/* Common code for sc_follow, sc_display_link and sc_copy_link */
static bool
link_shortcuts(zathura_t* zathura, girara_callback_inputbar_activate_t callback,
const char* text)
{
if (zathura->document == NULL || zathura->ui.session == NULL) {
return false;
}
bool show_links = draw_links(zathura);
/* ask for input */
if (show_links == true) {
GtkWidget *inputbar = zathura->ui.session->gtk.inputbar;
gulong handler_id = g_signal_connect(inputbar, "hide", G_CALLBACK(cb_hide_links), zathura);
g_object_set_data(G_OBJECT(inputbar), "handler_id", GUINT_TO_POINTER(handler_id));
zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR);
girara_dialog(zathura->ui.session, text, FALSE, NULL, callback, zathura->ui.session);
}
return false;
}
bool bool
sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
@ -133,21 +157,7 @@ sc_display_link(girara_session_t* session, girara_argument_t* UNUSED(argument),
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data; zathura_t* zathura = session->global.data;
if (zathura->document == NULL || zathura->ui.session == NULL) { return link_shortcuts(zathura, cb_sc_display_link, "Display Link: ");
return false;
}
bool show_links = draw_links(zathura);
/* ask for input */
if (show_links) {
zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR);
girara_dialog(zathura->ui.session, "Display link:", FALSE, NULL,
cb_sc_display_link,
zathura->ui.session);
}
return false;
} }
bool bool
@ -158,21 +168,7 @@ sc_copy_link(girara_session_t* session, girara_argument_t* UNUSED(argument),
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data; zathura_t* zathura = session->global.data;
if (zathura->document == NULL || zathura->ui.session == NULL) { return link_shortcuts(zathura, cb_sc_copy_link, "Copy Link: ");
return false;
}
bool show_links = draw_links(zathura);
/* ask for input */
if (show_links) {
zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR);
girara_dialog(zathura->ui.session, "Copy link:", FALSE, NULL,
cb_sc_copy_link,
zathura->ui.session);
}
return false;
} }
bool bool
@ -272,19 +268,7 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data; zathura_t* zathura = session->global.data;
if (zathura->document == NULL || zathura->ui.session == NULL) { return link_shortcuts(zathura, cb_sc_follow, "Follow Link: ");
return false;
}
bool show_links = draw_links(zathura);
/* ask for input */
if (show_links == true) {
zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR);
girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, cb_sc_follow, zathura->ui.session);
}
return false;
} }
bool bool