Commit 6ca81e37 authored by Abdo Roig-Maranges's avatar Abdo Roig-Maranges
Browse files

use the new document functions for marks, bookmarks and initialization

We get the position data from the document object instead of the gtk
adjustment itself.
parent f94d43d2
......@@ -25,14 +25,14 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
g_return_val_if_fail(zathura && zathura->document && zathura->bookmarks.bookmarks, NULL);
g_return_val_if_fail(id, NULL);
double x = zathura_adjustment_get_ratio(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)));
double y = zathura_adjustment_get_ratio(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)));
double position_x = zathura_document_get_position_x(zathura->document);
double position_y = zathura_document_get_position_y(zathura->document);
zathura_bookmark_t* old = zathura_bookmark_get(zathura, id);
if (old != NULL) {
old->page = page;
old->x = x;
old->y = y;
old->x = position_x;
old->y = position_y;
if (zathura->database != NULL) {
const char* path = zathura_document_get_path(zathura->document);
......@@ -52,8 +52,8 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
bookmark->id = g_strdup(id);
bookmark->page = page;
bookmark->x = x;
bookmark->y = y;
bookmark->x = position_x;
bookmark->y = position_y;
girara_list_append(zathura->bookmarks.bookmarks, bookmark);
if (zathura->database != NULL) {
......
......@@ -118,16 +118,9 @@ cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list)
}
zathura_jumplist_add(zathura);
if (bookmark->x != DBL_MIN && bookmark->y != DBL_MIN) {
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
zathura_adjustment_set_value_from_ratio(hadjustment, bookmark->x);
zathura_adjustment_set_value_from_ratio(vadjustment, bookmark->y);
zathura_document_set_current_page_number(zathura->document, bookmark->page - 1);
statusbar_page_number_update(zathura);
} else {
page_set(zathura, bookmark->page - 1);
}
page_set(zathura, bookmark->page - 1);
if (bookmark->x != DBL_MIN && bookmark->y != DBL_MIN)
position_set(zathura, bookmark->x, bookmark->y);
zathura_jumplist_add(zathura);
return true;
......
......@@ -23,7 +23,8 @@ struct zathura_mark_s {
int key; /**> Marks key */
double position_x; /**> Horizontal adjustment */
double position_y; /**> Vertical adjustment */
float scale; /**> Zoom level */
unsigned int page; /**> Page number */
double scale; /**> Zoom level */
};
bool
......@@ -196,21 +197,16 @@ mark_add(zathura_t* zathura, int key)
return;
}
GtkScrolledWindow *window = GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view);
GtkAdjustment* v_adjustment = gtk_scrolled_window_get_vadjustment(window);
GtkAdjustment* h_adjustment = gtk_scrolled_window_get_hadjustment(window);
unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
double position_x = zathura_document_get_position_x(zathura->document);
double position_y = zathura_document_get_position_y(zathura->document);
if (v_adjustment == NULL || h_adjustment == NULL) {
return;
}
double position_x = gtk_adjustment_get_value(h_adjustment);
double position_y = gtk_adjustment_get_value(v_adjustment);
float scale = zathura_document_get_scale(zathura->document);
double scale = zathura_document_get_scale(zathura->document);
/* search for existing mark */
GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
if (mark->key == key) {
mark->page = page_id;
mark->position_x = position_x;
mark->position_y = position_y;
mark->scale = scale;
......@@ -222,6 +218,7 @@ mark_add(zathura_t* zathura, int key)
zathura_mark_t* mark = g_malloc0(sizeof(zathura_mark_t));
mark->key = key;
mark->page = page_id;
mark->position_x = position_x;
mark->position_y = position_y;
mark->scale = scale;
......@@ -243,11 +240,10 @@ mark_evaluate(zathura_t* zathura, int key)
render_all(zathura);
zathura_jumplist_add(zathura);
page_set(zathura, mark->page);
position_set(zathura, mark->position_x, mark->position_y);
zathura_jumplist_add(zathura);
cb_view_vadjustment_value_changed(NULL, zathura);
zathura->global.update_page_number = true;
return;
}
......
......@@ -946,12 +946,8 @@ document_close(zathura_t* zathura, bool keep_monitor)
girara_setting_get(zathura->ui.session, "first-page-column", &(file_info.first_page_column));
/* 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);
file_info.position_x = zathura_document_get_position_x(zathura->document);
file_info.position_y = zathura_document_get_position_y(zathura->document);
/* save file info */
zathura_db_set_fileinfo(zathura->database, path, &file_info);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment