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

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) ...@@ -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(zathura && zathura->document && zathura->bookmarks.bookmarks, NULL);
g_return_val_if_fail(id, 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 position_x = zathura_document_get_position_x(zathura->document);
double y = zathura_adjustment_get_ratio(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view))); double position_y = zathura_document_get_position_y(zathura->document);
zathura_bookmark_t* old = zathura_bookmark_get(zathura, id); zathura_bookmark_t* old = zathura_bookmark_get(zathura, id);
if (old != NULL) { if (old != NULL) {
old->page = page; old->page = page;
old->x = x; old->x = position_x;
old->y = y; old->y = position_y;
if (zathura->database != NULL) { if (zathura->database != NULL) {
const char* path = zathura_document_get_path(zathura->document); 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) ...@@ -52,8 +52,8 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
bookmark->id = g_strdup(id); bookmark->id = g_strdup(id);
bookmark->page = page; bookmark->page = page;
bookmark->x = x; bookmark->x = position_x;
bookmark->y = y; bookmark->y = position_y;
girara_list_append(zathura->bookmarks.bookmarks, bookmark); girara_list_append(zathura->bookmarks.bookmarks, bookmark);
if (zathura->database != NULL) { if (zathura->database != NULL) {
......
...@@ -118,16 +118,9 @@ cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list) ...@@ -118,16 +118,9 @@ cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list)
} }
zathura_jumplist_add(zathura); zathura_jumplist_add(zathura);
if (bookmark->x != DBL_MIN && bookmark->y != DBL_MIN) { page_set(zathura, bookmark->page - 1);
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); if (bookmark->x != DBL_MIN && bookmark->y != DBL_MIN)
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); position_set(zathura, bookmark->x, bookmark->y);
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);
}
zathura_jumplist_add(zathura); zathura_jumplist_add(zathura);
return true; return true;
......
...@@ -23,7 +23,8 @@ struct zathura_mark_s { ...@@ -23,7 +23,8 @@ struct zathura_mark_s {
int key; /**> Marks key */ int key; /**> Marks key */
double position_x; /**> Horizontal adjustment */ double position_x; /**> Horizontal adjustment */
double position_y; /**> Vertical adjustment */ double position_y; /**> Vertical adjustment */
float scale; /**> Zoom level */ unsigned int page; /**> Page number */
double scale; /**> Zoom level */
}; };
bool bool
...@@ -196,21 +197,16 @@ mark_add(zathura_t* zathura, int key) ...@@ -196,21 +197,16 @@ mark_add(zathura_t* zathura, int key)
return; return;
} }
GtkScrolledWindow *window = GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view); unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
GtkAdjustment* v_adjustment = gtk_scrolled_window_get_vadjustment(window); double position_x = zathura_document_get_position_x(zathura->document);
GtkAdjustment* h_adjustment = gtk_scrolled_window_get_hadjustment(window); double position_y = zathura_document_get_position_y(zathura->document);
if (v_adjustment == NULL || h_adjustment == NULL) { double scale = zathura_document_get_scale(zathura->document);
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);
/* search for existing mark */ /* search for existing mark */
GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark) GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
if (mark->key == key) { if (mark->key == key) {
mark->page = page_id;
mark->position_x = position_x; mark->position_x = position_x;
mark->position_y = position_y; mark->position_y = position_y;
mark->scale = scale; mark->scale = scale;
...@@ -222,6 +218,7 @@ mark_add(zathura_t* zathura, int key) ...@@ -222,6 +218,7 @@ mark_add(zathura_t* zathura, int key)
zathura_mark_t* mark = g_malloc0(sizeof(zathura_mark_t)); zathura_mark_t* mark = g_malloc0(sizeof(zathura_mark_t));
mark->key = key; mark->key = key;
mark->page = page_id;
mark->position_x = position_x; mark->position_x = position_x;
mark->position_y = position_y; mark->position_y = position_y;
mark->scale = scale; mark->scale = scale;
...@@ -243,11 +240,10 @@ mark_evaluate(zathura_t* zathura, int key) ...@@ -243,11 +240,10 @@ mark_evaluate(zathura_t* zathura, int key)
render_all(zathura); render_all(zathura);
zathura_jumplist_add(zathura); zathura_jumplist_add(zathura);
page_set(zathura, mark->page);
position_set(zathura, mark->position_x, mark->position_y); position_set(zathura, mark->position_x, mark->position_y);
zathura_jumplist_add(zathura); zathura_jumplist_add(zathura);
cb_view_vadjustment_value_changed(NULL, zathura);
zathura->global.update_page_number = true; zathura->global.update_page_number = true;
return; return;
} }
......
...@@ -946,12 +946,8 @@ document_close(zathura_t* zathura, bool keep_monitor) ...@@ -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)); girara_setting_get(zathura->ui.session, "first-page-column", &(file_info.first_page_column));
/* get position */ /* get position */
GtkScrolledWindow *window = GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view); file_info.position_x = zathura_document_get_position_x(zathura->document);
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(window); file_info.position_y = zathura_document_get_position_y(zathura->document);
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 */ /* save file info */
zathura_db_set_fileinfo(zathura->database, path, &file_info); zathura_db_set_fileinfo(zathura->database, path, &file_info);
......
Markdown is supported
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