Merge branch 'develop' of pwmt.org:zathura into develop

This commit is contained in:
Sebastian Ramacher 2012-04-21 02:15:53 +02:00
commit fda6420732
8 changed files with 195 additions and 102 deletions

View file

@ -116,7 +116,7 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, _("Transparency for highlighting"), NULL, NULL); girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, _("Transparency for highlighting"), NULL, NULL);
bool_value = true; bool_value = true;
girara_setting_add(gsession, "render-loading", &bool_value, BOOLEAN, false, _("Render 'Loading ...'"), NULL, NULL); girara_setting_add(gsession, "render-loading", &bool_value, BOOLEAN, false, _("Render 'Loading ...'"), NULL, NULL);
girara_setting_add(gsession, "adjust-open", "best-fit", STRING, false, _("Adjust to when opening file"), NULL, NULL); girara_setting_add(gsession, "adjust-open", "none", STRING, false, _("Adjust to when opening file"), NULL, NULL);
bool_value = false; bool_value = false;
girara_setting_add(gsession, "show-hidden", &bool_value, BOOLEAN, false, _("Show hidden files and directories"), NULL, NULL); girara_setting_add(gsession, "show-hidden", &bool_value, BOOLEAN, false, _("Show hidden files and directories"), NULL, NULL);
bool_value = true; bool_value = true;

View file

@ -20,6 +20,9 @@
#define KEY_OFFSET "offset" #define KEY_OFFSET "offset"
#define KEY_SCALE "scale" #define KEY_SCALE "scale"
#define KEY_ROTATE "rotate" #define KEY_ROTATE "rotate"
#define KEY_PAGES_PER_ROW "pages-per-row"
#define KEY_POSITION_X "position-x"
#define KEY_POSITION_Y "position-y"
#ifdef __GNU__ #ifdef __GNU__
#include <sys/file.h> #include <sys/file.h>
@ -45,9 +48,9 @@ static bool plain_remove_bookmark(zathura_database_t* db, const char* file,
static girara_list_t* plain_load_bookmarks(zathura_database_t* db, static girara_list_t* plain_load_bookmarks(zathura_database_t* db,
const char* file); const char* file);
static bool plain_set_fileinfo(zathura_database_t* db, const char* file, static bool plain_set_fileinfo(zathura_database_t* db, const char* file,
unsigned int page, unsigned int offset, double scale, unsigned int rotation); zathura_fileinfo_t* file_info);
static bool plain_get_fileinfo(zathura_database_t* db, const char* file, static bool plain_get_fileinfo(zathura_database_t* db, const char* file,
unsigned int* page, unsigned int* offset, double* scale, unsigned int* rotation); zathura_fileinfo_t* file_info);
static void plain_set_property(GObject* object, guint prop_id, static void plain_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec); const GValue* value, GParamSpec* pspec);
@ -367,24 +370,35 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
} }
static bool static bool
plain_set_fileinfo(zathura_database_t* db, const char* file, unsigned int plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
page, unsigned int offset, double scale, unsigned int rotation) file_info)
{ {
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db); zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->history == NULL) { if (priv->history == NULL || file_info == NULL || file == NULL) {
return false; return false;
} }
char* tmp = g_strdup_printf("%f", scale);
char* name = prepare_filename(file); char* name = prepare_filename(file);
g_key_file_set_integer(priv->history, name, KEY_PAGE, page); g_key_file_set_integer(priv->history, name, KEY_PAGE, file_info->current_page);
g_key_file_set_integer(priv->history, name, KEY_OFFSET, offset); g_key_file_set_integer(priv->history, name, KEY_OFFSET, file_info->page_offset);
g_key_file_set_string (priv->history, name, KEY_SCALE, tmp);
g_key_file_set_integer(priv->history, name, KEY_ROTATE, rotation); char* tmp = g_strdup_printf("%f", file_info->scale);
g_key_file_set_string (priv->history, name, KEY_SCALE, tmp);
g_free(tmp);
g_key_file_set_integer(priv->history, name, KEY_ROTATE, file_info->rotation);
g_key_file_set_integer(priv->history, name, KEY_PAGES_PER_ROW, file_info->pages_per_row);
tmp = g_strdup_printf("%f", file_info->position_x);
g_key_file_set_string(priv->history, name, KEY_POSITION_X, tmp);
g_free(tmp);
tmp = g_strdup_printf("%f", file_info->position_y);
g_key_file_set_string(priv->history, name, KEY_POSITION_Y, tmp);
g_free(tmp);
g_free(name); g_free(name);
g_free(tmp);
zathura_db_write_key_file_to_file(priv->history_path, priv->history); zathura_db_write_key_file_to_file(priv->history_path, priv->history);
@ -392,9 +406,13 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
} }
static bool static bool
plain_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
page, unsigned int* offset, double* scale, unsigned int* rotation) file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) {
return false;
}
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db); zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->history == NULL) { if (priv->history == NULL) {
return false; return false;
@ -405,13 +423,23 @@ plain_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
return false; return false;
} }
*page = g_key_file_get_integer(priv->history, name, KEY_PAGE, NULL); file_info->current_page = g_key_file_get_integer(priv->history, name, KEY_PAGE, NULL);
*offset = g_key_file_get_integer(priv->history, name, KEY_OFFSET, NULL); file_info->page_offset = g_key_file_get_integer(priv->history, name, KEY_OFFSET, NULL);
*rotation = g_key_file_get_integer(priv->history, name, KEY_ROTATE, NULL); file_info->rotation = g_key_file_get_integer(priv->history, name, KEY_ROTATE, NULL);
file_info->pages_per_row = g_key_file_get_integer(priv->history, name, KEY_PAGES_PER_ROW, NULL);
char* scale_string = g_key_file_get_string(priv->history, name, KEY_SCALE, NULL); char* scale_string = g_key_file_get_string(priv->history, name, KEY_SCALE, NULL);
*scale = strtod(scale_string, NULL); file_info->scale = strtod(scale_string, NULL);
g_free(scale_string); g_free(scale_string);
char* position_x_string = g_key_file_get_string(priv->history, name, KEY_POSITION_X, NULL);
file_info->position_x = strtod(position_x_string, NULL);
g_free(position_x_string);
char* position_y_string = g_key_file_get_string(priv->history, name, KEY_POSITION_Y, NULL);
file_info->position_y = strtod(position_y_string, NULL);
g_free(position_y_string);
g_free(name); g_free(name);
return true; return true;

View file

@ -20,9 +20,9 @@ static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file,
static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db, static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db,
const char* file); const char* file);
static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file, static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file,
unsigned int page, unsigned int offset, double scale, unsigned int rotation); zathura_fileinfo_t* file_info);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file, static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file,
unsigned int* page, unsigned int* offset, double* scale, unsigned int* rotation); zathura_fileinfo_t* file_info);
static void sqlite_set_property(GObject* object, guint prop_id, static void sqlite_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec); const GValue* value, GParamSpec* pspec);
@ -118,7 +118,11 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
"page INTEGER," "page INTEGER,"
"offset INTEGER," "offset INTEGER,"
"scale FLOAT," "scale FLOAT,"
"rotation INTEGER);"; "rotation INTEGER,"
"pages_per_row INTEGER,"
"position_x FLOAT,"
"position_y FLOAT"
");";
sqlite3* session = NULL; sqlite3* session = NULL;
if (sqlite3_open(path, &session) != SQLITE_OK) { if (sqlite3_open(path, &session) != SQLITE_OK) {
@ -272,9 +276,13 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
} }
static bool static bool
sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned int sqlite_set_fileinfo(zathura_database_t* db, const char* file,
page, unsigned int offset, double scale, unsigned int rotation) zathura_fileinfo_t* file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) {
return false;
}
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db); zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
static const char SQL_FILEINFO_SET[] = static const char SQL_FILEINFO_SET[] =
@ -285,11 +293,14 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
return false; return false;
} }
if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK || if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK ||
sqlite3_bind_int(stmt, 2, page) != SQLITE_OK || sqlite3_bind_int(stmt, 2, file_info->current_page) != SQLITE_OK ||
sqlite3_bind_int(stmt, 3, offset) != SQLITE_OK || sqlite3_bind_int(stmt, 3, file_info->page_offset) != SQLITE_OK ||
sqlite3_bind_double(stmt, 4, scale) != SQLITE_OK || sqlite3_bind_double(stmt, 4, file_info->scale) != SQLITE_OK ||
sqlite3_bind_int(stmt, 5, rotation) != SQLITE_OK) { sqlite3_bind_int(stmt, 5, file_info->rotation) != SQLITE_OK ||
sqlite3_bind_int(stmt, 6, file_info->pages_per_row) != SQLITE_OK ||
sqlite3_bind_double(stmt, 7, file_info->position_x) != SQLITE_OK ||
sqlite3_bind_double(stmt, 8, file_info->position_y) != SQLITE_OK) {
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
girara_error("Failed to bind arguments."); girara_error("Failed to bind arguments.");
return false; return false;
@ -302,9 +313,13 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
} }
static bool static bool
sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* sqlite_get_fileinfo(zathura_database_t* db, const char* file,
page, unsigned int* offset, double* scale, unsigned int* rotation) zathura_fileinfo_t* file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) {
return false;
}
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db); zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
static const char SQL_FILEINFO_GET[] = static const char SQL_FILEINFO_GET[] =
@ -312,7 +327,7 @@ sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_FILEINFO_GET); sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_FILEINFO_GET);
if (stmt == NULL) { if (stmt == NULL) {
return false; return false;
} }
if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK) { if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK) {
@ -327,10 +342,14 @@ sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
return false; return false;
} }
*page = sqlite3_column_int(stmt, 0); file_info->current_page = sqlite3_column_int(stmt, 0);
*offset = sqlite3_column_int(stmt, 1); file_info->page_offset = sqlite3_column_int(stmt, 1);
*scale = sqlite3_column_double(stmt, 2); file_info->scale = sqlite3_column_double(stmt, 2);
*rotation = sqlite3_column_int(stmt, 3); file_info->rotation = sqlite3_column_int(stmt, 3);
file_info->pages_per_row = sqlite3_column_int(stmt, 4);
file_info->position_x = sqlite3_column_double(stmt, 5);
file_info->position_y = sqlite3_column_double(stmt, 6);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return true; return true;

View file

@ -46,22 +46,19 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
} }
bool bool
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int zathura_db_set_fileinfo(zathura_database_t* db, const char* file,
page, unsigned int offset, double scale, unsigned int rotation) zathura_fileinfo_t* file_info)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL, false); g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->set_fileinfo(db, file, page, offset, return ZATHURA_DATABASE_GET_INTERFACE(db)->set_fileinfo(db, file, file_info);
scale, rotation);
} }
bool bool
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
page, unsigned int* offset, double* scale, unsigned int* rotation) zathura_fileinfo_t* file_info)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && page != NULL && g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false);
offset != NULL && scale != NULL && rotation != NULL, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->get_fileinfo(db, file, page, offset, return ZATHURA_DATABASE_GET_INTERFACE(db)->get_fileinfo(db, file, file_info);
scale, rotation);
} }

View file

@ -9,6 +9,16 @@
#include "bookmarks.h" #include "bookmarks.h"
typedef struct zathura_fileinfo_s {
unsigned int current_page;
unsigned int page_offset;
double scale;
unsigned int rotation;
unsigned int pages_per_row;
double position_x;
double position_y;
} zathura_fileinfo_t;
#define ZATHURA_TYPE_DATABASE \ #define ZATHURA_TYPE_DATABASE \
(zathura_database_get_type ()) (zathura_database_get_type ())
#define ZATHURA_DATABASE(obj) \ #define ZATHURA_DATABASE(obj) \
@ -29,13 +39,12 @@ struct _ZathuraDatabaseInterface
bool (*add_bookmark)(ZathuraDatabase* db, const char* file, zathura_bookmark_t* bookmark); bool (*add_bookmark)(ZathuraDatabase* db, const char* file, zathura_bookmark_t* bookmark);
bool (*remove_bookmark)(ZathuraDatabase* db, const char* file, const char* id); bool (*remove_bookmark)(ZathuraDatabase* db, const char* file, const char* id);
girara_list_t* (*load_bookmarks)(ZathuraDatabase* db, const char* file); girara_list_t* (*load_bookmarks)(ZathuraDatabase* db, const char* file);
bool (*set_fileinfo)(ZathuraDatabase* db, const char* file, unsigned bool (*set_fileinfo)(ZathuraDatabase* db, const char* file, zathura_fileinfo_t* file_info);
int page, unsigned int offset, double scale, unsigned int rotation);
bool (*get_fileinfo)(ZathuraDatabase* db, const char* file, unsigned bool (*get_fileinfo)(ZathuraDatabase* db, const char* file, zathura_fileinfo_t* file_info);
int* page, unsigned int* offset, double* scale, unsigned int* rotation);
}; };
GType zathura_database_get_type(void); GType zathura_database_get_type(void);
@ -84,26 +93,20 @@ girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char*
* *
* @param db The database instance * @param db The database instance
* @param file The file to which the file info belongs to. * @param file The file to which the file info belongs to.
* @param page The last page. * @param file_info The file info
* @param offset The last offset.
* @param scale The last scale.
* @param rotation The last rotation.
* @return true on success, false otherwise. * @return true on success, false otherwise.
*/ */
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file,
int page, unsigned int offset, double scale, unsigned int rotation); zathura_fileinfo_t* file_info);
/* Get file info (last site, ...) from the database. /* Get file info (last site, ...) from the database.
* *
* @param db The database instance * @param db The database instance
* @param file The file to which the file info belongs to. * @param file The file to which the file info belongs to.
* @param page The last page. * @param file_info The file info
* @param offset The last offset.
* @param scale The last scale.
* @param rotation The rotation.
* @return true on success, false otherwise. * @return true on success, false otherwise.
*/ */
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
int* page, unsigned int* offset, double* scale, unsigned int* rotation); zathura_fileinfo_t* file_info);
#endif // DATABASE_H #endif // DATABASE_H

View file

@ -114,10 +114,11 @@ zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char*
document = g_malloc0(sizeof(zathura_document_t)); document = g_malloc0(sizeof(zathura_document_t));
document->file_path = real_path; document->file_path = real_path;
document->password = password; document->password = password;
document->scale = 1.0; document->scale = 1.0;
document->plugin = plugin; document->plugin = plugin;
document->adjust_mode = ZATHURA_ADJUST_NONE;
/* open document */ /* open document */
if (plugin->functions.document_open == NULL) { if (plugin->functions.document_open == NULL) {

View file

@ -949,7 +949,8 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t*
int value = 1; int value = 1;
girara_setting_get(zathura->ui.session, "zoom-step", &value); girara_setting_get(zathura->ui.session, "zoom-step", &value);
float zoom_step = value / 100.0f; t = (t == 0) ? 1 : t;
float zoom_step = value / 100.0f * t;
float old_zoom = zathura_document_get_scale(zathura->document); float old_zoom = zathura_document_get_scale(zathura->document);
/* specify new zoom value */ /* specify new zoom value */

114
zathura.c
View file

@ -38,8 +38,21 @@ typedef struct zathura_document_info_s
const char* password; const char* password;
} zathura_document_info_t; } zathura_document_info_t;
typedef struct page_set_delayed_s
{
zathura_t* zathura;
unsigned int page;
} page_set_delayed_t;
typedef struct position_set_delayed_s
{
zathura_t* zathura;
zathura_fileinfo_t file_info;
} position_set_delayed_t;
static gboolean document_info_open(gpointer data); static gboolean document_info_open(gpointer data);
static gboolean purge_pages(gpointer data); static gboolean purge_pages(gpointer data);
static gboolean position_set_delayed(gpointer data);
/* function implementation */ /* function implementation */
zathura_t* zathura_t*
@ -462,41 +475,38 @@ document_open(zathura_t* zathura, const char* path, const char* password)
goto error_out; goto error_out;
} }
const char* file_path = zathura_document_get_path(document); const char* file_path = zathura_document_get_path(document);
unsigned int number_of_pages = zathura_document_get_number_of_pages(document); unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
unsigned int current_page_number = 0;
double scale = 1;
unsigned int page_offset = 0;
unsigned int rotate = 0;
/* read history file */ /* read history file */
zathura_db_get_fileinfo(zathura->database, file_path, &current_page_number, zathura_fileinfo_t file_info = { 0, 0, 1, 0, 1, 0, 0 };
&page_offset, &scale, &rotate); zathura_db_get_fileinfo(zathura->database, file_path, &file_info);
zathura_document_set_page_offset(document, page_offset); /* set page offset */
zathura_document_set_page_offset(document, file_info.page_offset);
/* check for valid scale value */ /* check for valid scale value */
if (scale <= FLT_EPSILON) { if (file_info.scale <= FLT_EPSILON) {
girara_warning("document info: '%s' has non positive scale", file_path); girara_warning("document info: '%s' has non positive scale", file_path);
zathura_document_set_scale(document, 1); zathura_document_set_scale(document, 1);
} else { } else {
zathura_document_set_scale(document, scale); zathura_document_set_scale(document, file_info.scale);
} }
/* check current page number */ /* check current page number */
if (current_page_number > number_of_pages) { if (file_info.current_page > number_of_pages) {
girara_warning("document info: '%s' has an invalid page number", file_path); girara_warning("document info: '%s' has an invalid page number", file_path);
zathura_document_set_current_page_number(document, 0); zathura_document_set_current_page_number(document, 0);
} else { } else {
zathura_document_set_current_page_number(document, current_page_number); zathura_document_set_current_page_number(document, file_info.current_page);
} }
/* check for valid rotation */ /* check for valid rotation */
if (rotate % 90 != 0) { if (file_info.rotation % 90 != 0) {
girara_warning("document info: '%s' has an invalid rotation", file_path); girara_warning("document info: '%s' has an invalid rotation", file_path);
zathura_document_set_rotation(document, 0); zathura_document_set_rotation(document, 0);
} else { } else {
zathura_document_set_rotation(document, rotate % 360); zathura_document_set_rotation(document, file_info.rotation % 360);
} }
/* jump to first page if setting enabled */ /* jump to first page if setting enabled */
@ -508,7 +518,7 @@ document_open(zathura_t* zathura, const char* path, const char* password)
/* apply open adjustment */ /* apply open adjustment */
char* adjust_open = "best-fit"; char* adjust_open = "best-fit";
zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_BESTFIT); zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_NONE);
if (girara_setting_get(zathura->ui.session, "adjust-open", &(adjust_open)) == true) { if (girara_setting_get(zathura->ui.session, "adjust-open", &(adjust_open)) == true) {
if (g_strcmp0(adjust_open, "best-fit") == 0) { if (g_strcmp0(adjust_open, "best-fit") == 0) {
zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_BESTFIT); zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_BESTFIT);
@ -590,7 +600,11 @@ document_open(zathura_t* zathura, const char* path, const char* password)
/* view mode */ /* view mode */
int pages_per_row = 1; int pages_per_row = 1;
girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row); if (file_info.pages_per_row > 0) {
pages_per_row = file_info.pages_per_row;
} else {
girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row);
}
page_widget_set_mode(zathura, pages_per_row); page_widget_set_mode(zathura, pages_per_row);
girara_set_view(zathura->ui.session, zathura->ui.page_widget_alignment); girara_set_view(zathura->ui.session, zathura->ui.page_widget_alignment);
@ -609,9 +623,6 @@ document_open(zathura_t* zathura, const char* path, const char* password)
/* bookmarks */ /* bookmarks */
zathura_bookmarks_load(zathura, file_path); zathura_bookmarks_load(zathura, file_path);
page_set_delayed(zathura, zathura_document_get_current_page_number(document));
cb_view_vadjustment_value_changed(NULL, zathura);
/* update title */ /* update title */
girara_set_window_title(zathura->ui.session, file_path); girara_set_window_title(zathura->ui.session, file_path);
@ -621,6 +632,18 @@ document_open(zathura_t* zathura, const char* path, const char* password)
girara_argument_t argument = { zathura_document_get_adjust_mode(document), NULL }; girara_argument_t argument = { zathura_document_get_adjust_mode(document), NULL };
sc_adjust_window(zathura->ui.session, &argument, NULL, 0); sc_adjust_window(zathura->ui.session, &argument, NULL, 0);
/* set position */
if (file_info.position_x != 0 || file_info.position_y != 0) {
position_set_delayed_t* p = g_malloc0(sizeof(position_set_delayed_t));
p->zathura = zathura;
p->file_info = file_info;
gdk_threads_add_idle(position_set_delayed, p);
} else {
page_set_delayed(zathura, zathura_document_get_current_page_number(document));
cb_view_vadjustment_value_changed(NULL, zathura);
}
return true; return true;
error_free: error_free:
@ -698,22 +721,34 @@ document_close(zathura_t* zathura, bool keep_monitor)
} }
} }
const char* path = zathura_document_get_path(zathura->document); /* store file information */
unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document); const char* path = zathura_document_get_path(zathura->document);
unsigned int page_offset = zathura_document_get_page_offset(zathura->document);
double scale = zathura_document_get_scale(zathura->document);
unsigned int rotation = zathura_document_get_rotation(zathura->document);
/* store last seen page */ zathura_fileinfo_t file_info = { 0 };
zathura_db_set_fileinfo(zathura->database, path, current_page_number, file_info.current_page = zathura_document_get_current_page_number(zathura->document);
page_offset, scale, rotation); file_info.page_offset = zathura_document_get_page_offset(zathura->document);
file_info.scale = zathura_document_get_scale(zathura->document);
file_info.rotation = zathura_document_get_rotation(zathura->document);
girara_setting_get(zathura->ui.session, "pages-per-row", &(file_info.pages_per_row));
/* get position */
GtkScrolledWindow *window = GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view);
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(window);
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(window);
file_info.position_x = gtk_adjustment_get_value(hadjustment);
file_info.position_y = gtk_adjustment_get_value(vadjustment);
/* save file info */
zathura_db_set_fileinfo(zathura->database, path, &file_info);
/* release render thread */ /* release render thread */
render_free(zathura->sync.render_thread); render_free(zathura->sync.render_thread);
zathura->sync.render_thread = NULL; zathura->sync.render_thread = NULL;
/* remove widgets */ /* remove widgets */
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, (gpointer)1); gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, (gpointer) 1);
free(zathura->pages); free(zathura->pages);
zathura->pages = NULL; zathura->pages = NULL;
@ -741,12 +776,6 @@ document_close(zathura_t* zathura, bool keep_monitor)
return true; return true;
} }
typedef struct page_set_delayed_s
{
zathura_t* zathura;
unsigned int page;
} page_set_delayed_t;
static gboolean static gboolean
page_set_delayed_impl(gpointer data) page_set_delayed_impl(gpointer data)
{ {
@ -876,3 +905,18 @@ gboolean purge_pages(gpointer data)
} }
return TRUE; return TRUE;
} }
static gboolean
position_set_delayed(gpointer data)
{
position_set_delayed_t* p = (position_set_delayed_t*) data;
GtkScrolledWindow *window = GTK_SCROLLED_WINDOW(p->zathura->ui.session->gtk.view);
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(window);
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(window);
gtk_adjustment_set_value(hadjustment, p->file_info.position_x);
gtk_adjustment_set_value(vadjustment, p->file_info.position_y);
return FALSE;
}