From c6403ec0977dc5e992926a9b98eaf34c24aac300 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 8 Feb 2012 21:34:53 +0100 Subject: [PATCH] wrap gtk_adjustment_set_value --- shortcuts.c | 19 +++++++++---------- utils.c | 6 ++++++ utils.h | 7 +++++++ zathura.c | 7 ++++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index b480805..1e81c2d 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -167,7 +167,6 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, girara_event_t* } else { if (t == 0) { page_set(zathura, zathura->document->number_of_pages - 1); - return true; } else { page_set(zathura, t - 1); } @@ -359,24 +358,24 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, switch(argument->n) { case FULL_UP: - new_value = (value - view_size) < 0 ? 0 : (value - view_size); + new_value = value - view_size; break; case FULL_DOWN: - new_value = (value + view_size) > max ? max : (value + view_size); + new_value = value + view_size; break; case HALF_UP: - new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2)); + new_value = value - (view_size / 2); break; case HALF_DOWN: - new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2)); + new_value = value + (view_size / 2); break; case LEFT: case UP: - new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step); + new_value = value - scroll_step; break; case RIGHT: case DOWN: - new_value = (value + scroll_step) > max ? max : (value + scroll_step); + new_value = value + scroll_step; break; case TOP: new_value = 0; @@ -388,7 +387,7 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, new_value = value; } - gtk_adjustment_set_value(adjustment, new_value); + set_adjustment(adjustment, new_value); return false; } @@ -466,8 +465,8 @@ sc_search(girara_session_t* session, girara_argument_t* argument, int x = offset.x - gtk_adjustment_get_page_size(view_hadjustment) / 2 + rectangle.x1; int y = offset.y - gtk_adjustment_get_page_size(view_vadjustment) / 2 + rectangle.y1; - gtk_adjustment_set_value(view_hadjustment, MAX(view_hadjustment->lower, MIN(view_hadjustment->upper - view_hadjustment->page_size, x))); - gtk_adjustment_set_value(view_vadjustment, MAX(view_vadjustment->lower, MIN(view_vadjustment->upper - view_vadjustment->page_size, y))); + set_adjustment(view_hadjustment, x); + set_adjustment(view_vadjustment, y); } return false; diff --git a/utils.c b/utils.c index a89d852..24066ed 100644 --- a/utils.c +++ b/utils.c @@ -226,3 +226,9 @@ recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle) return tmp; } + +void +set_adjustment(GtkAdjustment* adjustment, gdouble value) +{ + gtk_adjustment_set_value(adjustment, MAX(adjustment->lower, MIN(adjustment->upper - adjustment->page_size, value))); +} diff --git a/utils.h b/utils.h index 46d415e..796b417 100644 --- a/utils.h +++ b/utils.h @@ -82,4 +82,11 @@ void page_calculate_offset(zathura_page_t* page, page_offset_t* offset); */ zathura_rectangle_t recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle); +/** + * Set adjustment of a GtkAdjustment respecting its limits. + * @param adjust the GtkAdkustment instance + * @param value the new adjustment + */ +void set_adjustment(GtkAdjustment* adjust, gdouble value); + #endif // UTILS_H diff --git a/zathura.c b/zathura.c index 8e3a41c..f22e440 100644 --- a/zathura.c +++ b/zathura.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -576,8 +577,8 @@ page_set(zathura_t* zathura, unsigned int page_id) 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)); - gtk_adjustment_set_value(view_hadjustment, offset.x); - gtk_adjustment_set_value(view_vadjustment, offset.y); + set_adjustment(view_hadjustment, offset.x); + set_adjustment(view_vadjustment, offset.y); return true; @@ -616,7 +617,7 @@ page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row) gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, (gpointer)0); - gtk_table_resize(GTK_TABLE(zathura->ui.page_widget), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); + gtk_table_resize(GTK_TABLE(zathura->ui.page_widget), ceil(zathura->document->number_of_pages / pages_per_row), pages_per_row); for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { int x = i % pages_per_row;