diff --git a/callbacks.c b/callbacks.c index a14e077..07d460b 100644 --- a/callbacks.c +++ b/callbacks.c @@ -91,20 +91,6 @@ cb_pages_per_row_value_changed(girara_session_t* UNUSED(session), girara_setting page_view_set_mode(zathura, pages_per_row); } -typedef struct page_set_delayed_s { - zathura_t* zathura; - unsigned int page; -} page_set_delayed_t; - -static gboolean -page_set_delayed(gpointer data) { - page_set_delayed_t* p = data; - page_set(p->zathura, p->page); - - g_free(p); - return FALSE; -} - void cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, GtkTreeViewColumn* UNUSED(column), zathura_t* zathura) @@ -129,10 +115,7 @@ cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, if (index_element->type == ZATHURA_LINK_TO_PAGE) { sc_toggle_index(zathura->ui.session, NULL, 0); - page_set_delayed_t* p = g_malloc(sizeof(page_set_delayed_t)); - p->zathura = zathura; - p->page = index_element->target.page_number; - g_idle_add(page_set_delayed, p); + page_set_delayed(zathura, index_element->target.page_number); } else if (index_element->type == ZATHURA_LINK_EXTERNAL) { // TODO } diff --git a/zathura.c b/zathura.c index 610e172..6747261 100644 --- a/zathura.c +++ b/zathura.c @@ -340,6 +340,13 @@ document_open(zathura_t* zathura, const char* path, const char* password) girara_warning("Failed to load bookmarks for %s.\n", zathura->document->file_path); } + unsigned int page = 0u; + int offset = 0; + float scale = 1.0f; + if (zathura_db_get_fileinfo(zathura->database, zathura->document->file_path, &page, &offset, &scale)) { + page_set_delayed(zathura, page); + } + return true; error_free: @@ -408,6 +415,35 @@ document_close(zathura_t* zathura) return true; } +typedef struct page_set_delayed_s { + zathura_t* zathura; + unsigned int page; +} page_set_delayed_t; + +static gboolean +page_set_delayed_impl(gpointer data) { + page_set_delayed_t* p = data; + page_set(p->zathura, p->page); + + g_free(p); + return FALSE; +} + +bool +page_set_delayed(zathura_t* zathura, unsigned int page_id) +{ + if (zathura == NULL || zathura->document == NULL || zathura->document->pages == NULL || + page_id >= zathura->document->number_of_pages) { + return false; + } + + page_set_delayed_t* p = g_malloc(sizeof(page_set_delayed_t)); + p->zathura = zathura; + p->page = page_id; + g_idle_add(page_set_delayed_impl, p); + return true; +} + bool page_set(zathura_t* zathura, unsigned int page_id) { diff --git a/zathura.h b/zathura.h index 163d094..732764c 100644 --- a/zathura.h +++ b/zathura.h @@ -162,6 +162,14 @@ bool document_close(zathura_t* zathura); */ bool page_set(zathura_t* zathura, unsigned int page_id); +/** + * Opens the page with the given number (delayed) + * + * @param zathura The zathura session + * @return If no error occured true, otherwise false, is returned. + */ +bool page_set_delayed(zathura_t* zathura, unsigned int page_id); + /** * Builds the box structure to show the rendered pages *