From 2b9b8a9c7046f14f64cc2416d396540c4ce23123 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 4 Dec 2023 23:01:34 +0100 Subject: [PATCH] Add callback that clears highlighted links when inputbar is hidden Since hiding the inputbar marks the end of the `follow a link` action, clearing all links at that event ensures that it will work in all possible situations. --- zathura/callbacks.c | 21 +++++++++++++++++++++ zathura/callbacks.h | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/zathura/callbacks.c b/zathura/callbacks.c index 6fa1cfc..9a2d38b 100644 --- a/zathura/callbacks.c +++ b/zathura/callbacks.c @@ -834,3 +834,24 @@ cb_gesture_zoom_scale_changed(GtkGestureZoom* UNUSED(self), gdouble scale, void* render_all(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); + } +} diff --git a/zathura/callbacks.h b/zathura/callbacks.h index c8520ee..786a8e4 100644 --- a/zathura/callbacks.h +++ b/zathura/callbacks.h @@ -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); +/** + * 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