From 38c9cb2e265250797ef1a398ee3a6dd91501c076 Mon Sep 17 00:00:00 2001 From: laomuon Date: Wed, 7 Aug 2024 01:16:24 +0200 Subject: [PATCH] WIP --- zathura/shortcuts.c | 3 --- zathura/utils.c | 15 ++++++++++++--- zathura/zathura.h | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/zathura/shortcuts.c b/zathura/shortcuts.c index 230c16df..a0230055 100644 --- a/zathura/shortcuts.c +++ b/zathura/shortcuts.c @@ -1200,7 +1200,6 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL); gtk_tree_view_column_set_alignment(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 1), 1.0f); - gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE); g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), zathura); gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview); @@ -1224,11 +1223,9 @@ bool sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argume zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE); } - // g_idle_add(G_SOURCE_FUNC(index_scroll_to_current_page), zathura); girara_set_view(session, zathura->ui.index); index_scroll_to_current_page(zathura); girara_mode_set(zathura->ui.session, zathura->modes.index); - refresh_view(zathura); } return false; diff --git a/zathura/utils.c b/zathura/utils.c index 7aa5e542..b6d15d4d 100644 --- a/zathura/utils.c +++ b/zathura/utils.c @@ -12,6 +12,7 @@ #include #include +#include "glib.h" #include "links.h" #include "utils.h" #include "zathura.h" @@ -20,6 +21,7 @@ #include "page.h" #include "plugin.h" #include "content-type.h" +#include "zathura/types.h" double zathura_correct_zoom_value(girara_session_t* session, const double zoom) { if (session == NULL) { @@ -126,20 +128,27 @@ static gboolean search_current_index(GtkTreeModel* model, GtkTreePath* UNUSED(pa return FALSE; } +static void tree_view_scroll_to_cell(zathura_t* zathura) +{ + GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data; + GtkTreePath* current_path = gtk_tree_path_new_from_string(zathura->global.current_index_path); + gtk_tree_view_scroll_to_cell(tree_view, current_path, NULL, TRUE, 0.5, 0.0); +} + void index_scroll_to_current_page(zathura_t* zathura) { GtkTreeView* tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data; GtkTreeModel* model = gtk_tree_view_get_model(tree_view); - SearchData search_data; search_data.current_page = zathura_document_get_current_page_number(zathura->document); gtk_tree_model_foreach(model, search_current_index, &search_data); GtkTreePath* current_path = gtk_tree_model_get_path(model, &search_data.current_iter); + zathura->global.current_index_path = gtk_tree_path_to_string(current_path); gtk_tree_view_expand_to_path(tree_view, current_path); - gtk_tree_view_scroll_to_cell(tree_view, current_path, NULL, TRUE, 0.5, 0.0); + + g_idle_add(G_SOURCE_FUNC(tree_view_scroll_to_cell), zathura); gtk_tree_view_set_cursor(tree_view, current_path, NULL, FALSE); - girara_error("%f\n", gtk_adjustment_get_upper(gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(tree_view)))); gtk_tree_path_free(current_path); } diff --git a/zathura/zathura.h b/zathura/zathura.h index 7ee6a186..604246ff 100644 --- a/zathura/zathura.h +++ b/zathura/zathura.h @@ -139,6 +139,7 @@ struct zathura_s { GdkModifierType synctex_edit_modmask; /**< Modifier to trigger synctex edit */ GdkModifierType highlighter_modmask; /**< Modifier to draw with a highlighter */ bool double_click_follow; /**< Double/Single click to follow link */ + char *current_index_path; } global; struct {