Commit e1a57e34 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Imported Upstream version 0.2.5

parent ed946ca2
...@@ -42,11 +42,15 @@ DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) ...@@ -42,11 +42,15 @@ DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
all: options ${PROJECT} po build-manpages all: options ${PROJECT} po build-manpages
girara-version-check: # pkg-config based version checks
ifneq ($(GIRARA_VERSION_CHECK), 0) .version-checks/%:
$(error "The minimum required version of girara is ${GIRARA_MIN_VERSION}") $(QUIET)test $($(*)_VERSION_CHECK) -eq 0 || \
endif pkg-config --atleast-version $($(*)_MIN_VERSION) $($(*)_PKG_CONFIG_NAME) || ( \
$(QUIET)touch girara-version-check echo "The minium required version of $(*) is $($(*)_MIN_VERSION)" && \
false \
)
@mkdir -p .version-checks
$(QUIET)touch $@
options: options:
@echo ${PROJECT} build options: @echo ${PROJECT} build options:
...@@ -56,11 +60,11 @@ options: ...@@ -56,11 +60,11 @@ options:
@echo "CC = ${CC}" @echo "CC = ${CC}"
version.h: version.h.in config.mk version.h: version.h.in config.mk
$(QUIET)sed 's/ZVMAJOR/${ZATHURA_VERSION_MAJOR}/' < version.h.in | \ $(QUIET)sed -e 's/ZVMAJOR/${ZATHURA_VERSION_MAJOR}/' \
sed 's/ZVMINOR/${ZATHURA_VERSION_MINOR}/' | \ -e 's/ZVMINOR/${ZATHURA_VERSION_MINOR}/' \
sed 's/ZVREV/${ZATHURA_VERSION_REV}/' | \ -e 's/ZVREV/${ZATHURA_VERSION_REV}/' \
sed 's/ZVAPI/${ZATHURA_API_VERSION}/' | \ -e 's/ZVAPI/${ZATHURA_API_VERSION}/' \
sed 's/ZVABI/${ZATHURA_ABI_VERSION}/' > version.h -e 's/ZVABI/${ZATHURA_ABI_VERSION}/' version.h.in > version.h
%.o: %.c %.o: %.c
$(ECHO) CC $< $(ECHO) CC $<
...@@ -72,8 +76,8 @@ version.h: version.h.in config.mk ...@@ -72,8 +76,8 @@ version.h: version.h.in config.mk
@mkdir -p .depend @mkdir -p .depend
$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep $(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
${OBJECTS}: config.mk version.h girara-version-check ${OBJECTS} ${DOBJECTS}: config.mk version.h \
${DOBJECTS}: config.mk version.h girara-version-check .version-checks/GIRARA .version-checks/GLIB .version-checks/GTK
${PROJECT}: ${OBJECTS} ${PROJECT}: ${OBJECTS}
$(ECHO) CC -o $@ $(ECHO) CC -o $@
...@@ -83,7 +87,7 @@ clean: ...@@ -83,7 +87,7 @@ clean:
$(QUIET)rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ $(QUIET)rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
${DOBJECTS} ${PROJECT}-debug .depend ${PROJECT}.pc doc version.h \ ${DOBJECTS} ${PROJECT}-debug .depend ${PROJECT}.pc doc version.h \
*gcda *gcno $(PROJECT).info gcov *.tmp \ *gcda *gcno $(PROJECT).info gcov *.tmp \
girara-version-check .version-checks
ifneq "$(wildcard ${RSTTOMAN})" "" ifneq "$(wildcard ${RSTTOMAN})" ""
$(QUIET)rm -f zathura.1 zathurarc.5 $(QUIET)rm -f zathura.1 zathurarc.5
endif endif
......
...@@ -5,7 +5,8 @@ girara user interface library and several document libraries. ...@@ -5,7 +5,8 @@ girara user interface library and several document libraries.
Requirements Requirements
------------ ------------
gtk2 (>= 2.28) gtk2 (>= 2.18) or gtk3
glib (>= 2.28)
girara girara
sqlite3 (optional, >= 3.5.9) sqlite3 (optional, >= 3.5.9)
check (for tests) check (for tests)
...@@ -36,8 +37,13 @@ To build and install zathura: ...@@ -36,8 +37,13 @@ To build and install zathura:
make install make install
Uninstall: Uninstall
---------- ---------
To delete zathura from your system, just type: To delete zathura from your system, just type:
make uninstall make uninstall
Bugs
----
Please report bugs at http://bugs.pwmt.org or contact us on our mailing list at
zathura@lists.pwmt.org.
...@@ -2,6 +2,142 @@ ...@@ -2,6 +2,142 @@
#include "adjustment.h" #include "adjustment.h"
#include "utils.h" #include "utils.h"
#include <math.h>
double
page_calc_height_width(zathura_document_t* document, double height, double width,
unsigned int* page_height, unsigned int* page_width, bool rotate)
{
g_return_val_if_fail(document != NULL && page_height != NULL && page_width != NULL, 0.0);
double scale = zathura_document_get_scale(document);
if (rotate && zathura_document_get_rotation(document) % 180) {
*page_width = round(height * scale);
*page_height = round(width * scale);
scale = MAX(*page_width / height, *page_height / width);
} else {
*page_width = round(width * scale);
*page_height = round(height * scale);
scale = MAX(*page_width / width, *page_height / height);
}
return scale;
}
void
page_calc_position(zathura_document_t* document, double x, double y,
double *xn, double *yn) {
g_return_if_fail(document != NULL && xn != NULL && yn != NULL);
unsigned int rot = zathura_document_get_rotation(document);
if (rot == 90) {
*xn = 1 - y;
*yn = x;
}else if (rot == 180) {
*xn = 1 - x;
*yn = 1 - y;
} else if (rot == 270) {
*xn = y;
*yn = 1 - x;
} else {
*xn = x;
*yn = y;
}
}
unsigned int
position_to_page_number(zathura_document_t* document,
double pos_x, double pos_y){
g_return_val_if_fail(document != NULL, 0);
unsigned int doc_width, doc_height;
zathura_document_get_document_size(document, &doc_height, &doc_width);
unsigned int cell_width, cell_height;
zathura_document_get_cell_size(document, &cell_height, &cell_width);
unsigned int c0 = zathura_document_get_first_page_column(document);
unsigned int npag = zathura_document_get_number_of_pages(document);
unsigned int ncol = zathura_document_get_pages_per_row(document);
unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
unsigned int pad = zathura_document_get_page_padding(document);
unsigned int col = floor(pos_x * (double)doc_width / (double)(cell_width + pad));
unsigned int row = floor(pos_y * (double)doc_height / (double)(cell_height + pad));
return ncol * (row % nrow) + (col % ncol) - (c0 - 1);
}
void
page_number_to_position(zathura_document_t* document, unsigned int page_number,
double xalign, double yalign, double *pos_x, double *pos_y) {
g_return_if_fail(document != NULL);
unsigned int c0 = zathura_document_get_first_page_column(document);
unsigned int npag = zathura_document_get_number_of_pages(document);
unsigned int ncol = zathura_document_get_pages_per_row(document);
unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
/* row and column for page_number indexed from 0 */
unsigned int row = (page_number + c0 - 1) / ncol;
unsigned int col = (page_number + c0 - 1) % ncol;
/* sizes of page cell, viewport and document */
unsigned int cell_height = 0, cell_width = 0;
zathura_document_get_cell_size(document, &cell_height, &cell_width);
unsigned int view_height = 0, view_width = 0;
zathura_document_get_viewport_size(document, &view_height, &view_width);
unsigned int doc_height = 0, doc_width = 0;
zathura_document_get_document_size(document, &doc_height, &doc_width);
/* compute the shift to align to the viewport. If the page fits to viewport, just center it. */
double shift_x = 0.5, shift_y = 0.5;
if (cell_width > view_width) {
shift_x = 0.5 + (xalign - 0.5) * ((double)cell_width - (double)view_width) / (double)cell_width;
}
if (cell_height > view_height) {
shift_y = 0.5 + (yalign - 0.5) * ((double)cell_height - (double)view_height) / (double)cell_height;
}
/* compute the position */
*pos_x = ((double)col + shift_x) / (double)ncol;
*pos_y = ((double)row + shift_y) / (double)nrow;
}
bool
page_is_visible(zathura_document_t *document, unsigned int page_number) {
g_return_val_if_fail(document != NULL, false);
/* position at the center of the viewport */
double pos_x = zathura_document_get_position_x(document);
double pos_y = zathura_document_get_position_y(document);
/* get the center of page page_number */
double page_x, page_y;
page_number_to_position(document, page_number, 0.5, 0.5, &page_x, &page_y);
unsigned int cell_width, cell_height;
zathura_document_get_cell_size(document, &cell_height, &cell_width);
unsigned int doc_width, doc_height;
zathura_document_get_document_size(document, &doc_height, &doc_width);
unsigned int view_width, view_height;
zathura_document_get_viewport_size(document, &view_height, &view_width);
return ( fabs(pos_x - page_x) < 0.5 * (double)(view_width + cell_width) / (double)doc_width &&
fabs(pos_y - page_y) < 0.5 * (double)(view_height + cell_height) / (double)doc_height);
}
GtkAdjustment* GtkAdjustment*
zathura_adjustment_clone(GtkAdjustment* adjustment) zathura_adjustment_clone(GtkAdjustment* adjustment)
......
...@@ -4,8 +4,73 @@ ...@@ -4,8 +4,73 @@
#define ZATHURA_ADJUSTMENT_H #define ZATHURA_ADJUSTMENT_H
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <stdbool.h>
#include "document.h"
/* Clone a GtkAdjustment /**
* Calculate the page size according to the corrent scaling and rotation if
* desired.
*
* @param document the document
* @param height width the original height and width
* @return page_height page_width the scaled and rotated height and width
* @param rotate honor page's rotation
* @return real scale after rounding
*/
double page_calc_height_width(zathura_document_t* document, double height, double width,
unsigned int* page_height, unsigned int* page_width, bool rotate);
/**
* Calculate a page relative position after a rotation. The positions x y are
* relative to a page, i.e. 0=top of page, 1=bottom of page. They are NOT
* relative to the entire document.
*
* @param document the document
* @param x y the x y coordinates on the unrotated page
* @param xn yn the x y coordinates after rotation
*/
void page_calc_position(zathura_document_t* document, double x, double y,
double *xn, double *yn);
/**
* Converts a relative position within the document to a page number.
*
* @param document The document
* @param pos_x pos_y the position relative to the document
* @return page sitting in that position
*/
unsigned int position_to_page_number(zathura_document_t* document,
double pos_x, double pos_y);
/**
* Converts a page number to a position in units relative to the document
*
* We can specify where to aliwn the viewport and the page. For instance, xalign
* = 0 means align them on the left margin, xalign = 0.5 means centered, and
* xalign = 1.0 align them on the right margin.
*
* The return value is the position in in units relative to the document (0=top
* 1=bottom) of the point thet will lie at the center of the viewport.
*
* @param document The document
* @param page_number the given page number
* @param xalign yalign where to align the viewport and the page
* @return pos_x pos_y position that will lie at the center of the viewport.
*/
void page_number_to_position(zathura_document_t* document, unsigned int page_number,
double xalign, double yalign, double *pos_x, double *pos_y);
/**
* Checks whether a given page falls within the viewport
*
* @param document The document
* @param page_number the page number
* @return true if the page intersects the viewport
*/
bool page_is_visible(zathura_document_t *document, unsigned int page_number);
/**
* Clone a GtkAdjustment
* *
* Creates a new adjustment with the same value, lower and upper bounds, step * Creates a new adjustment with the same value, lower and upper bounds, step
* and page increments and page_size as the original adjustment. * and page increments and page_size as the original adjustment.
......
...@@ -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) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <string.h> #include <string.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <math.h>
#include "callbacks.h" #include "callbacks.h"
#include "links.h" #include "links.h"
...@@ -48,119 +49,95 @@ cb_buffer_changed(girara_session_t* session) ...@@ -48,119 +49,95 @@ cb_buffer_changed(girara_session_t* session)
} }
} }
void static void
cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpointer data) update_visible_pages(zathura_t* zathura) {
{ const unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL || zathura->ui.page_widget == NULL) {
return;
}
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
/* current adjustment values */
GdkRectangle view_rect = {
.x = 0,
.y = 0,
.width = gtk_adjustment_get_page_size(view_hadjustment),
.height = gtk_adjustment_get_page_size(view_vadjustment)
};
int page_padding = 1;
girara_setting_get(zathura->ui.session, "page-padding", &page_padding);
GdkRectangle center = {
.x = (view_rect.width + 1) / 2,
.y = (view_rect.height + 1) / 2,
.width = (2 * page_padding) + 1,
.height = (2 * page_padding) + 1
};
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
double scale = zathura_document_get_scale(zathura->document);
bool updated = false;
/* find page that fits */
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) { for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id); zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
GdkRectangle page_rect = {
.width = zathura_page_get_width(page) * scale,
.height = zathura_page_get_height(page) * scale
};
GtkWidget* page_widget = zathura_page_get_widget(zathura, page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
gtk_widget_translate_coordinates(page_widget, ZathuraPage* zathura_page_widget = ZATHURA_PAGE(page_widget);
zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y);
if (gdk_rectangle_intersect(&view_rect, &page_rect, NULL) == TRUE) { if (page_is_visible(zathura->document, page_id) == true) {
/* make page visible */
if (zathura_page_get_visibility(page) == false) { if (zathura_page_get_visibility(page) == false) {
zathura_page_set_visibility(page, true); zathura_page_set_visibility(page, true);
zathura_page_widget_update_view_time(ZATHURA_PAGE(page_widget)); zathura_page_widget_update_view_time(zathura_page_widget);
zathura_page_cache_add(zathura, zathura_page_get_index(page)); zathura_renderer_page_cache_add(zathura->sync.render_thread, zathura_page_get_index(page));
}
if (zathura->global.update_page_number == true && updated == false
&& gdk_rectangle_intersect(&center, &page_rect, NULL) == TRUE) {
zathura_document_set_current_page_number(zathura->document, page_id);
updated = true;
} }
} else { } else {
zathura_page_set_visibility(page, false); /* make page invisible */
/* if the page is not visible and not cached, but still has a surface, we if (zathura_page_get_visibility(page) == true) {
* need to get rid of the surface */ zathura_page_set_visibility(page, false);
if (zathura_page_widget_have_surface(ZATHURA_PAGE(page_widget)) == true && /* If a page becomes invisible, abort the render request. */
zathura_page_cache_is_cached(zathura, zathura_page_get_index(page)) == false) { zathura_page_widget_abort_render_request(zathura_page_widget);
zathura_page_widget_update_surface(ZATHURA_PAGE(page_widget), NULL);
} }
/* reset current search result */
girara_list_t* results = NULL; girara_list_t* results = NULL;
g_object_get(page_widget, "search-results", &results, NULL); g_object_get(page_widget, "search-results", &results, NULL);
if (results != NULL) { if (results != NULL) {
g_object_set(page_widget, "search-current", 0, NULL); g_object_set(page_widget, "search-current", 0, NULL);
} }
} }
} }
}
void
cb_view_hadjustment_value_changed(GtkAdjustment* adjustment, gpointer data)
{
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL) {
return;
}
/* Do nothing in index mode */
if (girara_mode_get(zathura->ui.session) == zathura->modes.index) {
return;
}
update_visible_pages(zathura);
double position_x = zathura_adjustment_get_ratio(adjustment);
double position_y = zathura_document_get_position_y(zathura->document);
unsigned int page_id = position_to_page_number(zathura->document, position_x, position_y);
zathura_document_set_position_x(zathura->document, position_x);
zathura_document_set_position_y(zathura->document, position_y);
zathura_document_set_current_page_number(zathura->document, page_id);
statusbar_page_number_update(zathura); statusbar_page_number_update(zathura);
} }
void void
cb_view_hadjustment_changed(GtkAdjustment* adjustment, gpointer data) cb_view_vadjustment_value_changed(GtkAdjustment* adjustment, gpointer data)
{ {
zathura_t* zathura = data; zathura_t* zathura = data;
g_return_if_fail(zathura != NULL); if (zathura == NULL || zathura->document == NULL) {
return;
}
zathura_adjust_mode_t adjust_mode = /* Do nothing in index mode */
zathura_document_get_adjust_mode(zathura->document); if (girara_mode_get(zathura->ui.session) == zathura->modes.index) {
return;
}
gdouble lower, upper, page_size, value, ratio; update_visible_pages(zathura);
bool zoom_center = false;
switch (adjust_mode) {
center:
case ZATHURA_ADJUST_BESTFIT:
case ZATHURA_ADJUST_WIDTH:
lower = gtk_adjustment_get_lower(adjustment);
upper = gtk_adjustment_get_upper(adjustment);
page_size = gtk_adjustment_get_page_size(adjustment);
value = ((upper - lower) - page_size) / 2.0;
zathura_adjustment_set_value(adjustment, value);
break;
default:
girara_setting_get(zathura->ui.session, "zoom-center", &zoom_center);
if (zoom_center) {
goto center;
}
ratio = zathura_adjustment_get_ratio(zathura->ui.hadjustment); double position_x = zathura_document_get_position_x(zathura->document);
zathura_adjustment_set_value_from_ratio(adjustment, ratio); double position_y = zathura_adjustment_get_ratio(adjustment);
break; unsigned int page_id = position_to_page_number(zathura->document, position_x, position_y);
}
zathura_document_set_position_x(zathura->document, position_x);
zathura_document_set_position_y(zathura->document, position_y);
zathura_document_set_current_page_number(zathura->document, page_id);
statusbar_page_number_update(zathura);
} }
void void
cb_view_vadjustment_changed(GtkAdjustment* adjustment, gpointer data) cb_view_hadjustment_changed(GtkAdjustment* adjustment, gpointer data)
{ {
zathura_t* zathura = data; zathura_t* zathura = data;
g_return_if_fail(zathura != NULL); g_return_if_fail(zathura != NULL);
...@@ -168,93 +145,99 @@ cb_view_vadjustment_changed(GtkAdjustment* adjustment, gpointer data) ...@@ -168,93 +145,99 @@ cb_view_vadjustment_changed(GtkAdjustment* adjustment, gpointer data)
zathura_adjust_mode_t adjust_mode = zathura_adjust_mode_t adjust_mode =
zathura_document_get_adjust_mode(zathura->document); zathura_document_get_adjust_mode(zathura->document);
/* Do nothing in index mode */
if (girara_mode_get(zathura->ui.session) == zathura->modes.index) {
return;
}
/* Don't scroll we're focusing the inputbar. */ /* Don't scroll we're focusing the inputbar. */
if (adjust_mode == ZATHURA_ADJUST_INPUTBAR) { if (adjust_mode == ZATHURA_ADJUST_INPUTBAR) {
return; return;
} }
double ratio = zathura_adjustment_get_ratio(zathura->ui.vadjustment); /* save the viewport size */
unsigned int view_width = (unsigned int)floor(gtk_adjustment_get_page_size(adjustment));
zathura_document_set_viewport_width(zathura->document, view_width);
/* reset the adjustment, in case bounds have changed */
double ratio = zathura_document_get_position_x(zathura->document);
zathura_adjustment_set_value_from_ratio(adjustment, ratio); zathura_adjustment_set_value_from_ratio(adjustment, ratio);
} }
void void
cb_adjustment_track_value(GtkAdjustment* adjustment, gpointer data) cb_view_vadjustment_changed(GtkAdjustment* adjustment, gpointer data)
{ {
GtkAdjustment* tracker = data; zathura_t* zathura = data;
g_return_if_fail(zathura != NULL);
zathura_adjust_mode_t adjust_mode =
zathura_document_get_adjust_mode(zathura->document);
gdouble lower = gtk_adjustment_get_lower(adjustment); /* Do nothing in index mode */
gdouble upper = gtk_adjustment_get_upper(adjustment); if (girara_mode_get(zathura->ui.session) == zathura->modes.index) {
if (lower != gtk_adjustment_get_lower(tracker) ||
upper != gtk_adjustment_get_upper(tracker)) {
return; return;
} }
gdouble value = gtk_adjustment_get_value(adjustment); /* Don't scroll we're focusing the inputbar. */
gtk_adjustment_set_value(tracker, value); if (adjust_mode == ZATHURA_ADJUST_INPUTBAR) {
} return;
}
void /* save the viewport size */
cb_adjustment_track_bounds(GtkAdjustment* adjustment, gpointer data) unsigned int view_height = (unsigned int)floor(gtk_adjustment_get_page_size(adjustment));
{ zathura_document_set_viewport_height(zathura->document, view_height);
GtkAdjustment* tracker = data;
gdouble value = gtk_adjustment_get_value(adjustment); /* reset the adjustment, in case bounds have changed */
gdouble lower = gtk_adjustment_get_lower(adjustment); double ratio = zathura_document_get_position_y(zathura->document);
gdouble upper = gtk_adjustment_get_upper(adjustment); zathura_adjustment_set_value_from_ratio(adjustment, ratio);
gdouble page_size = gtk_adjustment_get_page_size(adjustment);
gtk_adjustment_set_value(tracker, value);
gtk_adjustment_set_lower(tracker, lower);
gtk_adjustment_set_upper(tracker, upper);
gtk_adjustment_set_page_size(tracker, page_size);
} }
void void
cb_pages_per_row_value_changed(girara_session_t* session, const char* UNUSED(name), girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) cb_refresh_view(GtkWidget* GIRARA_UNUSED(view), gpointer data)
{ {
g_return_if_fail(value != NULL); zathura_t* zathura = data;
g_return_if_fail(session != NULL); if (zathura == NULL || zathura->document == NULL) {
g_return_if_fail(session->global.data != NULL); return;
zathura_t* zathura = session->global.data; }
int pages_per_row = *(int*) value;
if (pages_per_row < 1) { unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
pages_per_row = 1; zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL) {
return;
} }
unsigned int first_page_column = 1; GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
girara_setting_get(session, "first-page-column", &first_page_column); GtkAdjustment* hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
page_widget_set_mode(zathura, pages_per_row, first_page_column); double position_x = zathura_document_get_position_x(zathura->document);
double position_y = zathura_document_get_position_y(zathura->document);
if (zathura->document != NULL) { zathura_adjustment_set_value_from_ratio(vadj, position_y);
unsigned int current_page = zathura_document_get_current_page_number(zathura->document); zathura_adjustment_set_value_from_ratio(hadj, position_x);
page_set_delayed(zathura, current_page);
} statusbar_page_number_update(zathura);
} }
void void
cb_first_page_column_value_changed(girara_session_t* session, const char* UNUSED(name), girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) cb_page_layout_value_changed(girara_session_t* session, const char* UNUSED(name),