Preserve zoom / current page on reload

Fixes #408
This commit is contained in:
gi1242 gi1242 2024-03-24 15:33:10 -04:00
parent 3450c68d43
commit a1ff4c2d00
4 changed files with 42 additions and 12 deletions

View File

@ -539,7 +539,7 @@ cb_password_dialog(GtkEntry* entry, void* data)
/* try to open document again */
if (document_open(dialog->zathura, dialog->path, dialog->uri, input,
ZATHURA_PAGE_NUMBER_UNSPECIFIED) == false) {
ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL) == false) {
gdk_threads_add_idle(password_dialog, dialog);
} else {
g_free(dialog->path);

View File

@ -19,6 +19,7 @@
#include "print.h"
#include "page-widget.h"
#include "adjustment.h"
#include "database.h"
#include <math.h>
/* Helper function for highlighting the links */
@ -480,13 +481,16 @@ sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
return false;
}
/* Get file info (zoom, current page, etc.) */
zathura_fileinfo_t file_info = zathura_get_fileinfo(zathura);
/* close current document */
document_close(zathura, true);
/* reopen document */
/* reopen document with old file info */
document_open(
zathura, zathura_filemonitor_get_filepath(zathura->file_monitor.monitor),
NULL, zathura->file_monitor.password, ZATHURA_PAGE_NUMBER_UNSPECIFIED);
NULL, zathura->file_monitor.password, file_info.current_page, &file_info );
return false;
}

View File

@ -870,7 +870,7 @@ document_info_open(gpointer data)
document_info->password, document_info->synctex);
} else {
document_open(document_info->zathura, file, uri, document_info->password,
document_info->page_number);
document_info->page_number, NULL);
}
g_free(file);
g_free(uri);
@ -1015,7 +1015,7 @@ static void document_open_page_most_frequent_size(zathura_document_t* document,
bool
document_open(zathura_t* zathura, const char* path, const char* uri, const char* password,
int page_number)
int page_number, zathura_fileinfo_t* file_info_p)
{
if (zathura == NULL || zathura->plugins.manager == NULL || path == NULL) {
goto error_out;
@ -1075,8 +1075,13 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
.position_x = 0,
.position_y = 0
};
bool known_file = false;
if (zathura->database != NULL) {
if( file_info_p ) {
file_info = *file_info_p;
known_file = true;
}
else if (zathura->database != NULL) {
const uint8_t* file_hash = zathura_document_get_hash(document);
known_file = zathura_db_get_fileinfo(zathura->database, file_path, file_hash, &file_info);
}
@ -1358,7 +1363,7 @@ document_open_synctex(zathura_t* zathura, const char* path, const char* uri,
const char* password, const char* synctex)
{
bool ret = document_open(zathura, path, password, uri,
ZATHURA_PAGE_NUMBER_UNSPECIFIED);
ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL);
if (ret == false) {
return false;
}
@ -1454,11 +1459,10 @@ remove_page_from_table(GtkWidget* page, gpointer UNUSED(permanent))
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(page)), page);
}
static void
save_fileinfo_to_db(zathura_t* zathura)
zathura_fileinfo_t
zathura_get_fileinfo(zathura_t* zathura)
{
const char* path = zathura_document_get_path(zathura->document);
const uint8_t* file_hash = zathura_document_get_hash(zathura->document);
/* Caller needs to g_free(file_info.first_page_column_list) */
zathura_fileinfo_t file_info = {
.current_page = zathura_document_get_current_page_number(zathura->document),
@ -1479,6 +1483,17 @@ save_fileinfo_to_db(zathura_t* zathura)
girara_setting_get(zathura->ui.session, "page-right-to-left",
&(file_info.page_right_to_left));
return file_info;
}
static void
save_fileinfo_to_db(zathura_t* zathura)
{
const char* path = zathura_document_get_path(zathura->document);
const uint8_t* file_hash = zathura_document_get_hash(zathura->document);
zathura_fileinfo_t file_info = zathura_get_fileinfo(zathura);
/* save file info */
zathura_db_set_fileinfo(zathura->database, path, file_hash, &file_info);
/* save jumplist */

View File

@ -90,6 +90,7 @@ typedef enum {
/* forward declaration for types from database.h */
typedef struct _ZathuraDatabase zathura_database_t;
typedef struct zathura_fileinfo_s zathura_fileinfo_t;
/* forward declaration for types from content-type.h */
typedef struct zathura_content_type_context_s zathura_content_type_context_t;
@ -328,11 +329,12 @@ void zathura_update_view_ppi(zathura_t* zathura);
* @param path The path to the file
* @param password The password of the file
* @param page_number Open given page number
* @param file_info Open given page number
*
* @return If no error occurred true, otherwise false, is returned.
*/
bool document_open(zathura_t* zathura, const char* path, const char* uri, const char* password,
int page_number);
int page_number, zathura_fileinfo_t* file_info);
/**
* Opens a file
@ -373,6 +375,15 @@ void document_open_idle(zathura_t* zathura, const char* path,
*/
bool document_save(zathura_t* zathura, const char* path, bool overwrite);
/**
* Get fileinfo (zoom, current page, etc).
*
* @param zathura The zathura session
*
* @return file_info (caller needs to g_free(file_info.first_page_column_list))
*/
zathura_fileinfo_t zathura_get_fileinfo(zathura_t* zathura);
/**
* Frees the "predecessor" buffers used for smooth-reload
*