diff --git a/callbacks.c b/callbacks.c index 2c6323a..c01221e 100644 --- a/callbacks.c +++ b/callbacks.c @@ -223,7 +223,11 @@ cb_pages_per_row_value_changed(girara_session_t* session, const char* UNUSED(nam unsigned int first_page_column = 1; girara_setting_get(session, "first-page-column", &first_page_column); - page_widget_set_mode(zathura, pages_per_row, first_page_column); + unsigned int page_padding = 1; + girara_setting_get(session, "page-padding", &page_padding); + + page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column); + zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column); if (zathura->document != NULL) { unsigned int current_page = zathura_document_get_current_page_number(zathura->document); @@ -248,7 +252,11 @@ cb_first_page_column_value_changed(girara_session_t* session, const char* UNUSED unsigned int pages_per_row = 1; girara_setting_get(session, "pages-per-row", &pages_per_row); - page_widget_set_mode(zathura, pages_per_row, first_page_column); + unsigned int page_padding = 1; + girara_setting_get(session, "page-padding", &page_padding); + + page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column); + zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column); if (zathura->document != NULL) { unsigned int current_page = zathura_document_get_current_page_number(zathura->document); diff --git a/zathura.c b/zathura.c index 56cbe02..39b88c1 100644 --- a/zathura.c +++ b/zathura.c @@ -225,18 +225,6 @@ zathura_init(zathura_t* zathura) /* signals */ g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), zathura); - /* set page padding */ - int page_padding = 1; - girara_setting_get(zathura->ui.session, "page-padding", &page_padding); - -#if (GTK_MAJOR_VERSION == 3) - gtk_grid_set_row_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); - gtk_grid_set_column_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); -#else - gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_widget), page_padding); - gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_widget), page_padding); -#endif - /* database */ char* database = NULL; girara_setting_get(zathura->ui.session, "database", &database); @@ -759,8 +747,12 @@ document_open(zathura_t* zathura, const char* path, const char* password, } /* view mode */ - int pages_per_row = 1; - int first_page_column = 1; + unsigned int pages_per_row = 1; + unsigned int first_page_column = 1; + unsigned int page_padding = 1; + + girara_setting_get(zathura->ui.session, "page-padding", &page_padding); + if (file_info.pages_per_row > 0) { pages_per_row = file_info.pages_per_row; } else { @@ -775,7 +767,9 @@ document_open(zathura_t* zathura, const char* path, const char* password, girara_setting_set(zathura->ui.session, "pages-per-row", &pages_per_row); girara_setting_set(zathura->ui.session, "first-page-column", &first_page_column); - page_widget_set_mode(zathura, pages_per_row, first_page_column); + + page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column); + zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column); girara_set_view(zathura->ui.session, zathura->ui.page_widget_alignment); @@ -1092,7 +1086,8 @@ statusbar_page_number_update(zathura_t* zathura) } void -page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row, unsigned int first_page_column) +page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, + unsigned int pages_per_row, unsigned int first_page_column) { /* show at least one page */ if (pages_per_row == 0) { @@ -1103,7 +1098,6 @@ page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row, unsigned in if (first_page_column < 1) { first_page_column = 1; } - if (first_page_column > pages_per_row) { first_page_column = ((first_page_column - 1) % pages_per_row) + 1; } @@ -1115,9 +1109,18 @@ page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row, unsigned in gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, (gpointer)0); unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); + #if (GTK_MAJOR_VERSION == 3) + gtk_grid_set_row_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); + gtk_grid_set_column_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); + #else - gtk_table_resize(GTK_TABLE(zathura->ui.page_widget), ceil((number_of_pages + first_page_column - 1) / pages_per_row), pages_per_row); + gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_widget), page_padding); + gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_widget), page_padding); + + unsigned int ncol = pages_per_row; + unsigned int nrow = (number_of_pages + first_page_column - 1 + ncol - 1) / ncol; + gtk_table_resize(GTK_TABLE(zathura->ui.page_widget), nrow, ncol); #endif for (unsigned int i = 0; i < number_of_pages; i++) { diff --git a/zathura.h b/zathura.h index 1ed99a4..4f39b35 100644 --- a/zathura.h +++ b/zathura.h @@ -325,10 +325,12 @@ void position_set(zathura_t* zathura, double position_x, double position_y); * Builds the box structure to show the rendered pages * * @param zathura The zathura session + * @param page_padding padding in pixels between pages * @param pages_per_row Number of shown pages per row * @param first_page_column Column on which first page start */ -void page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row, unsigned int first_page_column); +void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, + unsigned int pages_per_row, unsigned int first_page_column); /** * Updates the page number in the statusbar. Note that 1 will be added to the